defmodule ShardWeb.LayoutView do use ShardWeb, :view 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 case pk_list |> Enum.filter(&(&1 != conn.assigns.pk)) |> Enum.map(&Base.encode16/1) do [] -> conn.assigns.pk |> Base.encode16 l -> Enum.join(l, ",") end end def nicks_of_pk_list(conn, pk_list) do case pk_list |> Enum.filter(&(&1 != conn.assigns.pk)) |> Enum.map(&SApp.Identity.get_nick/1) do [] -> "(myself)" l -> Enum.join(l, ", ") end end def chat_shard_last_msg(pid) do [{{_, msgbin, _}, true}] = SApp.Chat.read_history(pid, nil, 1) {_, msg} = SData.term_unbin msgbin msg end def privchat_with_unread(conn) do 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, do: {id, %SApp.Chat.PrivChat.Manifest{pk_list: pk_list}, pid} end def chat_with_unread(_conn) do 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} end end