aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/cli/cli.ex
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-12 18:16:46 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-12 18:16:46 +0200
commit574b572fac144135c4381581351445bf5d0de81c (patch)
tree1ad2fa0157583a955069332e6a957250ff362967 /shard/lib/cli/cli.ex
parent7bc609a85b43ed86eccb9cd40d9db31f15aaba1d (diff)
downloadshard-0.0.3.tar.gz
shard-0.0.3.zip
Clean up interface to shards0.0.3
Diffstat (limited to 'shard/lib/cli/cli.ex')
-rw-r--r--shard/lib/cli/cli.ex21
1 files changed, 10 insertions, 11 deletions
diff --git a/shard/lib/cli/cli.ex b/shard/lib/cli/cli.ex
index 319f96b..45eeece 100644
--- a/shard/lib/cli/cli.ex
+++ b/shard/lib/cli/cli.ex
@@ -9,7 +9,7 @@ defmodule SCLI do
def run() do
for {_chid, %SApp.Chat.Manifest{}, chpid} <- Shard.Manager.list_shards do
- GenServer.cast(chpid, {:subscribe, self()})
+ SApp.Chat.subscribe(chpid)
end
pk = Shard.Keys.get_any_identity
@@ -28,14 +28,13 @@ defmodule SCLI do
nick = case id_pid do
nil -> SApp.Identity.default_nick(state.pk)
_ ->
- info = GenServer.call(id_pid, :get_info)
- info.nick
+ SApp.Identity.get_info(id_pid).nick
end
prompt = case state.room_pid do
nil -> "(no channel) #{nick}: "
_ ->
- case GenServer.call(state.room_pid, :manifest) do
+ case SApp.Chat.get_manifest(state.room_pid) do
%SApp.Chat.Manifest{channel: chan} ->
"##{chan} #{nick}: "
%SApp.Chat.PrivChat.Manifest{pk_list: pk_list} ->
@@ -57,7 +56,7 @@ defmodule SCLI do
run(state)
true ->
if str != "" do
- GenServer.cast(state.room_pid, {:chat_send, state.pk, str})
+ SApp.Chat.chat_send(state.room_pid, state.pk, str)
end
run(state)
end
@@ -102,7 +101,7 @@ defmodule SCLI do
if state.room_pid == nil do
IO.puts "Not currently on a channel!"
else
- GenServer.call(state.room_pid, {:read_history, nil, 25})
+ SApp.Chat.read_history(state.room_pid, nil, 25)
|> Enum.each(fn {{pk, msgbin, _sign}, true} ->
{ts, msg} = SData.term_unbin msgbin
nick = SApp.Identity.get_nick pk
@@ -114,14 +113,14 @@ defmodule SCLI do
defp handle_command(state, ["join", qchan]) do
pid = Shard.Manager.find_or_start %SApp.Chat.Manifest{channel: qchan}
- GenServer.cast(pid, {:subscribe, self()})
+ SApp.Chat.subscribe(pid)
IO.puts "Switching to ##{qchan}"
%{state | room_pid: pid}
end
defp handle_command(state, ["pm" | people_list]) do
known_people = for {_, %SApp.Identity.Manifest{pk: pk}, pid} <- Shard.Manager.list_shards() do
- info = GenServer.call(pid, :get_info)
+ info = SApp.Identity.get_info(pid)
{pk, info.nick}
end
pk_list = for qname <- people_list do
@@ -145,7 +144,7 @@ defmodule SCLI do
if Enum.all?(pk_list, &(&1 != :error)) do
manifest = SApp.Chat.PrivChat.Manifest.new([state.pk | pk_list])
pid = Shard.Manager.find_or_start manifest
- GenServer.cast(pid, {:subscribe, self()})
+ SApp.Chat.subscribe(pid)
IO.puts "Switching to private conversation."
%{state | room_pid: pid}
else
@@ -161,8 +160,8 @@ defmodule SCLI do
if pid == nil do
IO.puts "Sorry, we have a problem with the identity shard"
else
- info = GenServer.call(pid, :get_info)
- GenServer.call(pid, {:set_info, %{info | nick: nick}})
+ info = SApp.Identity.get_info(pid)
+ SApp.Identity.set_info(pid, %{info | nick: nick})
end
state
end