diff options
author | Alex Auvolat <alex@adnab.me> | 2018-09-26 15:26:06 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-09-26 15:26:06 +0200 |
commit | 7d0009d83c9b5c747d4adb535817924762429f30 (patch) | |
tree | 59b368cf189fc10976337e8caf4e6b623d69a04b /shard/lib/app/identity.ex | |
parent | f16973d3a492ae6d4890c40d77b0a93d3293bf3a (diff) | |
download | shard-7d0009d83c9b5c747d4adb535817924762429f30.tar.gz shard-7d0009d83c9b5c747d4adb535817924762429f30.zip |
Make it work, including Web interface
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 |