Poll notification: only notify local users
authorAlex Gleason <alex@alexgleason.me>
Sun, 18 Jul 2021 16:03:56 +0000 (11:03 -0500)
committerAlex Gleason <alex@alexgleason.me>
Sun, 18 Jul 2021 16:10:23 +0000 (11:10 -0500)
lib/pleroma/notification.ex
test/pleroma/notification_test.exs

index 4a6e5d3f931c58b67dbcfcdd80a2cb18203243ba..32f13df69c31a6400d77156b6fdfcaba36e0289d 100644 (file)
@@ -471,9 +471,11 @@ defmodule Pleroma.Notification do
         end
 
       notifications =
-        Enum.map([actor | voters], fn ap_id ->
-          with %User{} = user <- User.get_by_ap_id(ap_id) do
-            create_notification(activity, user, type: "poll")
+        Enum.reduce([actor | voters], [], fn ap_id, acc ->
+          with %User{local: true} = user <- User.get_by_ap_id(ap_id) do
+            [create_notification(activity, user, type: "poll") | acc]
+          else
+            _ -> acc
           end
         end)
 
index 0d2cacb57a6c465ff930b08f7f0b023d584c560e..3810e772b1fd25a388a84051bcbfc0c20981dfee 100644 (file)
@@ -139,7 +139,7 @@ defmodule Pleroma.NotificationTest do
 
     {:ok, notifications} = Notification.create_poll_notifications(activity)
 
-    assert [user1.id, user3.id, user2.id] == Enum.map(notifications, & &1.user_id)
+    assert [user2.id, user3.id, user1.id] == Enum.map(notifications, & &1.user_id)
   end
 
   describe "CommonApi.post/2 notification-related functionality" do