aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/app
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-12 11:10:17 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-12 11:10:17 +0200
commitd15d5fbfc5133a9d0f0d99dbbfc023849f61cc37 (patch)
treedaedfd26af6978301b2633a338a137a874876d1f /shard/lib/app
parent6dcc2eefc3c8db0cadd7300536527dbd1905fa48 (diff)
downloadshard-d15d5fbfc5133a9d0f0d99dbbfc023849f61cc37.tar.gz
shard-d15d5fbfc5133a9d0f0d99dbbfc023849f61cc37.zip
Update TODO, refactor a bit
Diffstat (limited to 'shard/lib/app')
-rw-r--r--shard/lib/app/chat.ex6
-rw-r--r--shard/lib/app/identity.ex56
2 files changed, 31 insertions, 31 deletions
diff --git a/shard/lib/app/chat.ex b/shard/lib/app/chat.ex
index 35ecdbf..ea210d8 100644
--- a/shard/lib/app/chat.ex
+++ b/shard/lib/app/chat.ex
@@ -108,12 +108,6 @@ defmodule SApp.Chat do
end
end
- def find_proc(chan) do
- manifest = %Manifest{channel: chan}
- id = SData.term_hash manifest
- Shard.Manager.find_proc id
- end
-
@doc """
Implementation of the :manifest call that returns the chat room's manifest
"""
diff --git a/shard/lib/app/identity.ex b/shard/lib/app/identity.ex
index 06bc225..02e8eb9 100644
--- a/shard/lib/app/identity.ex
+++ b/shard/lib/app/identity.ex
@@ -46,30 +46,6 @@ defmodule SApp.Identity do
end
end
- def default_nick(pk) do
- nick_suffix = Shard.Keys.pk_display pk
- "Anon" <> nick_suffix
- end
-
- def find_proc(pk) do
- manifest = %Manifest{pk: pk}
- id = SData.term_hash manifest
- case Shard.Manager.find_proc id do
- nil ->
- case Shard.Manifest.start manifest do
- {:ok, pid} -> pid
- {:error, :redundant} -> find_proc(pk)
- end
- pid -> pid
- end
- end
-
- def get_nick(pk) do
- pid = find_proc pk
- info = GenServer.call(pid, :get_info)
- info.nick
- end
-
def handle_call(:manifest, _from, state) do
{:reply, state.manifest, state}
end
@@ -136,8 +112,38 @@ defmodule SApp.Identity do
{:noreply, state}
end
- def bcast_state(state, _exclude \\ []) do
+ defp bcast_state(state, _exclude \\ []) do
# TODO: effectively apply exclude list
SNet.Group.broadcast(state.netgroup, {state.id, nil, {:update, SData.SignRev.signed(state.state), false}})
end
+
+ # ================
+ # PUBLIC INTERFACE
+ # ================
+
+ @doc"""
+ Return the default nickname associated to a pk,
+ in the form "Anonxxxxxxxx" with some bytes of the pk in hex.
+ """
+ def default_nick(pk) do
+ nick_suffix = Shard.Keys.pk_display pk
+ "Anon" <> nick_suffix
+ end
+
+ @doc"""
+ Find the shard process for an identity. Launches such a process
+ if necessary.
+ """
+ def find_proc(pk) do
+ Shard.Manager.find_or_start %Manifest{pk: pk}
+ end
+
+ @doc"""
+ Get a user's nickname from his pk
+ """
+ def get_nick(pk) do
+ pid = find_proc pk
+ info = GenServer.call(pid, :get_info)
+ info.nick
+ end
end