MastodonAPI: Stream fixes.
This commit is contained in:
parent
a2d7e0f4d4
commit
5719f69ae3
|
@ -24,6 +24,9 @@ def create(to, actor, context, object, additional \\ %{}, published \\ nil, loca
|
||||||
:ok <- maybe_federate(activity) do
|
:ok <- maybe_federate(activity) do
|
||||||
if activity.data["type"] == "Create" and Enum.member?(activity.data["to"], "https://www.w3.org/ns/activitystreams#Public") 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)
|
Pleroma.Web.Streamer.stream("public", activity)
|
||||||
|
if local do
|
||||||
|
Pleroma.Web.Streamer.stream("public:local", activity)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
|
defmodule Pleroma.Web.MastodonAPI.MastodonSocket do
|
||||||
use Phoenix.Socket
|
use Phoenix.Socket
|
||||||
|
|
||||||
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
alias Pleroma.{User, Repo}
|
||||||
|
|
||||||
transport :streaming, Phoenix.Transports.WebSocket.Raw,
|
transport :streaming, Phoenix.Transports.WebSocket.Raw,
|
||||||
timeout: :infinity # We never receive data.
|
timeout: :infinity # We never receive data.
|
||||||
|
|
||||||
def connect(params, socket) do
|
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
|
socket = socket
|
||||||
|> assign(:topic, params["stream"])
|
|> assign(:topic, params["stream"])
|
||||||
|
|> assign(:user, user)
|
||||||
Pleroma.Web.Streamer.add_socket(params["stream"], socket)
|
Pleroma.Web.Streamer.add_socket(params["stream"], socket)
|
||||||
{:ok, socket}
|
{:ok, socket}
|
||||||
else
|
else
|
||||||
:error
|
_e -> :error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ def handle_cast(%{action: :stream, topic: topic, item: item}, topics) do
|
||||||
Enum.each(topics[topic] || [], fn (socket) ->
|
Enum.each(topics[topic] || [], fn (socket) ->
|
||||||
json = %{
|
json = %{
|
||||||
event: "update",
|
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!
|
} |> Poison.encode!
|
||||||
|
|
||||||
send socket.transport_pid, {:text, json}
|
send socket.transport_pid, {:text, json}
|
||||||
|
|
Loading…
Reference in a new issue