Exclude blockers from notifications when `blockers_visible: false`
authorAlex Gleason <alex@alexgleason.me>
Wed, 6 Jan 2021 21:39:14 +0000 (15:39 -0600)
committerAlex Gleason <alex@alexgleason.me>
Wed, 6 Jan 2021 21:39:14 +0000 (15:39 -0600)
lib/pleroma/notification.ex
test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs

index dd7a1c82405f6e8e8ed5fd926bfeb2d2e5a494b5..e9c9b3ea285cf1100a24ae7a071ae4504a0999b4 100644 (file)
@@ -132,6 +132,7 @@ defmodule Pleroma.Notification do
     |> preload([n, a, o], activity: {a, object: o})
     |> exclude_notification_muted(user, exclude_notification_muted_opts)
     |> exclude_blocked(user, exclude_blocked_opts)
+    |> exclude_blockers(user)
     |> exclude_filtered(user)
     |> exclude_visibility(opts)
   end
@@ -145,6 +146,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
index 9ac8488f627ae84f02ce0960dc871fc4e167d458..ef35bdd0086ebc6822b555e4a9e8382f4c8ce456 100644 (file)
@@ -103,6 +103,25 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
     assert [_] = result
   end
 
+  test "excludes mentions from blockers when blockers_visible is false" do
+    clear_config([:activitypub, :blockers_visible], false)
+
+    %{user: user, conn: conn} = oauth_access(["read:notifications"])
+    blocker = insert(:user)
+
+    {:ok, _} = CommonAPI.block(blocker, user)
+    {:ok, activity} = CommonAPI.post(blocker, %{status: "hi @#{user.nickname}"})
+
+    {:ok, [_notification]} = Notification.create_notifications(activity)
+
+    conn =
+      conn
+      |> assign(:user, user)
+      |> get("/api/v1/notifications")
+
+    assert [] == json_response_and_validate_schema(conn, 200)
+  end
+
   test "getting a single notification" do
     %{user: user, conn: conn} = oauth_access(["read:notifications"])
     other_user = insert(:user)