diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/notification.ex | 8 | ||||
-rw-r--r-- | lib/pleroma/user.ex | 16 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index aba6096bc..d661d6ab2 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -338,6 +338,14 @@ defmodule Pleroma.Notification do |> Repo.delete_all() end + def destroy_multiple_from_types(%{id: user_id}, types) do + from(n in Notification, + where: n.user_id == ^user_id, + where: n.type in ^types + ) + |> Repo.delete_all() + end + def dismiss(%Pleroma.Activity{} = activity) do Notification |> where([n], n.activity_id == ^activity.id) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index f6e30555c..f32907f01 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1202,10 +1202,24 @@ defmodule Pleroma.User do |> update_and_set_cache() end - def update_and_set_cache(changeset) do + def update_and_set_cache(%{data: %Pleroma.User{} = user} = changeset) do + was_superuser_before_update = User.superuser?(user) + with {:ok, user} <- Repo.update(changeset, stale_error_field: :id) do set_cache(user) end + |> maybe_remove_report_notifications(was_superuser_before_update) + end + + defp maybe_remove_report_notifications({:ok, %Pleroma.User{} = user} = result, true) do + if not User.superuser?(user), + do: user |> Notification.destroy_multiple_from_types(["pleroma:report"]) + + result + end + + defp maybe_remove_report_notifications(result, _) do + result end def get_user_friends_ap_ids(user) do |