aboutsummaryrefslogtreecommitdiff
path: root/shardweb/lib/shard_web/channels
diff options
context:
space:
mode:
Diffstat (limited to 'shardweb/lib/shard_web/channels')
-rw-r--r--shardweb/lib/shard_web/channels/room_channel.ex12
1 files changed, 2 insertions, 10 deletions
diff --git a/shardweb/lib/shard_web/channels/room_channel.ex b/shardweb/lib/shard_web/channels/room_channel.ex
index f582e06..7c3a16c 100644
--- a/shardweb/lib/shard_web/channels/room_channel.ex
+++ b/shardweb/lib/shard_web/channels/room_channel.ex
@@ -6,15 +6,7 @@ defmodule ShardWeb.RoomChannel do
def join("room:" <> room_name, payload, socket) do
if authorized?(payload) do
- list = for {_chid, %SApp.Chat.Manifest{channel: chan}, chpid} <- Shard.Manager.list_shards,
- do: {chan, chpid}
- pid = case List.keyfind(list, room_name, 0) do
- nil ->
- {:ok, pid} = Shard.Manifest.start %SApp.Chat.Manifest{channel: room_name}
- pid
- {_, pid} ->
- pid
- end
+ pid = Shard.Manager.find_or_start %SApp.Chat.Manifest{channel: room_name}
socket = assign(socket, :pid, pid)
GenServer.cast(pid, {:subscribe, self()})
@@ -68,8 +60,8 @@ defmodule ShardWeb.RoomChannel do
payload = Map.put(payload, "name", nick)
payload = Map.put(payload, "pk16", Shard.Keys.pk_display pk)
- broadcast socket, "shout", payload
GenServer.cast(socket.assigns.pid, {:chat_send, pk, payload["message"]})
+ broadcast socket, "shout", payload
{:noreply, socket}
end