diff options
author | lain <lain@soykaf.club> | 2020-08-31 09:21:02 +0000 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-08-31 09:21:02 +0000 |
commit | e0eb90f62a5c8cc14c8fd7fc82ab54342f6fe209 (patch) | |
tree | 8a0f40e1b1fb261cb1644472d79f3a65f5ced623 /lib | |
parent | 0417b2f649172ea300c124159aa86b964e404a0c (diff) | |
parent | d91c4feebeb199f7c584f0a4292ce6f9cc331798 (diff) | |
download | pleroma-e0eb90f62a5c8cc14c8fd7fc82ab54342f6fe209.tar.gz |
Merge branch 'issue/2068' into 'develop'
[#2068] marks notifications as read after mute
Closes #2068
See merge request pleroma/pleroma!2930
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..8868a910e 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -648,4 +648,16 @@ defmodule Pleroma.Notification do ) |> Repo.one() end + + @spec mark_context_as_read(User.t(), String.t()) :: {integer(), nil | [term()]} + def mark_context_as_read(%User{id: id}, 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..4ab533658 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_context_as_read(user, activity.data["context"]) do {:ok, activity} else {:error, _} -> {:error, dgettext("errors", "conversation is already muted")} |