diff options
author | Maksim Pechnikov <parallel588@gmail.com> | 2020-08-28 18:17:44 +0300 |
---|---|---|
committer | Maksim Pechnikov <parallel588@gmail.com> | 2020-08-28 18:17:44 +0300 |
commit | f0fefc4f5c3aa4fa62f2edee72ee864a16e7176d (patch) | |
tree | da935ab3300f9055b87e920213e2e18549c810d6 /lib | |
parent | 51844b1e420fdfbceed6fda85e4c2e0ad87a9b1e (diff) | |
download | pleroma-f0fefc4f5c3aa4fa62f2edee72ee864a16e7176d.tar.gz pleroma-f0fefc4f5c3aa4fa62f2edee72ee864a16e7176d.zip |
marks notifications as read after mute
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/notification.ex | 12 | ||||
-rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 3 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index c1825f810..b952e81fa 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -648,4 +648,16 @@ defmodule Pleroma.Notification do ) |> Repo.one() end + + @spec mark_as_read(User.t(), Activity.t()) :: {integer(), nil | [term()]} + def mark_as_read(%User{id: id}, %Activity{data: %{"context" => context}}) do + from( + n in Notification, + join: a in assoc(n, :activity), + where: n.user_id == ^id, + where: n.seen == false, + where: fragment("?->>'context'", a.data) == ^context + ) + |> Repo.update_all(set: [seen: true]) + end end diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 5ad2b91c2..43e9e39a8 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -452,7 +452,8 @@ defmodule Pleroma.Web.CommonAPI do end def add_mute(user, activity) do - with {:ok, _} <- ThreadMute.add_mute(user.id, activity.data["context"]) do + with {:ok, _} <- ThreadMute.add_mute(user.id, activity.data["context"]), + _ <- Pleroma.Notification.mark_as_read(user, activity) do {:ok, activity} else {:error, _} -> {:error, dgettext("errors", "conversation is already muted")} |