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 @@ def create_notification(%Activity{} = activity, %User{} = user, do_send \\ true)
|
|||
|> 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 +635,11 @@ def skip?(:filtered, activity, user) do
|
|||
|
||||
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
|
||||
from(n in __MODULE__,
|
||||
where: n.user_id == ^user.id,
|
||||
|
|
|
@ -217,7 +217,10 @@ test "it creates a notification for the user if the user mutes the activity auth
|
|||
muter = Repo.get(User, muter.id)
|
||||
{: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
|
||||
|
||||
test "notification created if user is muted without notifications" do
|
||||
|
@ -1012,6 +1015,7 @@ test "it returns notifications for muted user without notifications", %{user: us
|
|||
[notification] = Notification.for_user(user)
|
||||
|
||||
assert notification.activity.object
|
||||
assert notification.seen
|
||||
end
|
||||
|
||||
test "it doesn't return notifications for muted user with notifications", %{user: user} do
|
||||
|
|
|
@ -219,7 +219,7 @@ test "muted notification" do
|
|||
|
||||
expected = %{
|
||||
id: to_string(notification.id),
|
||||
pleroma: %{is_seen: false, is_muted: true},
|
||||
pleroma: %{is_seen: true, is_muted: true},
|
||||
type: "favourite",
|
||||
account: AccountView.render("show.json", %{user: another_user, for: user}),
|
||||
status: StatusView.render("show.json", %{activity: create_activity, for: user}),
|
||||
|
|
Loading…
Reference in a new issue