From 574b572fac144135c4381581351445bf5d0de81c Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 12 Oct 2018 18:16:46 +0200 Subject: Clean up interface to shards --- shardweb/lib/channels/chat_channel.ex | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'shardweb/lib/channels/chat_channel.ex') diff --git a/shardweb/lib/channels/chat_channel.ex b/shardweb/lib/channels/chat_channel.ex index a413be1..25f1d09 100644 --- a/shardweb/lib/channels/chat_channel.ex +++ b/shardweb/lib/channels/chat_channel.ex @@ -9,7 +9,7 @@ defmodule ShardWeb.ChatChannel do pid = Shard.Manager.find_or_start %SApp.Chat.Manifest{channel: room_name} socket = assign(socket, :pid, pid) - GenServer.cast(pid, {:subscribe, self()}) + SApp.Chat.subscribe(pid) send(self(), :after_join) {:ok, socket} @@ -27,7 +27,7 @@ defmodule ShardWeb.ChatChannel do pid = Shard.Manager.find_or_start(SApp.Chat.PrivChat.Manifest.new(pk_list)) socket = assign(socket, :pid, pid) - GenServer.cast(pid, {:subscribe, self()}) + SApp.Chat.subscribe(pid) send(self(), :after_join) {:ok, socket} @@ -37,7 +37,7 @@ defmodule ShardWeb.ChatChannel do end def handle_info(:after_join, socket) do - GenServer.call(socket.assigns.pid, {:read_history, nil, 100}) + SApp.Chat.read_history(socket.assigns.pid, nil, 100) |> Enum.each(fn {{pk, msgbin, _sign}, true} -> {_ts, msg} = SData.term_unbin msgbin nick = SApp.Identity.get_nick pk @@ -47,7 +47,7 @@ defmodule ShardWeb.ChatChannel do message: msg, }) end) - GenServer.cast(socket.assigns.pid, :mark_read) + SApp.Chat.mark_read(socket.assigns.pid) {:noreply, socket} end @@ -58,12 +58,12 @@ defmodule ShardWeb.ChatChannel do push socket, "shout", %{"name" => nick, "pk16" => Shard.Keys.pk_display(pk), "message" => msg} - GenServer.cast(socket.assigns.pid, :mark_read) + SApp.Chat.mark_read(socket.assigns.pid) {:noreply, socket} end def handle_info({:chat_send, _, _}, socket) do - GenServer.cast(socket.assigns.pid, :mark_read) + SApp.Chat.mark_read(socket.assigns.pid) {:noreply, socket} end @@ -81,7 +81,7 @@ defmodule ShardWeb.ChatChannel do payload = Map.put(payload, "name", nick) payload = Map.put(payload, "pk16", Shard.Keys.pk_display pk) - GenServer.cast(socket.assigns.pid, {:chat_send, pk, payload["message"]}) + SApp.Chat.chat_send(socket.assigns.pid, pk, payload["message"]) broadcast socket, "shout", payload {:noreply, socket} end -- cgit v1.2.3