summaryrefslogtreecommitdiff
path: root/lib/aggiedit_web/channels/post_channel.ex
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-04-14 13:56:10 -0600
committerLogan Hunt <loganhunt@simponic.xyz>2022-04-14 13:56:10 -0600
commitdb7c2321cd0af59f9e810e84c7d4eb83ec416458 (patch)
tree2e559978cd4c7b4585c1c36e2cf8642aac94bd2b /lib/aggiedit_web/channels/post_channel.ex
parentcc58a376a94c28532121fca2e1ab1d0e7de11046 (diff)
downloadaggiedit-db7c2321cd0af59f9e810e84c7d4eb83ec416458.tar.gz
aggiedit-db7c2321cd0af59f9e810e84c7d4eb83ec416458.zip
Add initial channels for posts
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