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 +++++++------- shardweb/lib/controllers/chat_controller.ex | 2 +- shardweb/lib/controllers/identity_controller.ex | 4 ++-- shardweb/lib/templates/identity/list.html.eex | 2 +- shardweb/lib/templates/identity/view.html.eex | 2 +- shardweb/lib/templates/layout/app.html.eex | 8 ++++---- shardweb/lib/templates/page/peer_list.html.eex | 4 ++-- shardweb/lib/templates/page/shard_list.html.eex | 2 +- shardweb/lib/views/layout_view.ex | 8 ++++---- 9 files changed, 23 insertions(+), 23 deletions(-) (limited to 'shardweb') 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 diff --git a/shardweb/lib/controllers/chat_controller.ex b/shardweb/lib/controllers/chat_controller.ex index 31b80ba..75f2f18 100644 --- a/shardweb/lib/controllers/chat_controller.ex +++ b/shardweb/lib/controllers/chat_controller.ex @@ -14,7 +14,7 @@ defmodule ShardWeb.ChatController do def privchat(conn, %{"people_list" => people_list}) do known_people = for {_, %SApp.Identity.Manifest{pk: pk}, pid} <- Shard.Manager.list_shards() do - info = GenServer.call(pid, :get_info) + info = SApp.Identity.get_info(pid) {pk, info.nick} end diff --git a/shardweb/lib/controllers/identity_controller.ex b/shardweb/lib/controllers/identity_controller.ex index dd254bb..962a888 100644 --- a/shardweb/lib/controllers/identity_controller.ex +++ b/shardweb/lib/controllers/identity_controller.ex @@ -27,9 +27,9 @@ defmodule ShardWeb.IdentityController do def update(conn, params) do pid = SApp.Identity.find_proc(conn.assigns.pk) - info = GenServer.call(pid, :get_info) + info = SApp.Identity.get_info(pid) info = %{info | nick: params["nick"]} - GenServer.call(pid, {:set_info, info}) + SApp.Identity.set_info(pid, info) redirect conn, to: identity_path(conn, :self) end diff --git a/shardweb/lib/templates/identity/list.html.eex b/shardweb/lib/templates/identity/list.html.eex index 6437f9c..19dba2d 100644 --- a/shardweb/lib/templates/identity/list.html.eex +++ b/shardweb/lib/templates/identity/list.html.eex @@ -25,7 +25,7 @@ <%= for {_id, manifest, pid} <- people_list() do %> - <%= GenServer.call(pid, :get_info).nick %> + <%= SApp.Identity.get_info(pid).nick %> <%= if manifest.pk == @pk do %> myself <% end %> diff --git a/shardweb/lib/templates/identity/view.html.eex b/shardweb/lib/templates/identity/view.html.eex index 8bb8ca2..58be7e7 100644 --- a/shardweb/lib/templates/identity/view.html.eex +++ b/shardweb/lib/templates/identity/view.html.eex @@ -19,7 +19,7 @@ <%= render ShardWeb.LayoutView, "flashes.html", assigns %>
-  <%= inspect((GenServer.call(@pid, :get_info)), pretty: true, width: 40) %>
+  <%= inspect(SApp.Identity.get_info(@pid), pretty: true, width: 40) %>
 
diff --git a/shardweb/lib/templates/layout/app.html.eex b/shardweb/lib/templates/layout/app.html.eex index d96bdeb..6cedcaf 100644 --- a/shardweb/lib/templates/layout/app.html.eex +++ b/shardweb/lib/templates/layout/app.html.eex @@ -61,7 +61,7 @@