Merge branch 'dismiss-notification-on-follow-request-rejection' into 'develop'
Dismiss the follow request notification on rejection See merge request pleroma/pleroma!2447
This commit is contained in:
commit
a81342a234
|
@ -261,6 +261,16 @@ def destroy_multiple(%{id: user_id} = _user, ids) do
|
||||||
|> Repo.delete_all()
|
|> Repo.delete_all()
|
||||||
end
|
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
|
def dismiss(%{id: user_id} = _user, id) do
|
||||||
notification = Repo.get(Notification, id)
|
notification = Repo.get(Notification, id)
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.CommonAPI do
|
||||||
alias Pleroma.ActivityExpiration
|
alias Pleroma.ActivityExpiration
|
||||||
alias Pleroma.Conversation.Participation
|
alias Pleroma.Conversation.Participation
|
||||||
alias Pleroma.FollowingRelationship
|
alias Pleroma.FollowingRelationship
|
||||||
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.ThreadMute
|
alias Pleroma.ThreadMute
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@ -61,6 +62,7 @@ def reject_follow_request(follower, followed) do
|
||||||
with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
|
with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
|
||||||
{:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "reject"),
|
{:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "reject"),
|
||||||
{:ok, _relationship} <- FollowingRelationship.update(follower, followed, :follow_reject),
|
{:ok, _relationship} <- FollowingRelationship.update(follower, followed, :follow_reject),
|
||||||
|
{:ok, _notifications} <- Notification.dismiss(follow_activity),
|
||||||
{:ok, _activity} <-
|
{:ok, _activity} <-
|
||||||
ActivityPub.reject(%{
|
ActivityPub.reject(%{
|
||||||
to: [follower.ap_id],
|
to: [follower.ap_id],
|
||||||
|
|
|
@ -362,6 +362,16 @@ test "it doesn't create a notification for follow-unfollow-follow chains" do
|
||||||
notification_id = notification.id
|
notification_id = notification.id
|
||||||
assert [%{id: ^notification_id}] = Notification.for_user(followed_user)
|
assert [%{id: ^notification_id}] = Notification.for_user(followed_user)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "get notification" do
|
describe "get notification" do
|
||||||
|
|
Loading…
Reference in a new issue