diff options
author | Alex Auvolat <alex@adnab.me> | 2018-10-12 18:16:46 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-10-12 18:16:46 +0200 |
commit | 574b572fac144135c4381581351445bf5d0de81c (patch) | |
tree | 1ad2fa0157583a955069332e6a957250ff362967 /shardweb | |
parent | 7bc609a85b43ed86eccb9cd40d9db31f15aaba1d (diff) | |
download | shard-574b572fac144135c4381581351445bf5d0de81c.tar.gz shard-574b572fac144135c4381581351445bf5d0de81c.zip |
Clean up interface to shards0.0.3
Diffstat (limited to 'shardweb')
-rw-r--r-- | shardweb/lib/channels/chat_channel.ex | 14 | ||||
-rw-r--r-- | shardweb/lib/controllers/chat_controller.ex | 2 | ||||
-rw-r--r-- | shardweb/lib/controllers/identity_controller.ex | 4 | ||||
-rw-r--r-- | shardweb/lib/templates/identity/list.html.eex | 2 | ||||
-rw-r--r-- | shardweb/lib/templates/identity/view.html.eex | 2 | ||||
-rw-r--r-- | shardweb/lib/templates/layout/app.html.eex | 8 | ||||
-rw-r--r-- | shardweb/lib/templates/page/peer_list.html.eex | 4 | ||||
-rw-r--r-- | shardweb/lib/templates/page/shard_list.html.eex | 2 | ||||
-rw-r--r-- | shardweb/lib/views/layout_view.ex | 8 |
9 files changed, 23 insertions, 23 deletions
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 @@ </tr> <%= for {_id, manifest, pid} <- people_list() do %> <tr> - <td><i class="fa fa-user"></i> <%= GenServer.call(pid, :get_info).nick %> + <td><i class="fa fa-user"></i> <%= SApp.Identity.get_info(pid).nick %> <%= if manifest.pk == @pk do %> <span class="badge badge-success"><i class="fa fa-user"></i> myself</span> <% 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 %> <pre> - <%= inspect((GenServer.call(@pid, :get_info)), pretty: true, width: 40) %> + <%= inspect(SApp.Identity.get_info(@pid), pretty: true, width: 40) %> </pre> 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 @@ <b class="caret"></b> </a> <ul class="dropdown-menu message-dropdown"> - <%= for {id, %SApp.Chat.PrivChat.Manifest{pk_list: pk_list}, pid} <- sur do %> + <%= for {_id, %SApp.Chat.PrivChat.Manifest{pk_list: pk_list}, pid} <- sur do %> <li class="message-preview"> <a href="<%= chat_path(@conn, :privchat, str_of_pk_list(@conn, pk_list)) %>"> <div class="media"> @@ -137,7 +137,7 @@ <%= for {id, %SApp.Chat.Manifest{channel: name}, pid} <- shard_list() do %> <li class="<%= if @shard == id do "custom_active" else "" end %>"> <a href="<%= chat_path(@conn, :chat, name) %>"> - <%= if GenServer.call(pid, :has_unread) != nil do %> + <%= if SApp.Chat.has_unread?(pid) != nil do %> <span class="have_unread">#<%= name %></span> <% else %> #<%= name %> @@ -159,7 +159,7 @@ <%= for {id, %SApp.Chat.PrivChat.Manifest{pk_list: pk_list}, pid} <- shard_list() do %> <li class="<%= if id == @shard do "custom_active" else "" end %>"> <a href="<%= chat_path(@conn, :privchat, str_of_pk_list(@conn, pk_list)) %>"> - <%= if GenServer.call(pid, :has_unread) != nil do %> + <%= if SApp.Chat.has_unread?(pid) != nil do %> <span class="have_unread"><%= nicks_of_pk_list(@conn, pk_list) %></span> <% else %> <%= nicks_of_pk_list(@conn, pk_list) %> @@ -171,7 +171,7 @@ <% end %> </li> <li class="<%= if @view_module == ShardWeb.PageView and @view_template == "peer_list.html" do "active" else "" end %>"> - <a href="<%= page_path(@conn, :peer_list) %>"><i class="fa fa-fw fa-globe"></i> Peer list</a> + <a href="<%= page_path(@conn, :peer_list) %>"><i class="fa fa-fw fa-server"></i> Peer list</a> </li> <li> <a href="#"><i class="fa fa-fw fa-gear"></i> Settings</a> diff --git a/shardweb/lib/templates/page/peer_list.html.eex b/shardweb/lib/templates/page/peer_list.html.eex index ff6479f..09060a7 100644 --- a/shardweb/lib/templates/page/peer_list.html.eex +++ b/shardweb/lib/templates/page/peer_list.html.eex @@ -10,7 +10,7 @@ <i class="fa fa-dashboard"></i> Dashboard </li> <li class="active"> - <i class="fa fa-globe"></i> Peer list + <i class="fa fa-server"></i> Peer list </li> </ol> </div> @@ -29,7 +29,7 @@ <tr> <td> <%= case auth do %> - <% nil -> %>(anonymous) + <% nil -> %><i class="fa fa-globe"></i> (anonymous) <% %SNet.Auth{his_pk: his_pk} -> %> <i class="fa fa-user"></i> <%= SApp.Identity.get_nick(his_pk) %> diff --git a/shardweb/lib/templates/page/shard_list.html.eex b/shardweb/lib/templates/page/shard_list.html.eex index 012223a..cc23205 100644 --- a/shardweb/lib/templates/page/shard_list.html.eex +++ b/shardweb/lib/templates/page/shard_list.html.eex @@ -30,7 +30,7 @@ <td> <%= case manifest do %> <% %SApp.Identity.Manifest{pk: pk} -> %><i class="fa fa-user"></i> - <%= GenServer.call(pid, :get_info).nick %> + <%= SApp.Identity.get_info(pid).nick %> <a href="<%= identity_path(@conn, :view, pk|>Base.encode16) %>"> <small><%= Shard.Keys.pk_display pk %></small> </a> diff --git a/shardweb/lib/views/layout_view.ex b/shardweb/lib/views/layout_view.ex index 990df55..d554804 100644 --- a/shardweb/lib/views/layout_view.ex +++ b/shardweb/lib/views/layout_view.ex @@ -26,7 +26,7 @@ defmodule ShardWeb.LayoutView do end def chat_shard_last_msg(pid) do - [{{_, msgbin, _}, true}] = GenServer.call(pid, {:read_history, nil, 1}) + [{{_, msgbin, _}, true}] = SApp.Chat.read_history(pid, nil, 1) {_, msg} = SData.term_unbin msgbin msg end @@ -34,14 +34,14 @@ defmodule ShardWeb.LayoutView do def privchat_with_unread(conn) do for {id, %SApp.Chat.PrivChat.Manifest{pk_list: pk_list}, pid} <- shard_list(), conn.assigns.pk in pk_list, - unread_time = GenServer.call(pid, :has_unread), + unread_time = SApp.Chat.has_unread?(pid), unread_time != nil, do: {id, %SApp.Chat.PrivChat.Manifest{pk_list: pk_list}, pid} end - def chat_with_unread(conn) do + def chat_with_unread(_conn) do for {id, %SApp.Chat.Manifest{channel: c}, pid} <- shard_list(), - unread_time = GenServer.call(pid, :has_unread), + unread_time = SApp.Chat.has_unread?(pid), unread_time != nil, do: {id, %SApp.Chat.Manifest{channel: c}, pid} end |