streamer: use direct object for filter checks when there is no valid child object...
authorAriadne Conill <ariadne@dereferenced.org>
Sun, 3 Nov 2019 15:05:12 +0000 (09:05 -0600)
committerlain <lain@soykaf.club>
Mon, 4 Nov 2019 15:25:05 +0000 (16:25 +0100)
We call Object.normalize/1 to get the child object for situations like Announce.
However, the check is flawed and immediately fails if Object.normalize/1 fails.
Instead, we should use the activity itself in those cases to allow activities which
never have a child object to pass through the filter.

Closes #1291

lib/pleroma/web/streamer/worker.ex
test/web/streamer/streamer_test.exs

index 0ea224874ed9ce430d840ac88e5a296f4f3e3774..da7a5a6f274b4ca510ce8273214a484f1abde58b 100644 (file)
@@ -136,7 +136,7 @@ defmodule Pleroma.Web.Streamer.Worker do
     recipients = MapSet.new(item.recipients)
     domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.info.domain_blocks)
 
-    with parent when not is_nil(parent) <- Object.normalize(item),
+    with parent <- Object.normalize(item) || item,
          true <- Enum.all?([blocks, mutes, reblog_mutes], &(item.actor not in &1)),
          true <- Enum.all?([blocks, mutes], &(parent.data["actor"] not in &1)),
          true <- MapSet.disjoint?(recipients, recipient_blocks),
index 313567bfd331455bcbd14effd5b51b9d349256a5..601f6df498d0b792488f0294eeadf526ac8589b9 100644 (file)
@@ -110,6 +110,24 @@ defmodule Pleroma.Web.StreamerTest do
       Streamer.stream("user:notification", notif)
       Task.await(task)
     end
+
+    test "it sends follow activities to the 'user:notification' stream", %{
+      user: user
+    } do
+      user2 = insert(:user)
+      task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
+
+      Streamer.add_socket(
+        "user:notification",
+        %{transport_pid: task.pid, assigns: %{user: user}}
+      )
+
+      {:ok, _follower, _followed, _activity} = CommonAPI.follow(user2, user)
+
+      # We don't directly pipe the notification to the streamer as it's already
+      # generated as a side effect of CommonAPI.follow().
+      Task.await(task)
+    end
   end
 
   test "it sends to public" do