From 8c49dd71d29359447c24b1cd4f48a8faf0c4fdca Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 15 Oct 2018 12:18:05 +0200 Subject: Refactor shard starting/stopping --- shardweb/lib/controllers/chat_controller.ex | 5 ++--- shardweb/lib/templates/identity/list.html.eex | 4 ++-- shardweb/lib/templates/page/shard_list.html.eex | 8 ++++---- shardweb/lib/views/layout_view.ex | 7 +++++-- 4 files changed, 13 insertions(+), 11 deletions(-) (limited to 'shardweb/lib') 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 @@ Public key - <%= for {_id, manifest, pid} <- people_list() do %> + <%= for {_id, manifest, _} <- people_list() do %> - <%= SApp.Identity.get_info(pid).nick %> + <%= SApp.Identity.get_nick(manifest.pk) %> <%= if manifest.pk == @pk do %> myself <% 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 @@ Shard Id - Pid + State - <%= for {id, manifest, pid} <- shard_list() do %> + <%= for {id, manifest, state} <- shard_list() do %> <%= case manifest do %> <% %SApp.Identity.Manifest{pk: pk} -> %> - <%= SApp.Identity.get_info(pid).nick %> + <%= SApp.Identity.get_nick(pk) %> <%= Shard.Keys.pk_display pk %> @@ -50,7 +50,7 @@ <% end %> <%= id |> Base.encode16 %> - <%= inspect(pid) %> + <%= inspect(state) %> <% end %> 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} -- cgit v1.2.3