aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/cli
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-12 11:10:17 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-12 11:10:17 +0200
commitd15d5fbfc5133a9d0f0d99dbbfc023849f61cc37 (patch)
treedaedfd26af6978301b2633a338a137a874876d1f /shard/lib/cli
parent6dcc2eefc3c8db0cadd7300536527dbd1905fa48 (diff)
downloadshard-d15d5fbfc5133a9d0f0d99dbbfc023849f61cc37.tar.gz
shard-d15d5fbfc5133a9d0f0d99dbbfc023849f61cc37.zip
Update TODO, refactor a bit
Diffstat (limited to 'shard/lib/cli')
-rw-r--r--shard/lib/cli/cli.ex35
1 files changed, 8 insertions, 27 deletions
diff --git a/shard/lib/cli/cli.ex b/shard/lib/cli/cli.ex
index 85fa3fc..3b52fa5 100644
--- a/shard/lib/cli/cli.ex
+++ b/shard/lib/cli/cli.ex
@@ -113,18 +113,9 @@ defmodule SCLI do
end
defp handle_command(state, ["join", qchan]) do
- pid = SApp.Chat.find_proc qchan
- case pid do
- nil ->
- {:ok, pid} = Shard.Manifest.start %SApp.Chat.Manifest{channel: qchan}
- GenServer.cast(pid, {:subscribe, self()})
- IO.puts "Joining ##{qchan} (new shard)"
- %{state | room_pid: pid}
- pid ->
- GenServer.cast(pid, {:subscribe, self()})
- IO.puts "Switching to ##{qchan}"
- %{state | room_pid: pid}
- end
+ pid = Shard.Manager.find_or_start %SApp.Chat.Manifest{channel: qchan}
+ IO.puts "Switching to ##{qchan}"
+ %{state | room_pid: pid}
end
defp handle_command(state, ["pm" | people_list]) do
@@ -151,22 +142,12 @@ defmodule SCLI do
end
end
if Enum.all?(pk_list, &(&1 != :error)) do
- pk_list = [state.pk | pk_list]
- manifest = SApp.Chat.PrivChat.Manifest.new(pk_list)
- id = SData.term_hash manifest
- case Shard.Manager.find_proc id do
- nil ->
- {:ok, pid} = Shard.Manifest.start manifest
- GenServer.cast(pid, {:subscribe, self()})
- IO.puts "Joining private conversation (new shard)."
- %{state | room_pid: pid}
- pid ->
- GenServer.cast(pid, {:subscribe, self()})
- IO.puts "Switching to private conversation."
- %{state | room_pid: pid}
- end
+ manifest = SApp.Chat.PrivChat.Manifest.new([state.pk | pk_list])
+ pid = Shard.Manager.find_or_start manifest
+ IO.puts "Switching to private conversation."
+ %{state | room_pid: pid}
else
- state
+ state
end
end