Merge branch 'admin-fix-duplicated-endpoints' into 'develop'
[akkoma] / lib / pleroma / notification.ex
index 4a6e5d3f931c58b67dbcfcdd80a2cb18203243ba..9e0ce0329e2638652eded2a150d4fc1087c9d013 100644 (file)
@@ -128,6 +128,7 @@ defmodule Pleroma.Notification do
     |> where([user_actor: user_actor], user_actor.is_active)
     |> exclude_notification_muted(user, exclude_notification_muted_opts)
     |> exclude_blocked(user, exclude_blocked_opts)
+    |> exclude_blockers(user)
     |> exclude_filtered(user)
     |> exclude_visibility(opts)
   end
@@ -141,6 +142,17 @@ defmodule Pleroma.Notification do
     |> FollowingRelationship.keep_following_or_not_domain_blocked(user)
   end
 
+  defp exclude_blockers(query, user) do
+    if Pleroma.Config.get([:activitypub, :blockers_visible]) == true do
+      query
+    else
+      blocker_ap_ids = User.incoming_relationships_ungrouped_ap_ids(user, [:block])
+
+      query
+      |> where([n, a], a.actor not in ^blocker_ap_ids)
+    end
+  end
+
   defp exclude_notification_muted(query, _, %{@include_muted_option => true}) do
     query
   end
@@ -471,9 +483,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)