diff options
Diffstat (limited to 'shard/lib/app/identity.ex')
-rw-r--r-- | shard/lib/app/identity.ex | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/shard/lib/app/identity.ex b/shard/lib/app/identity.ex index 95ffb92..42d1bf8 100644 --- a/shard/lib/app/identity.ex +++ b/shard/lib/app/identity.ex @@ -1,14 +1,29 @@ defmodule SApp.Identity do + @moduledoc""" + Shard application for keeping state associated with a user's identity. + + Current functionality: + + - nickname + - peer info: ip, port to connect to if we want a secure connection with this person + (used for private chat) + + Future functionnality: + + - friend list + - notifications & invites + """ + use GenServer require Logger defmodule Manifest do - defstruct [:pk] - end + @moduledoc""" + Manifest for a user identity shard, defined by the public key of the user. + """ - defmodule State do - defstruct [:info, :rev, :signed] + defstruct [:pk] end defimpl Shard.Manifest, for: Manifest do @@ -17,6 +32,10 @@ defmodule SApp.Identity do end end + defmodule State do + defstruct [:info, :rev, :signed] + end + def start_link(pk) do GenServer.start_link(__MODULE__, pk) end @@ -139,11 +158,23 @@ defmodule SApp.Identity do end @doc""" + Get the info dict of an identity shard. The pid of the shard must be given as an argument. + """ + def get_info(pid) do + GenServer.call(pid, :get_info) + end + + @doc""" + Set the info dict of an identity shard. + """ + def set_info(pid, new_info) do + GenServer.call(pid, {:set_info, new_info}) + 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 + get_info(find_proc pk).nick end end |