diff options
author | Alex Auvolat <alex@adnab.me> | 2018-10-15 12:18:05 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-10-15 12:18:05 +0200 |
commit | 8c49dd71d29359447c24b1cd4f48a8faf0c4fdca (patch) | |
tree | e2d8b61139d6b72e6abfda6277918f54fdae36ef /shardweb | |
parent | 7a9678843647de930885792149b279ef105f67b6 (diff) | |
download | shard-8c49dd71d29359447c24b1cd4f48a8faf0c4fdca.tar.gz shard-8c49dd71d29359447c24b1cd4f48a8faf0c4fdca.zip |
Refactor shard starting/stopping
Diffstat (limited to 'shardweb')
-rw-r--r-- | shardweb/lib/controllers/chat_controller.ex | 5 | ||||
-rw-r--r-- | shardweb/lib/templates/identity/list.html.eex | 4 | ||||
-rw-r--r-- | shardweb/lib/templates/page/shard_list.html.eex | 8 | ||||
-rw-r--r-- | shardweb/lib/views/layout_view.ex | 7 |
4 files changed, 13 insertions, 11 deletions
diff --git a/shardweb/lib/controllers/chat_controller.ex b/shardweb/lib/controllers/chat_controller.ex index 75f2f18..080ee61 100644 --- a/shardweb/lib/controllers/chat_controller.ex +++ b/shardweb/lib/controllers/chat_controller.ex @@ -13,9 +13,8 @@ defmodule ShardWeb.ChatController do end def privchat(conn, %{"people_list" => people_list}) do - known_people = for {_, %SApp.Identity.Manifest{pk: pk}, pid} <- Shard.Manager.list_shards() do - info = SApp.Identity.get_info(pid) - {pk, info.nick} + known_people = for {_, %SApp.Identity.Manifest{pk: pk}, _} <- Shard.Manager.list_shards() do + {pk, SApp.Identity.get_nick(pk)} end pk_list = for qname <- String.split(people_list, ",") do diff --git a/shardweb/lib/templates/identity/list.html.eex b/shardweb/lib/templates/identity/list.html.eex index 19dba2d..629a0db 100644 --- a/shardweb/lib/templates/identity/list.html.eex +++ b/shardweb/lib/templates/identity/list.html.eex @@ -23,9 +23,9 @@ <th></th> <th>Public key</th> </tr> - <%= for {_id, manifest, pid} <- people_list() do %> + <%= for {_id, manifest, _} <- people_list() do %> <tr> - <td><i class="fa fa-user"></i> <%= SApp.Identity.get_info(pid).nick %> + <td><i class="fa fa-user"></i> <%= SApp.Identity.get_nick(manifest.pk) %> <%= 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/page/shard_list.html.eex b/shardweb/lib/templates/page/shard_list.html.eex index cc23205..27f70b4 100644 --- a/shardweb/lib/templates/page/shard_list.html.eex +++ b/shardweb/lib/templates/page/shard_list.html.eex @@ -23,14 +23,14 @@ <tr> <th>Shard</th> <th>Id</th> - <th>Pid</th> + <th>State</th> </tr> - <%= for {id, manifest, pid} <- shard_list() do %> + <%= for {id, manifest, state} <- shard_list() do %> <tr> <td> <%= case manifest do %> <% %SApp.Identity.Manifest{pk: pk} -> %><i class="fa fa-user"></i> - <%= SApp.Identity.get_info(pid).nick %> + <%= SApp.Identity.get_nick(pk) %> <a href="<%= identity_path(@conn, :view, pk|>Base.encode16) %>"> <small><%= Shard.Keys.pk_display pk %></small> </a> @@ -50,7 +50,7 @@ <% end %> </td> <td><small><%= id |> Base.encode16 %></small></td> - <td><%= inspect(pid) %></td> + <td><%= inspect(state) %></td> </tr> <% end %> </table> diff --git a/shardweb/lib/views/layout_view.ex b/shardweb/lib/views/layout_view.ex index d554804..40863a1 100644 --- a/shardweb/lib/views/layout_view.ex +++ b/shardweb/lib/views/layout_view.ex @@ -3,6 +3,7 @@ defmodule ShardWeb.LayoutView do def shard_list do Shard.Manager.list_shards + |> Enum.map(fn {id, manifest, _} -> {id, manifest, Shard.Manager.find_or_start manifest} end) end def str_of_pk_list(conn, pk_list) do @@ -32,7 +33,8 @@ defmodule ShardWeb.LayoutView do end def privchat_with_unread(conn) do - for {id, %SApp.Chat.PrivChat.Manifest{pk_list: pk_list}, pid} <- shard_list(), + for {id, %SApp.Chat.PrivChat.Manifest{pk_list: pk_list}, _} <- shard_list(), + pid = Shard.Manager.find_or_start(%SApp.Chat.PrivChat.Manifest{pk_list: pk_list}), conn.assigns.pk in pk_list, unread_time = SApp.Chat.has_unread?(pid), unread_time != nil, @@ -40,7 +42,8 @@ defmodule ShardWeb.LayoutView do end def chat_with_unread(_conn) do - for {id, %SApp.Chat.Manifest{channel: c}, pid} <- shard_list(), + for {id, %SApp.Chat.Manifest{channel: c}, _} <- shard_list(), + pid = Shard.Manager.find_or_start(%SApp.Chat.Manifest{channel: c}), unread_time = SApp.Chat.has_unread?(pid), unread_time != nil, do: {id, %SApp.Chat.Manifest{channel: c}, pid} |