diff options
Diffstat (limited to 'shard/lib/app/identity.ex')
-rw-r--r-- | shard/lib/app/identity.ex | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/shard/lib/app/identity.ex b/shard/lib/app/identity.ex index 7e97897..204dfb1 100644 --- a/shard/lib/app/identity.ex +++ b/shard/lib/app/identity.ex @@ -43,10 +43,7 @@ defmodule SApp.Identity do end def default_nick(pk) do - nick_suffix = pk - |> binary_part(0, 4) - |> Base.encode16 - |> String.downcase + nick_suffix = Shard.Keys.pk_display pk "Anon" <> nick_suffix end @@ -56,6 +53,19 @@ defmodule SApp.Identity do Shard.Manager.find_proc id end + def get_nick(pk) do + case find_proc pk do + nil -> + if Shard.Keys.valid_identity_pk? pk do + Shard.Manifest.start %Manifest{pk: pk} + end + default_nick pk + pid -> + info = GenServer.call(pid, :get_info) + info.nick + end + end + def handle_call(:manifest, _from, state) do {:replyl, state.manifest, state} end @@ -85,11 +95,12 @@ defmodule SApp.Identity do def handle_cast({:interested, peer_id}, state) do Shard.Manager.send(peer_id, {state.id, nil, {:update, SData.SignRev.signed(state.state)}}) + {:noreply, state} end def handle_cast({:msg, peer_id, _shard_id, nil, msg}, state) do state = case msg do - {:update, signed} -> + {:update, signed} when signed != nil -> case SData.SignRev.merge(state.state, signed, state.pk) do {true, st2} -> Shard.Manager.save_state(state.id, st2) @@ -99,6 +110,7 @@ defmodule SApp.Identity do {false, _} -> state end + _ -> state end {:noreply, state} end |