1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.NotificationTest do
11 alias Pleroma.Notification
12 alias Pleroma.Tests.ObanHelpers
14 alias Pleroma.Web.ActivityPub.Transmogrifier
15 alias Pleroma.Web.CommonAPI
16 alias Pleroma.Web.Push
17 alias Pleroma.Web.Streamer
19 describe "create_notifications" do
20 test "creates a notification for an emoji reaction" do
22 other_user = insert(:user)
24 {:ok, activity} = CommonAPI.post(user, %{"status" => "yeah"})
25 {:ok, activity, _object} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
27 {:ok, [notification]} = Notification.create_notifications(activity)
29 assert notification.user_id == user.id
32 test "notifies someone when they are directly addressed" do
34 other_user = insert(:user)
35 third_user = insert(:user)
38 CommonAPI.post(user, %{
39 "status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
42 {:ok, [notification, other_notification]} = Notification.create_notifications(activity)
44 notified_ids = Enum.sort([notification.user_id, other_notification.user_id])
45 assert notified_ids == [other_user.id, third_user.id]
46 assert notification.activity_id == activity.id
47 assert other_notification.activity_id == activity.id
50 test "it creates a notification for subscribed users" do
52 subscriber = insert(:user)
54 User.subscribe(subscriber, user)
56 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
57 {:ok, [notification]} = Notification.create_notifications(status)
59 assert notification.user_id == subscriber.id
62 test "does not create a notification for subscribed users if status is a reply" do
64 other_user = insert(:user)
65 subscriber = insert(:user)
67 User.subscribe(subscriber, other_user)
69 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
71 {:ok, _reply_activity} =
72 CommonAPI.post(other_user, %{
73 "status" => "test reply",
74 "in_reply_to_status_id" => activity.id
77 user_notifications = Notification.for_user(user)
78 assert length(user_notifications) == 1
80 subscriber_notifications = Notification.for_user(subscriber)
81 assert Enum.empty?(subscriber_notifications)
85 describe "create_notification" do
86 @tag needs_streamer: true
87 test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
89 task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
90 task_user_notification = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
91 Streamer.add_socket("user", %{transport_pid: task.pid, assigns: %{user: user}})
95 %{transport_pid: task_user_notification.pid, assigns: %{user: user}}
98 activity = insert(:note_activity)
100 notify = Notification.create_notification(activity, user)
101 assert notify.user_id == user.id
103 Task.await(task_user_notification)
106 test "it creates a notification for user if the user blocks the activity author" do
107 activity = insert(:note_activity)
108 author = User.get_cached_by_ap_id(activity.data["actor"])
110 {:ok, _user_relationship} = User.block(user, author)
112 assert Notification.create_notification(activity, user)
115 test "it creates a notification for the user if the user mutes the activity author" do
116 muter = insert(:user)
117 muted = insert(:user)
118 {:ok, _} = User.mute(muter, muted)
119 muter = Repo.get(User, muter.id)
120 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
122 assert Notification.create_notification(activity, muter)
125 test "notification created if user is muted without notifications" do
126 muter = insert(:user)
127 muted = insert(:user)
129 {:ok, _user_relationships} = User.mute(muter, muted, false)
131 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
133 assert Notification.create_notification(activity, muter)
136 test "it creates a notification for an activity from a muted thread" do
137 muter = insert(:user)
138 other_user = insert(:user)
139 {:ok, activity} = CommonAPI.post(muter, %{"status" => "hey"})
140 CommonAPI.add_mute(muter, activity)
143 CommonAPI.post(other_user, %{
144 "status" => "Hi @#{muter.nickname}",
145 "in_reply_to_status_id" => activity.id
148 assert Notification.create_notification(activity, muter)
151 test "it disables notifications from followers" do
152 follower = insert(:user)
155 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{followers: false})
157 User.follow(follower, followed)
158 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
159 refute Notification.create_notification(activity, followed)
162 test "it disables notifications from non-followers" do
163 follower = insert(:user)
167 notification_settings: %Pleroma.User.NotificationSetting{non_followers: false}
170 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
171 refute Notification.create_notification(activity, followed)
174 test "it disables notifications from people the user follows" do
176 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{follows: false})
178 followed = insert(:user)
179 User.follow(follower, followed)
180 follower = Repo.get(User, follower.id)
181 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
182 refute Notification.create_notification(activity, follower)
185 test "it disables notifications from people the user does not follow" do
187 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{non_follows: false})
189 followed = insert(:user)
190 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
191 refute Notification.create_notification(activity, follower)
194 test "it doesn't create a notification for user if he is the activity author" do
195 activity = insert(:note_activity)
196 author = User.get_cached_by_ap_id(activity.data["actor"])
198 refute Notification.create_notification(activity, author)
201 test "it doesn't create a notification for follow-unfollow-follow chains" do
203 followed_user = insert(:user)
204 {:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
205 Notification.create_notification(activity, followed_user)
206 CommonAPI.unfollow(user, followed_user)
207 {:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
208 refute Notification.create_notification(activity_dupe, followed_user)
211 test "it doesn't create duplicate notifications for follow+subscribed users" do
213 subscriber = insert(:user)
215 {:ok, _, _, _} = CommonAPI.follow(subscriber, user)
216 User.subscribe(subscriber, user)
217 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
218 {:ok, [_notif]} = Notification.create_notifications(status)
221 test "it doesn't create subscription notifications if the recipient cannot see the status" do
223 subscriber = insert(:user)
225 User.subscribe(subscriber, user)
227 {:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
229 assert {:ok, []} == Notification.create_notifications(status)
233 describe "get notification" do
234 test "it gets a notification that belongs to the user" do
236 other_user = insert(:user)
238 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
240 {:ok, [notification]} = Notification.create_notifications(activity)
241 {:ok, notification} = Notification.get(other_user, notification.id)
243 assert notification.user_id == other_user.id
246 test "it returns error if the notification doesn't belong to the user" do
248 other_user = insert(:user)
250 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
252 {:ok, [notification]} = Notification.create_notifications(activity)
253 {:error, _notification} = Notification.get(user, notification.id)
257 describe "dismiss notification" do
258 test "it dismisses a notification that belongs to the user" do
260 other_user = insert(:user)
262 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
264 {:ok, [notification]} = Notification.create_notifications(activity)
265 {:ok, notification} = Notification.dismiss(other_user, notification.id)
267 assert notification.user_id == other_user.id
270 test "it returns error if the notification doesn't belong to the user" do
272 other_user = insert(:user)
274 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
276 {:ok, [notification]} = Notification.create_notifications(activity)
277 {:error, _notification} = Notification.dismiss(user, notification.id)
281 describe "clear notification" do
282 test "it clears all notifications belonging to the user" do
284 other_user = insert(:user)
285 third_user = insert(:user)
288 CommonAPI.post(user, %{
289 "status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
292 {:ok, _notifs} = Notification.create_notifications(activity)
295 CommonAPI.post(user, %{
296 "status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
299 {:ok, _notifs} = Notification.create_notifications(activity)
300 Notification.clear(other_user)
302 assert Notification.for_user(other_user) == []
303 assert Notification.for_user(third_user) != []
307 describe "set_read_up_to()" do
308 test "it sets all notifications as read up to a specified notification ID" do
310 other_user = insert(:user)
313 CommonAPI.post(user, %{
314 "status" => "hey @#{other_user.nickname}!"
318 CommonAPI.post(user, %{
319 "status" => "hey again @#{other_user.nickname}!"
322 [n2, n1] = notifs = Notification.for_user(other_user)
323 assert length(notifs) == 2
328 CommonAPI.post(user, %{
329 "status" => "hey yet again @#{other_user.nickname}!"
332 Notification.set_read_up_to(other_user, n2.id)
334 [n3, n2, n1] = Notification.for_user(other_user)
336 assert n1.seen == true
337 assert n2.seen == true
338 assert n3.seen == false
342 describe "for_user_since/2" do
343 defp days_ago(days) do
345 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
346 -days * 60 * 60 * 24,
351 test "Returns recent notifications" do
352 user1 = insert(:user)
353 user2 = insert(:user)
355 Enum.each(0..10, fn i ->
357 CommonAPI.post(user1, %{
358 "status" => "hey ##{i} @#{user2.nickname}!"
362 {old, new} = Enum.split(Notification.for_user(user2), 5)
364 Enum.each(old, fn notification ->
366 |> cast(%{updated_at: days_ago(10)}, [:updated_at])
367 |> Pleroma.Repo.update!()
370 recent_notifications_ids =
372 |> Notification.for_user_since(
373 NaiveDateTime.add(NaiveDateTime.utc_now(), -5 * 86_400, :second)
377 Enum.each(old, fn %{id: id} ->
378 refute id in recent_notifications_ids
381 Enum.each(new, fn %{id: id} ->
382 assert id in recent_notifications_ids
387 describe "notification target determination / get_notified_from_activity/2" do
388 test "it sends notifications to addressed users in new messages" do
390 other_user = insert(:user)
393 CommonAPI.post(user, %{
394 "status" => "hey @#{other_user.nickname}!"
397 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
399 assert other_user in enabled_receivers
402 test "it sends notifications to mentioned users in new messages" do
404 other_user = insert(:user)
407 "@context" => "https://www.w3.org/ns/activitystreams",
409 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
410 "actor" => user.ap_id,
413 "content" => "message with a Mention tag, but no explicit tagging",
417 "href" => other_user.ap_id,
418 "name" => other_user.nickname
421 "attributedTo" => user.ap_id
425 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
427 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
429 assert other_user in enabled_receivers
432 test "it does not send notifications to users who are only cc in new messages" do
434 other_user = insert(:user)
437 "@context" => "https://www.w3.org/ns/activitystreams",
439 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
440 "cc" => [other_user.ap_id],
441 "actor" => user.ap_id,
444 "content" => "hi everyone",
445 "attributedTo" => user.ap_id
449 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
451 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
453 assert other_user not in enabled_receivers
456 test "it does not send notification to mentioned users in likes" do
458 other_user = insert(:user)
459 third_user = insert(:user)
461 {:ok, activity_one} =
462 CommonAPI.post(user, %{
463 "status" => "hey @#{other_user.nickname}!"
466 {:ok, activity_two, _} = CommonAPI.favorite(activity_one.id, third_user)
468 {enabled_receivers, _disabled_receivers} =
469 Notification.get_notified_from_activity(activity_two)
471 assert other_user not in enabled_receivers
474 test "it does not send notification to mentioned users in announces" do
476 other_user = insert(:user)
477 third_user = insert(:user)
479 {:ok, activity_one} =
480 CommonAPI.post(user, %{
481 "status" => "hey @#{other_user.nickname}!"
484 {:ok, activity_two, _} = CommonAPI.repeat(activity_one.id, third_user)
486 {enabled_receivers, _disabled_receivers} =
487 Notification.get_notified_from_activity(activity_two)
489 assert other_user not in enabled_receivers
492 test_with_mock "it returns blocking recipient in disabled recipients list",
497 other_user = insert(:user)
498 {:ok, _user_relationship} = User.block(other_user, user)
500 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
502 {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
504 assert [] == enabled_receivers
505 assert [other_user] == disabled_receivers
507 assert 1 == length(Repo.all(Notification))
508 refute called(Push.send(:_))
511 test_with_mock "it returns notification-muting recipient in disabled recipients list",
516 other_user = insert(:user)
517 {:ok, _user_relationships} = User.mute(other_user, user)
519 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
521 {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
523 assert [] == enabled_receivers
524 assert [other_user] == disabled_receivers
526 assert 1 == length(Repo.all(Notification))
527 refute called(Push.send(:_))
530 test_with_mock "it returns thread-muting recipient in disabled recipients list",
535 other_user = insert(:user)
537 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
539 {:ok, _} = CommonAPI.add_mute(other_user, activity)
541 {:ok, same_context_activity} =
542 CommonAPI.post(user, %{
543 "status" => "hey-hey-hey @#{other_user.nickname}!",
544 "in_reply_to_status_id" => activity.id
547 {enabled_receivers, disabled_receivers} =
548 Notification.get_notified_from_activity(same_context_activity)
550 assert [other_user] == disabled_receivers
551 refute other_user in enabled_receivers
553 [pre_mute_notification, post_mute_notification] =
554 Repo.all(from(n in Notification, where: n.user_id == ^other_user.id, order_by: n.id))
556 pre_mute_notification_id = pre_mute_notification.id
557 post_mute_notification_id = post_mute_notification.id
562 %Notification{id: ^pre_mute_notification_id} -> true
571 %Notification{id: ^post_mute_notification_id} -> true
579 describe "notification lifecycle" do
580 test "liking an activity results in 1 notification, then 0 if the activity is deleted" do
582 other_user = insert(:user)
584 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
586 assert Enum.empty?(Notification.for_user(user))
588 {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
590 assert length(Notification.for_user(user)) == 1
592 {:ok, _} = CommonAPI.delete(activity.id, user)
594 assert Enum.empty?(Notification.for_user(user))
597 test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
599 other_user = insert(:user)
601 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
603 assert Enum.empty?(Notification.for_user(user))
605 {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
607 assert length(Notification.for_user(user)) == 1
609 {:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
611 assert Enum.empty?(Notification.for_user(user))
614 test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
616 other_user = insert(:user)
618 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
620 assert Enum.empty?(Notification.for_user(user))
622 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
624 assert length(Notification.for_user(user)) == 1
626 {:ok, _} = CommonAPI.delete(activity.id, user)
628 assert Enum.empty?(Notification.for_user(user))
631 test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
633 other_user = insert(:user)
635 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
637 assert Enum.empty?(Notification.for_user(user))
639 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
641 assert length(Notification.for_user(user)) == 1
643 {:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
645 assert Enum.empty?(Notification.for_user(user))
648 test "liking an activity which is already deleted does not generate a notification" do
650 other_user = insert(:user)
652 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
654 assert Enum.empty?(Notification.for_user(user))
656 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
658 assert Enum.empty?(Notification.for_user(user))
660 {:error, _} = CommonAPI.favorite(activity.id, other_user)
662 assert Enum.empty?(Notification.for_user(user))
665 test "repeating an activity which is already deleted does not generate a notification" do
667 other_user = insert(:user)
669 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
671 assert Enum.empty?(Notification.for_user(user))
673 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
675 assert Enum.empty?(Notification.for_user(user))
677 {:error, _} = CommonAPI.repeat(activity.id, other_user)
679 assert Enum.empty?(Notification.for_user(user))
682 test "replying to a deleted post without tagging does not generate a notification" do
684 other_user = insert(:user)
686 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
687 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
689 {:ok, _reply_activity} =
690 CommonAPI.post(other_user, %{
691 "status" => "test reply",
692 "in_reply_to_status_id" => activity.id
695 assert Enum.empty?(Notification.for_user(user))
698 test "notifications are deleted if a local user is deleted" do
700 other_user = insert(:user)
703 CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}", "visibility" => "direct"})
705 refute Enum.empty?(Notification.for_user(other_user))
707 {:ok, job} = User.delete(user)
708 ObanHelpers.perform(job)
710 assert Enum.empty?(Notification.for_user(other_user))
713 test "notifications are deleted if a remote user is deleted" do
714 remote_user = insert(:user)
715 local_user = insert(:user)
718 "@context" => "https://www.w3.org/ns/activitystreams",
720 "actor" => remote_user.ap_id,
721 "id" => remote_user.ap_id <> "/activities/test",
722 "to" => [local_user.ap_id],
726 "content" => "Hello!",
730 "href" => local_user.ap_id,
731 "name" => "@#{local_user.nickname}"
734 "to" => [local_user.ap_id],
736 "attributedTo" => remote_user.ap_id
740 {:ok, _dm_activity} = Transmogrifier.handle_incoming(dm_message)
742 refute Enum.empty?(Notification.for_user(local_user))
744 delete_user_message = %{
745 "@context" => "https://www.w3.org/ns/activitystreams",
746 "id" => remote_user.ap_id <> "/activities/delete",
747 "actor" => remote_user.ap_id,
749 "object" => remote_user.ap_id
752 {:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
753 ObanHelpers.perform_all()
755 assert Enum.empty?(Notification.for_user(local_user))
758 test "move activity generates a notification" do
759 %{ap_id: old_ap_id} = old_user = insert(:user)
760 %{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
761 follower = insert(:user)
762 other_follower = insert(:user, %{allow_following_move: false})
764 User.follow(follower, old_user)
765 User.follow(other_follower, old_user)
767 Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
768 ObanHelpers.perform_all()
770 assert [] = Notification.for_user(follower)
775 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
778 ] = Notification.for_user(follower, %{with_move: true})
780 assert [] = Notification.for_user(other_follower)
785 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
788 ] = Notification.for_user(other_follower, %{with_move: true})
792 describe "for_user" do
793 test "it returns notifications for muted user without notifications" do
795 muted = insert(:user)
796 {:ok, _user_relationships} = User.mute(user, muted, false)
798 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
800 assert length(Notification.for_user(user)) == 1
803 test "it doesn't return notifications for muted user with notifications" do
805 muted = insert(:user)
806 {:ok, _user_relationships} = User.mute(user, muted)
808 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
810 assert Notification.for_user(user) == []
813 test "it doesn't return notifications for blocked user" do
815 blocked = insert(:user)
816 {:ok, _user_relationship} = User.block(user, blocked)
818 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
820 assert Notification.for_user(user) == []
823 test "it doesn't return notificatitons for blocked domain" do
825 blocked = insert(:user, ap_id: "http://some-domain.com")
826 {:ok, user} = User.block_domain(user, "some-domain.com")
828 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
830 assert Notification.for_user(user) == []
833 test "it doesn't return notifications for muted thread" do
835 another_user = insert(:user)
837 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
839 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
840 assert Notification.for_user(user) == []
843 test "it returns notifications from a muted user when with_muted is set" do
845 muted = insert(:user)
846 {:ok, _user_relationships} = User.mute(user, muted)
848 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
850 assert length(Notification.for_user(user, %{with_muted: true})) == 1
853 test "it doesn't return notifications from a blocked user when with_muted is set" do
855 blocked = insert(:user)
856 {:ok, _user_relationship} = User.block(user, blocked)
858 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
860 assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
863 test "it doesn't return notifications from a domain-blocked user when with_muted is set" do
865 blocked = insert(:user, ap_id: "http://some-domain.com")
866 {:ok, user} = User.block_domain(user, "some-domain.com")
868 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
870 assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
873 test "it returns notifications from muted threads when with_muted is set" do
875 another_user = insert(:user)
877 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
879 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
880 assert length(Notification.for_user(user, %{with_muted: true})) == 1