From c60a5405db7c0bdb4f837e14088a495c1b741bc6 Mon Sep 17 00:00:00 2001 From: csaurus Date: Thu, 10 May 2018 22:17:59 -0400 Subject: [PATCH] Detect and try to stream incoming "direct" messages --- lib/pleroma/web/activity_pub/activity_pub.ex | 15 ++++++++++----- lib/pleroma/web/mastodon_api/mastodon_socket.ex | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index fde6e12d7..38e3a84fb 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -42,13 +42,18 @@ def insert(map, local \\ true) when is_map(map) do def stream_out(activity) do if activity.data["type"] in ["Create", "Announce"] do Pleroma.Web.Streamer.stream("user", activity) + direct? = activity.data["object"]["visibility"] == "direct" - if Enum.member?(activity.data["to"], "https://www.w3.org/ns/activitystreams#Public") do - Pleroma.Web.Streamer.stream("public", activity) + cond do + direct? -> + Pleroma.Web.Streamer.stream("direct", activity) - if activity.local do - Pleroma.Web.Streamer.stream("public:local", activity) - end + Enum.member?(activity.data["to"], "https://www.w3.org/ns/activitystreams#Public") -> + Pleroma.Web.Streamer.stream("public", activity) + + if activity.local do + Pleroma.Web.Streamer.stream("public:local", activity) + end end end end diff --git a/lib/pleroma/web/mastodon_api/mastodon_socket.ex b/lib/pleroma/web/mastodon_api/mastodon_socket.ex index f3e062941..080f62b31 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_socket.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_socket.ex @@ -15,7 +15,7 @@ def connect(params, socket) 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", "user"] <- params["stream"] do + stream when stream in ["public", "public:local", "user", "direct"] <- params["stream"] do socket = socket |> assign(:topic, params["stream"])