From d15d5fbfc5133a9d0f0d99dbbfc023849f61cc37 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 12 Oct 2018 11:10:17 +0200 Subject: Update TODO, refactor a bit --- shard/lib/app/identity.ex | 56 ++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 25 deletions(-) (limited to 'shard/lib/app/identity.ex') 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 -- cgit v1.2.3