From fd287387a042b86a62d80c41b1dd282316b6609b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 23 Jul 2019 13:14:26 -0500 Subject: [PATCH 1/3] Do not notify subscribers for messages from users which are replies to others --- lib/pleroma/web/common_api/utils.ex | 6 ++++++ test/notification_test.exs | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index fcc000969..6f0f56d96 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -439,6 +439,12 @@ def maybe_notify_mentioned_recipients( def maybe_notify_mentioned_recipients(recipients, _), do: recipients + def maybe_notify_subscribers(_, %Activity{ + data: %{"object" => %Object{data: %{"inReplyTo" => _ap_id}}} + }) do + :nothing + end + def maybe_notify_subscribers( recipients, %Activity{data: %{"actor" => actor, "type" => type}} = activity diff --git a/test/notification_test.exs b/test/notification_test.exs index dda570b49..06f0b6557 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -42,6 +42,24 @@ test "it creates a notification for subscribed users" do assert notification.user_id == subscriber.id end + + test "does not create a notification for subscribed users if status is a reply" do + user = insert(:user) + other_user = insert(:user) + subscriber = insert(:user) + + User.subscribe(subscriber, other_user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) + + {:ok, reply_activity} = + CommonAPI.post(other_user, %{ + "status" => "test reply", + "in_reply_to_status_id" => activity.id + }) + + refute Notification.create_notification(reply_activity, subscriber) + end end describe "create_notification" do From 6a79bb12c38bce6287b29c79c1ad3b7f9b967b69 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 23 Jul 2019 13:53:05 -0500 Subject: [PATCH 2/3] Fix function --- lib/pleroma/web/common_api/utils.ex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 6f0f56d96..94462c3dd 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -439,10 +439,11 @@ def maybe_notify_mentioned_recipients( def maybe_notify_mentioned_recipients(recipients, _), do: recipients - def maybe_notify_subscribers(_, %Activity{ - data: %{"object" => %Object{data: %{"inReplyTo" => _ap_id}}} + # Do not notify subscribers if author is making a reply + def maybe_notify_subscribers(recipients, %Activity{ + object: %Object{data: %{"inReplyTo" => _ap_id}} }) do - :nothing + recipients end def maybe_notify_subscribers( From ec7b085b76996bee7eaa60c21b9d8a0cba382a65 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 23 Jul 2019 13:57:22 -0500 Subject: [PATCH 3/3] Fix test --- test/notification_test.exs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/notification_test.exs b/test/notification_test.exs index 06f0b6557..28f8df49d 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -52,13 +52,17 @@ test "does not create a notification for subscribed users if status is a reply" {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) - {:ok, reply_activity} = + {:ok, _reply_activity} = CommonAPI.post(other_user, %{ "status" => "test reply", "in_reply_to_status_id" => activity.id }) - refute Notification.create_notification(reply_activity, subscriber) + user_notifications = Notification.for_user(user) + assert length(user_notifications) == 1 + + subscriber_notifications = Notification.for_user(subscriber) + assert Enum.empty?(subscriber_notifications) end end