|> 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)
alias Pleroma.ActivityExpiration
alias Pleroma.Conversation.Participation
alias Pleroma.FollowingRelationship
+ alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.ThreadMute
alias Pleroma.User
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],
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