diff options
Diffstat (limited to 'shard/lib/cli/cli.ex')
-rw-r--r-- | shard/lib/cli/cli.ex | 35 |
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 |