Commit 5719f69a authored by Roger Braun's avatar Roger Braun
Browse files

MastodonAPI: Stream fixes.

parent a2d7e0f4
Pipeline #240 failed with stage
in 1 minute and 50 seconds
......@@ -24,6 +24,9 @@ def create(to, actor, context, object, additional \\ %{}, published \\ nil, loca
:ok <- maybe_federate(activity) do
if["type"] == "Create" and Enum.member?(["to"], "") do"public", activity)
if local do"public:local", activity)
{:ok, activity}
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}
_e -> :error
......@@ -43,7 +43,7 @@ def handle_cast(%{action: :stream, topic: topic, item: item}, topics) do
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}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment