aboutsummaryrefslogtreecommitdiff
path: root/shardweb/lib/channels/chat_channel.ex
diff options
context:
space:
mode:
Diffstat (limited to 'shardweb/lib/channels/chat_channel.ex')
-rw-r--r--shardweb/lib/channels/chat_channel.ex20
1 files changed, 19 insertions, 1 deletions
diff --git a/shardweb/lib/channels/chat_channel.ex b/shardweb/lib/channels/chat_channel.ex
index 3e51c3a..f898602 100644
--- a/shardweb/lib/channels/chat_channel.ex
+++ b/shardweb/lib/channels/chat_channel.ex
@@ -3,7 +3,7 @@ defmodule ShardWeb.ChatChannel do
require Logger
- def join("room:" <> room_name, payload, socket) do
+ def join("chat:" <> room_name, payload, socket) do
if authorized?(payload) do
pid = Shard.Manager.find_or_start %SApp.Chat.Manifest{channel: room_name}
@@ -18,6 +18,24 @@ defmodule ShardWeb.ChatChannel do
end
end
+ def join("privchat:" <> room_name, payload, socket) do
+ if authorized?(payload) do
+
+ pk_list = room_name |> String.split(",") |> Enum.map(&Base.decode16!/1)
+ pk_list = [socket.assigns.pk | pk_list] |> Enum.sort() |> Enum.uniq()
+
+ pid = Shard.Manager.find_or_start(SApp.Chat.PrivChat.Manifest.new(pk_list))
+ socket = assign(socket, :pid, pid)
+
+ GenServer.cast(pid, {:subscribe, self()})
+ send(self(), :after_join)
+
+ {:ok, socket}
+ else
+ {:error, %{reason: "unauthorized"}}
+ end
+ end
+
def handle_info(:after_join, socket) do
GenServer.call(socket.assigns.pid, {:read_history, nil, 100})
|> Enum.each(fn {{pk, msgbin, _sign}, true} ->