diff options
author | feld <feld@feld.me> | 2020-08-25 21:32:32 +0000 |
---|---|---|
committer | feld <feld@feld.me> | 2020-08-25 21:32:32 +0000 |
commit | fb33321fa2b3638af1c1edc35de1e4d23ba18711 (patch) | |
tree | 53fe5e1774537d984c0c7443f5eb0d7ebf04442f /lib | |
parent | 976094cd7bdeed740a3dce8b8aac029d06603ed3 (diff) | |
parent | 25c69e271a3ea6687805e0bd0d4b902cda06e364 (diff) | |
download | pleroma-fb33321fa2b3638af1c1edc35de1e4d23ba18711.tar.gz |
Merge branch 'feature/1952-read-muted-notifications' into 'develop'
Automatically mark notifications about statuses from muted users and threads as read
Closes #1952
See merge request pleroma/pleroma!2893
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/notification.ex | 7 | ||||
-rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 0b171563b..c1825f810 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -15,6 +15,7 @@ defmodule Pleroma.Notification do alias Pleroma.Repo alias Pleroma.ThreadMute alias Pleroma.User + alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.Push alias Pleroma.Web.Streamer @@ -441,6 +442,7 @@ defmodule Pleroma.Notification do |> Multi.insert(:notification, %Notification{ user_id: user.id, activity: activity, + seen: mark_as_read?(activity, user), type: type_from_activity(activity) }) |> Marker.multi_set_last_read_id(user, "notifications") @@ -634,6 +636,11 @@ defmodule Pleroma.Notification do def skip?(_, _, _), do: false + def mark_as_read?(activity, target_user) do + user = Activity.user_actor(activity) + User.mutes_user?(target_user, user) || CommonAPI.thread_muted?(target_user, activity) + end + def for_user_and_activity(user, activity) do from(n in __MODULE__, where: n.user_id == ^user.id, diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index a8141b28f..5ad2b91c2 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -465,7 +465,7 @@ defmodule Pleroma.Web.CommonAPI do end def thread_muted?(%User{id: user_id}, %{data: %{"context" => context}}) - when is_binary("context") do + when is_binary(context) do ThreadMute.exists?(user_id, context) end |