mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
Mark notifications about statuses from muted users as read automatically
This commit is contained in:
parent
ec242b4706
commit
0865f36965
3 changed files with 12 additions and 2 deletions
|
@ -441,6 +441,7 @@ defmodule Pleroma.Notification do
|
||||||
|> Multi.insert(:notification, %Notification{
|
|> Multi.insert(:notification, %Notification{
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
activity: activity,
|
activity: activity,
|
||||||
|
seen: mark_as_read?(activity, user),
|
||||||
type: type_from_activity(activity)
|
type: type_from_activity(activity)
|
||||||
})
|
})
|
||||||
|> Marker.multi_set_last_read_id(user, "notifications")
|
|> Marker.multi_set_last_read_id(user, "notifications")
|
||||||
|
@ -634,6 +635,11 @@ defmodule Pleroma.Notification do
|
||||||
|
|
||||||
def skip?(_, _, _), do: false
|
def skip?(_, _, _), do: false
|
||||||
|
|
||||||
|
def mark_as_read?(activity, target_user) do
|
||||||
|
user = Activity.user_actor(activity)
|
||||||
|
User.mutes_user?(target_user, user)
|
||||||
|
end
|
||||||
|
|
||||||
def for_user_and_activity(user, activity) do
|
def for_user_and_activity(user, activity) do
|
||||||
from(n in __MODULE__,
|
from(n in __MODULE__,
|
||||||
where: n.user_id == ^user.id,
|
where: n.user_id == ^user.id,
|
||||||
|
|
|
@ -217,7 +217,10 @@ defmodule Pleroma.NotificationTest do
|
||||||
muter = Repo.get(User, muter.id)
|
muter = Repo.get(User, muter.id)
|
||||||
{:ok, activity} = CommonAPI.post(muted, %{status: "Hi @#{muter.nickname}"})
|
{:ok, activity} = CommonAPI.post(muted, %{status: "Hi @#{muter.nickname}"})
|
||||||
|
|
||||||
assert Notification.create_notification(activity, muter)
|
notification = Notification.create_notification(activity, muter)
|
||||||
|
|
||||||
|
assert notification.id
|
||||||
|
assert notification.seen
|
||||||
end
|
end
|
||||||
|
|
||||||
test "notification created if user is muted without notifications" do
|
test "notification created if user is muted without notifications" do
|
||||||
|
@ -1012,6 +1015,7 @@ defmodule Pleroma.NotificationTest do
|
||||||
[notification] = Notification.for_user(user)
|
[notification] = Notification.for_user(user)
|
||||||
|
|
||||||
assert notification.activity.object
|
assert notification.activity.object
|
||||||
|
assert notification.seen
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it doesn't return notifications for muted user with notifications", %{user: user} do
|
test "it doesn't return notifications for muted user with notifications", %{user: user} do
|
||||||
|
|
|
@ -219,7 +219,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
id: to_string(notification.id),
|
id: to_string(notification.id),
|
||||||
pleroma: %{is_seen: false, is_muted: true},
|
pleroma: %{is_seen: true, is_muted: true},
|
||||||
type: "favourite",
|
type: "favourite",
|
||||||
account: AccountView.render("show.json", %{user: another_user, for: user}),
|
account: AccountView.render("show.json", %{user: another_user, for: user}),
|
||||||
status: StatusView.render("show.json", %{activity: create_activity, for: user}),
|
status: StatusView.render("show.json", %{activity: create_activity, for: user}),
|
||||||
|
|
Loading…
Reference in a new issue