From d15d5fbfc5133a9d0f0d99dbbfc023849f61cc37 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 12 Oct 2018 11:10:17 +0200 Subject: Update TODO, refactor a bit --- shardweb/lib/shard_web/channels/room_channel.ex | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'shardweb') 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 -- cgit v1.2.3