summaryrefslogtreecommitdiff
path: root/lib/aggiedit_web/channels/post_channel.ex
blob: 308c6de95251b246ed6b942334a94407a275570b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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