From 5adce547d0f68c9762246fc2c7da9a1979601e31 Mon Sep 17 00:00:00 2001 From: Alexander Tumin Date: Tue, 7 Feb 2023 15:30:07 +0300 Subject: [PATCH] Require related object for notifications to filter on content --- lib/pleroma/notification.ex | 1 + test/pleroma/notification_test.exs | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 1989bb50c..885d61233 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -195,6 +195,7 @@ defp exclude_filtered(query, user) do from([_n, a, o] in query, where: fragment("not(?->>'content' ~* ?)", o.data, ^regex) or + fragment("?->>'content' is null", o.data) or fragment("?->>'actor' = ?", o.data, ^user.ap_id) ) end diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index 6bc6dff1a..4905cb7eb 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -1251,5 +1251,32 @@ test "it returns notifications about favorites with filtered word", %{user: user assert length(Notification.for_user(user)) == 1 end + + test "it returns notifications when related object is without content and filters are defined", + %{user: user} do + followed_user = insert(:user, is_locked: true) + + insert(:filter, user: followed_user, phrase: "test", hide: true) + + {:ok, _, _, _activity} = CommonAPI.follow(user, followed_user) + refute FollowingRelationship.following?(user, followed_user) + assert [notification] = Notification.for_user(followed_user) + + assert %{type: "follow_request"} = + NotificationView.render("show.json", %{ + notification: notification, + for: followed_user + }) + + assert {:ok, _} = CommonAPI.accept_follow_request(user, followed_user) + + assert [notification] = Notification.for_user(followed_user) + + assert %{type: "follow"} = + NotificationView.render("show.json", %{ + notification: notification, + for: followed_user + }) + end end end