aboutsummaryrefslogblamecommitdiff
path: root/shardweb/lib/shard_web/controllers/room_controller.ex
blob: 8c98aa62f13fc2b42c6e60eee024a5b4d4c1804a (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                                    
                


                                      


                                                


                                         

                  



                                    
                                         
                                                 

                             

                

     
defmodule ShardWeb.RoomController do
  use ShardWeb, :controller

  require Logger
  import PhoenixGon.Controller

  def show(conn, %{"room" => room}) do
    pk = get_session(conn, :pk)
    {pk, conn} = cond do
      pk == nil || not Shard.Keys.have_sk? pk ->
        pk = Shard.Keys.get_any_identity
        conn = put_session(conn, :pk, pk)
        {pk, conn}
      true ->
        {pk, conn}
    end

    name = SApp.Identity.get_nick pk

    conn = put_gon(conn, chat_room: room)
    conn = put_gon(conn, pk: (pk|>Base.encode16))
    render conn, "show.html",
      room: room,
      pk: pk,
      name: name
  end
end