Dismiss the follow request notification on rejection
authoreugenijm <eugenijm@protonmail.com>
Thu, 30 Apr 2020 12:02:35 +0000 (15:02 +0300)
committerrinpatch <rinpatch@sdf.org>
Sat, 2 May 2020 16:16:27 +0000 (19:16 +0300)
lib/pleroma/notification.ex
lib/pleroma/web/common_api/common_api.ex

index 815356a5e5ed12c5b46753865428dec2144dcca0..556075fbab791ee7a34541f2bbbb76c83d3e0d54 100644 (file)
@@ -271,6 +271,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)
 
index c847820086a55a29c6898822158b9c3f698032c2..74e9e8cfa500d19db45c5e9b814256c183146e77 100644 (file)
@@ -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
@@ -58,6 +59,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],