Add check on activity visibility in sub notification
authorSadposter <hannah+pleroma@coffee-and-dreams.uk>
Sun, 7 Apr 2019 14:11:29 +0000 (15:11 +0100)
committerSadposter <hannah+pleroma@coffee-and-dreams.uk>
Sun, 7 Apr 2019 14:11:29 +0000 (15:11 +0100)
lib/pleroma/web/common_api/utils.ex
test/notification_test.exs

index 4e0a6b2d9be8e5c927a422d600804b4d9adfc8d5..a450a70c3bfa9b9d0fb71d79bb6c2e420dd18f3f 100644 (file)
@@ -12,6 +12,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
   alias Pleroma.Repo
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.Utils
+  alias Pleroma.Web.ActivityPub.Visibility
   alias Pleroma.Web.Endpoint
   alias Pleroma.Web.MediaProxy
 
@@ -337,13 +338,14 @@ defmodule Pleroma.Web.CommonAPI.Utils do
 
   def maybe_notify_subscribers(
         recipients,
-        %Activity{data: %{"actor" => actor, "type" => type}}
+        %Activity{data: %{"actor" => actor, "type" => type}} = activity
       )
       when type == "Create" do
     with %User{} = user <- User.get_by_ap_id(actor) do
       subscriber_ids =
         user
         |> User.subscribers()
+        |> Enum.filter(&Visibility.visible_for_user?(activity, &1))
         |> Enum.map(& &1.ap_id)
 
       recipients ++ subscriber_ids
index 8109623affed59e009948b42b40a386b2e3e2fcf..5727620c9b5fe41bcb327085b2fe60cc30176559 100644 (file)
@@ -106,6 +106,18 @@ defmodule Pleroma.NotificationTest do
       {:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
       {:ok, [_notif]} = Notification.create_notifications(status)
     end
+
+    test "it doesn't create subscription notifications if the recipient cannot see the status" do
+      user = insert(:user)
+      subscriber = insert(:user)
+
+      User.subscribe(subscriber, user)
+
+      {:ok, status} =
+        TwitterAPI.create_status(user, %{"status" => "inwisible", "visibility" => "direct"})
+
+      assert {:ok, []} == Notification.create_notifications(status)
+    end
   end
 
   describe "get notification" do