aboutsummaryrefslogblamecommitdiff
path: root/shardweb/lib/views/layout_view.ex
blob: d554804f0f1e6242f7a6f9ed9e954e798077b883 (plain) (tree)
1
2
3
4
5
6

                                



                             



















                                            

                                 
                                                                  






                                                                                  
                                               



                                                                 
                                
                                                                   
                                               


                                                  
   
defmodule ShardWeb.LayoutView do
  use ShardWeb, :view

  def shard_list do
    Shard.Manager.list_shards
  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}, pid} <- shard_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}, pid} <- shard_list(),
      unread_time = SApp.Chat.has_unread?(pid),
      unread_time != nil,
    do: {id, %SApp.Chat.Manifest{channel: c}, pid}
  end
end