Detect and try to stream incoming "direct" messages
authorcsaurus <csaurus@mailbox.org>
Fri, 11 May 2018 02:17:59 +0000 (22:17 -0400)
committercsaurus <csaurus@mailbox.org>
Sat, 12 May 2018 21:40:59 +0000 (17:40 -0400)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/mastodon_api/mastodon_socket.ex

index fde6e12d78f712e3074cbddd0cf0f37bc2653731..38e3a84fbccbe39de47d2f238940bfff5d7b55c5 100644 (file)
@@ -42,13 +42,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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
index f3e0629416d6dae4ba17d9b5998b3bd864f0d1bf..080f62b313ac4128f0a017d60f2c3d0bb6d4c373 100644 (file)
@@ -15,7 +15,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonSocket 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"])