1 defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
4 alias Pleroma.Web.OAuth.Token
5 alias Pleroma.{User, Repo}
7 transport :streaming, Phoenix.Transports.WebSocket.Raw,
8 timeout: :infinity # We never receive data.
10 def connect(params, socket) do
11 with token when not is_nil(token) <- params["access_token"],
12 %Token{user_id: user_id} <- Repo.get_by(Token, token: token),
13 %User{} = user <- Repo.get(User, user_id),
14 stream when stream in ["public", "public:local"] <- params["stream"] do
16 |> assign(:topic, params["stream"])
17 |> assign(:user, user)
18 Pleroma.Web.Streamer.add_socket(params["stream"], socket)
25 def id(socket), do: nil
27 def handle(:text, message, state) do
32 #| {:text, message, state}
33 #| {:close, "Goodbye!"}
37 def handle(:closed, reason, %{socket: socket}) do
38 topic = socket.assigns[:topic]
39 Pleroma.Web.Streamer.remove_socket(topic, socket)