aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-04-30 18:38:52 +0000
committerlain <lain@soykaf.club>2020-04-30 18:38:52 +0000
commita81342a234a3808e2115c888a45c524e39a6ab60 (patch)
tree0df42c05eeb882d9aa354b5990e74f4b76412393
parent55a3a3c3e52247427cf0c5b1ad459e86a2be0097 (diff)
parentbef34568f0d005baabca266b99ac0f6e620e6899 (diff)
downloadpleroma-a81342a234a3808e2115c888a45c524e39a6ab60.tar.gz
Merge branch 'dismiss-notification-on-follow-request-rejection' into 'develop'
Dismiss the follow request notification on rejection See merge request pleroma/pleroma!2447
-rw-r--r--lib/pleroma/notification.ex10
-rw-r--r--lib/pleroma/web/common_api/common_api.ex2
-rw-r--r--test/notification_test.exs10
3 files changed, 22 insertions, 0 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex
index aaa675253..9a109dfab 100644
--- a/lib/pleroma/notification.ex
+++ b/lib/pleroma/notification.ex
@@ -261,6 +261,16 @@ defmodule Pleroma.Notification do
|> Repo.delete_all()
end
+ def dismiss(%Pleroma.Activity{} = activity) do
+ Notification
+ |> where([n], n.activity_id == ^activity.id)
+ |> Repo.delete_all()
+ |> case do
+ {_, notifications} -> {:ok, notifications}
+ _ -> {:error, "Cannot dismiss notification"}
+ end
+ end
+
def dismiss(%{id: user_id} = _user, id) do
notification = Repo.get(Notification, id)
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index d1efe0c36..4112e441a 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.CommonAPI do
alias Pleroma.ActivityExpiration
alias Pleroma.Conversation.Participation
alias Pleroma.FollowingRelationship
+ alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.ThreadMute
alias Pleroma.User
@@ -61,6 +62,7 @@ defmodule Pleroma.Web.CommonAPI do
with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
{:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "reject"),
{:ok, _relationship} <- FollowingRelationship.update(follower, followed, :follow_reject),
+ {:ok, _notifications} <- Notification.dismiss(follow_activity),
{:ok, _activity} <-
ActivityPub.reject(%{
to: [follower.ap_id],
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 6ad824c57..0e9ffcb18 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -362,6 +362,16 @@ defmodule Pleroma.NotificationTest do
notification_id = notification.id
assert [%{id: ^notification_id}] = Notification.for_user(followed_user)
end
+
+ test "dismisses the notification on follow request rejection" do
+ clear_config([:notifications, :enable_follow_request_notifications], true)
+ user = insert(:user, locked: true)
+ follower = insert(:user)
+ {:ok, _, _, _follow_activity} = CommonAPI.follow(follower, user)
+ assert [notification] = Notification.for_user(user)
+ {:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
+ assert [] = Notification.for_user(user)
+ end
end
describe "get notification" do