:ok <- maybe_federate(activity) do
if activity.data["type"] == "Create" and Enum.member?(activity.data["to"], "https://www.w3.org/ns/activitystreams#Public") do
Pleroma.Web.Streamer.stream("public", activity)
+ if local do
+ Pleroma.Web.Streamer.stream("public:local", activity)
+ end
end
{:ok, activity}
end
defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
use Phoenix.Socket
+ alias Pleroma.Web.OAuth.Token
+ alias Pleroma.{User, Repo}
+
transport :streaming, Phoenix.Transports.WebSocket.Raw,
timeout: :infinity # We never receive data.
def connect(params, socket) do
- if params["stream"] == "public" do
+ with token when not is_nil(token) <- params["access_token"],
+ %Token{user_id: user_id} <- Repo.get_by(Token, token: token),
+ %User{} = user <- Repo.get(User, user_id),
+ stream when stream in ["public", "public:local"] <- params["stream"] do
socket = socket
|> assign(:topic, params["stream"])
+ |> assign(:user, user)
Pleroma.Web.Streamer.add_socket(params["stream"], socket)
{:ok, socket}
else
- :error
+ _e -> :error
end
end
Enum.each(topics[topic] || [], fn (socket) ->
json = %{
event: "update",
- payload: Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: item) |> Poison.encode!
+ payload: Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: item, for: socket.assigns[:user]) |> Poison.encode!
} |> Poison.encode!
send socket.transport_pid, {:text, json}