summaryrefslogtreecommitdiff
path: root/lib/aggiedit_web/channels/post_channel.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/aggiedit_web/channels/post_channel.ex')
-rw-r--r--lib/aggiedit_web/channels/post_channel.ex22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/aggiedit_web/channels/post_channel.ex b/lib/aggiedit_web/channels/post_channel.ex
new file mode 100644
index 0000000..308c6de
--- /dev/null
+++ b/lib/aggiedit_web/channels/post_channel.ex
@@ -0,0 +1,22 @@
+defmodule AggieditWeb.PostChannel do
+ use AggieditWeb, :channel
+
+ alias Aggiedit.Roles
+ alias Aggiedit.Rooms
+
+ @impl true
+ def join("post:" <> post_id, _payload, socket) do
+ post = Rooms.get_post!(post_id)
+ if Roles.guard?(socket.assigns.current_user, :show, post) do
+ {:ok, socket}
+ else
+ {:error, "You do not have permission to view this post."}
+ end
+ end
+
+ @impl true
+ def handle_in("send", body, socket) do
+ broadcast!(socket, "shout", body)
+ {:reply, :ok, socket}
+ end
+end \ No newline at end of file