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 "CommonApi.post/2 notification-related functionality" do
86 test_with_mock "creates but does NOT send notification to blocker user",
91 blocker = insert(:user)
92 {:ok, _user_relationship} = User.block(blocker, user)
94 {:ok, _activity} = CommonAPI.post(user, %{"status" => "hey @#{blocker.nickname}!"})
96 blocker_id = blocker.id
97 assert [%Notification{user_id: ^blocker_id}] = Repo.all(Notification)
98 refute called(Push.send(:_))
101 test_with_mock "creates but does NOT send notification to notification-muter user",
106 muter = insert(:user)
107 {:ok, _user_relationships} = User.mute(muter, user)
109 {:ok, _activity} = CommonAPI.post(user, %{"status" => "hey @#{muter.nickname}!"})
112 assert [%Notification{user_id: ^muter_id}] = Repo.all(Notification)
113 refute called(Push.send(:_))
116 test_with_mock "creates but does NOT send notification to thread-muter user",
121 thread_muter = insert(:user)
123 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{thread_muter.nickname}!"})
125 {:ok, _} = CommonAPI.add_mute(thread_muter, activity)
127 {:ok, _same_context_activity} =
128 CommonAPI.post(user, %{
129 "status" => "hey-hey-hey @#{thread_muter.nickname}!",
130 "in_reply_to_status_id" => activity.id
133 [pre_mute_notification, post_mute_notification] =
134 Repo.all(from(n in Notification, where: n.user_id == ^thread_muter.id, order_by: n.id))
136 pre_mute_notification_id = pre_mute_notification.id
137 post_mute_notification_id = post_mute_notification.id
142 %Notification{id: ^pre_mute_notification_id} -> true
151 %Notification{id: ^post_mute_notification_id} -> true
159 describe "create_notification" do
160 @tag needs_streamer: true
161 test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
163 task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
164 task_user_notification = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
165 Streamer.add_socket("user", %{transport_pid: task.pid, assigns: %{user: user}})
169 %{transport_pid: task_user_notification.pid, assigns: %{user: user}}
172 activity = insert(:note_activity)
174 notify = Notification.create_notification(activity, user)
175 assert notify.user_id == user.id
177 Task.await(task_user_notification)
180 test "it creates a notification for user if the user blocks the activity author" do
181 activity = insert(:note_activity)
182 author = User.get_cached_by_ap_id(activity.data["actor"])
184 {:ok, _user_relationship} = User.block(user, author)
186 assert Notification.create_notification(activity, user)
189 test "it creates a notification for the user if the user mutes the activity author" do
190 muter = insert(:user)
191 muted = insert(:user)
192 {:ok, _} = User.mute(muter, muted)
193 muter = Repo.get(User, muter.id)
194 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
196 assert Notification.create_notification(activity, muter)
199 test "notification created if user is muted without notifications" do
200 muter = insert(:user)
201 muted = insert(:user)
203 {:ok, _user_relationships} = User.mute(muter, muted, false)
205 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
207 assert Notification.create_notification(activity, muter)
210 test "it creates a notification for an activity from a muted thread" do
211 muter = insert(:user)
212 other_user = insert(:user)
213 {:ok, activity} = CommonAPI.post(muter, %{"status" => "hey"})
214 CommonAPI.add_mute(muter, activity)
217 CommonAPI.post(other_user, %{
218 "status" => "Hi @#{muter.nickname}",
219 "in_reply_to_status_id" => activity.id
222 assert Notification.create_notification(activity, muter)
225 test "it disables notifications from followers" do
226 follower = insert(:user)
229 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{followers: false})
231 User.follow(follower, followed)
232 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
233 refute Notification.create_notification(activity, followed)
236 test "it disables notifications from non-followers" do
237 follower = insert(:user)
241 notification_settings: %Pleroma.User.NotificationSetting{non_followers: false}
244 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
245 refute Notification.create_notification(activity, followed)
248 test "it disables notifications from people the user follows" do
250 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{follows: false})
252 followed = insert(:user)
253 User.follow(follower, followed)
254 follower = Repo.get(User, follower.id)
255 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
256 refute Notification.create_notification(activity, follower)
259 test "it disables notifications from people the user does not follow" do
261 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{non_follows: false})
263 followed = insert(:user)
264 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
265 refute Notification.create_notification(activity, follower)
268 test "it doesn't create a notification for user if he is the activity author" do
269 activity = insert(:note_activity)
270 author = User.get_cached_by_ap_id(activity.data["actor"])
272 refute Notification.create_notification(activity, author)
275 test "it doesn't create a notification for follow-unfollow-follow chains" do
277 followed_user = insert(:user)
278 {:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
279 Notification.create_notification(activity, followed_user)
280 CommonAPI.unfollow(user, followed_user)
281 {:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
282 refute Notification.create_notification(activity_dupe, followed_user)
285 test "it doesn't create duplicate notifications for follow+subscribed users" do
287 subscriber = insert(:user)
289 {:ok, _, _, _} = CommonAPI.follow(subscriber, user)
290 User.subscribe(subscriber, user)
291 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
292 {:ok, [_notif]} = Notification.create_notifications(status)
295 test "it doesn't create subscription notifications if the recipient cannot see the status" do
297 subscriber = insert(:user)
299 User.subscribe(subscriber, user)
301 {:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
303 assert {:ok, []} == Notification.create_notifications(status)
307 describe "get notification" do
308 test "it gets a notification that belongs to the user" do
310 other_user = insert(:user)
312 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
314 {:ok, [notification]} = Notification.create_notifications(activity)
315 {:ok, notification} = Notification.get(other_user, notification.id)
317 assert notification.user_id == other_user.id
320 test "it returns error if the notification doesn't belong to the user" do
322 other_user = insert(:user)
324 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
326 {:ok, [notification]} = Notification.create_notifications(activity)
327 {:error, _notification} = Notification.get(user, notification.id)
331 describe "dismiss notification" do
332 test "it dismisses a notification that belongs to the user" do
334 other_user = insert(:user)
336 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
338 {:ok, [notification]} = Notification.create_notifications(activity)
339 {:ok, notification} = Notification.dismiss(other_user, notification.id)
341 assert notification.user_id == other_user.id
344 test "it returns error if the notification doesn't belong to the user" do
346 other_user = insert(:user)
348 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
350 {:ok, [notification]} = Notification.create_notifications(activity)
351 {:error, _notification} = Notification.dismiss(user, notification.id)
355 describe "clear notification" do
356 test "it clears all notifications belonging to the user" do
358 other_user = insert(:user)
359 third_user = insert(:user)
362 CommonAPI.post(user, %{
363 "status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
366 {:ok, _notifs} = Notification.create_notifications(activity)
369 CommonAPI.post(user, %{
370 "status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
373 {:ok, _notifs} = Notification.create_notifications(activity)
374 Notification.clear(other_user)
376 assert Notification.for_user(other_user) == []
377 assert Notification.for_user(third_user) != []
381 describe "set_read_up_to()" do
382 test "it sets all notifications as read up to a specified notification ID" do
384 other_user = insert(:user)
387 CommonAPI.post(user, %{
388 "status" => "hey @#{other_user.nickname}!"
392 CommonAPI.post(user, %{
393 "status" => "hey again @#{other_user.nickname}!"
396 [n2, n1] = notifs = Notification.for_user(other_user)
397 assert length(notifs) == 2
402 CommonAPI.post(user, %{
403 "status" => "hey yet again @#{other_user.nickname}!"
406 Notification.set_read_up_to(other_user, n2.id)
408 [n3, n2, n1] = Notification.for_user(other_user)
410 assert n1.seen == true
411 assert n2.seen == true
412 assert n3.seen == false
416 describe "for_user_since/2" do
417 defp days_ago(days) do
419 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
420 -days * 60 * 60 * 24,
425 test "Returns recent notifications" do
426 user1 = insert(:user)
427 user2 = insert(:user)
429 Enum.each(0..10, fn i ->
431 CommonAPI.post(user1, %{
432 "status" => "hey ##{i} @#{user2.nickname}!"
436 {old, new} = Enum.split(Notification.for_user(user2), 5)
438 Enum.each(old, fn notification ->
440 |> cast(%{updated_at: days_ago(10)}, [:updated_at])
441 |> Pleroma.Repo.update!()
444 recent_notifications_ids =
446 |> Notification.for_user_since(
447 NaiveDateTime.add(NaiveDateTime.utc_now(), -5 * 86_400, :second)
451 Enum.each(old, fn %{id: id} ->
452 refute id in recent_notifications_ids
455 Enum.each(new, fn %{id: id} ->
456 assert id in recent_notifications_ids
461 describe "notification target determination / get_notified_from_activity/2" do
462 test "it sends notifications to addressed users in new messages" do
464 other_user = insert(:user)
467 CommonAPI.post(user, %{
468 "status" => "hey @#{other_user.nickname}!"
471 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
473 assert other_user in enabled_receivers
476 test "it sends notifications to mentioned users in new messages" do
478 other_user = insert(:user)
481 "@context" => "https://www.w3.org/ns/activitystreams",
483 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
484 "actor" => user.ap_id,
487 "content" => "message with a Mention tag, but no explicit tagging",
491 "href" => other_user.ap_id,
492 "name" => other_user.nickname
495 "attributedTo" => user.ap_id
499 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
501 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
503 assert other_user in enabled_receivers
506 test "it does not send notifications to users who are only cc in new messages" do
508 other_user = insert(:user)
511 "@context" => "https://www.w3.org/ns/activitystreams",
513 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
514 "cc" => [other_user.ap_id],
515 "actor" => user.ap_id,
518 "content" => "hi everyone",
519 "attributedTo" => user.ap_id
523 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
525 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
527 assert other_user not in enabled_receivers
530 test "it does not send notification to mentioned users in likes" do
532 other_user = insert(:user)
533 third_user = insert(:user)
535 {:ok, activity_one} =
536 CommonAPI.post(user, %{
537 "status" => "hey @#{other_user.nickname}!"
540 {:ok, activity_two, _} = CommonAPI.favorite(activity_one.id, third_user)
542 {enabled_receivers, _disabled_receivers} =
543 Notification.get_notified_from_activity(activity_two)
545 assert other_user not in enabled_receivers
548 test "it does not send notification to mentioned users in announces" do
550 other_user = insert(:user)
551 third_user = insert(:user)
553 {:ok, activity_one} =
554 CommonAPI.post(user, %{
555 "status" => "hey @#{other_user.nickname}!"
558 {:ok, activity_two, _} = CommonAPI.repeat(activity_one.id, third_user)
560 {enabled_receivers, _disabled_receivers} =
561 Notification.get_notified_from_activity(activity_two)
563 assert other_user not in enabled_receivers
566 test "it returns blocking recipient in disabled recipients list" do
568 other_user = insert(:user)
569 {:ok, _user_relationship} = User.block(other_user, user)
571 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
573 {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
575 assert [] == enabled_receivers
576 assert [other_user] == disabled_receivers
579 test "it returns notification-muting recipient in disabled recipients list" do
581 other_user = insert(:user)
582 {:ok, _user_relationships} = User.mute(other_user, user)
584 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
586 {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
588 assert [] == enabled_receivers
589 assert [other_user] == disabled_receivers
592 test "it returns thread-muting recipient in disabled recipients list" do
594 other_user = insert(:user)
596 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
598 {:ok, _} = CommonAPI.add_mute(other_user, activity)
600 {:ok, same_context_activity} =
601 CommonAPI.post(user, %{
602 "status" => "hey-hey-hey @#{other_user.nickname}!",
603 "in_reply_to_status_id" => activity.id
606 {enabled_receivers, disabled_receivers} =
607 Notification.get_notified_from_activity(same_context_activity)
609 assert [other_user] == disabled_receivers
610 refute other_user in enabled_receivers
614 describe "notification lifecycle" do
615 test "liking an activity results in 1 notification, then 0 if the activity is deleted" do
617 other_user = insert(:user)
619 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
621 assert Enum.empty?(Notification.for_user(user))
623 {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
625 assert length(Notification.for_user(user)) == 1
627 {:ok, _} = CommonAPI.delete(activity.id, user)
629 assert Enum.empty?(Notification.for_user(user))
632 test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
634 other_user = insert(:user)
636 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
638 assert Enum.empty?(Notification.for_user(user))
640 {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
642 assert length(Notification.for_user(user)) == 1
644 {:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
646 assert Enum.empty?(Notification.for_user(user))
649 test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
651 other_user = insert(:user)
653 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
655 assert Enum.empty?(Notification.for_user(user))
657 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
659 assert length(Notification.for_user(user)) == 1
661 {:ok, _} = CommonAPI.delete(activity.id, user)
663 assert Enum.empty?(Notification.for_user(user))
666 test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
668 other_user = insert(:user)
670 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
672 assert Enum.empty?(Notification.for_user(user))
674 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
676 assert length(Notification.for_user(user)) == 1
678 {:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
680 assert Enum.empty?(Notification.for_user(user))
683 test "liking an activity which is already deleted does not generate a notification" do
685 other_user = insert(:user)
687 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
689 assert Enum.empty?(Notification.for_user(user))
691 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
693 assert Enum.empty?(Notification.for_user(user))
695 {:error, _} = CommonAPI.favorite(activity.id, other_user)
697 assert Enum.empty?(Notification.for_user(user))
700 test "repeating an activity which is already deleted does not generate a notification" do
702 other_user = insert(:user)
704 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
706 assert Enum.empty?(Notification.for_user(user))
708 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
710 assert Enum.empty?(Notification.for_user(user))
712 {:error, _} = CommonAPI.repeat(activity.id, other_user)
714 assert Enum.empty?(Notification.for_user(user))
717 test "replying to a deleted post without tagging does not generate a notification" do
719 other_user = insert(:user)
721 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
722 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
724 {:ok, _reply_activity} =
725 CommonAPI.post(other_user, %{
726 "status" => "test reply",
727 "in_reply_to_status_id" => activity.id
730 assert Enum.empty?(Notification.for_user(user))
733 test "notifications are deleted if a local user is deleted" do
735 other_user = insert(:user)
738 CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}", "visibility" => "direct"})
740 refute Enum.empty?(Notification.for_user(other_user))
742 {:ok, job} = User.delete(user)
743 ObanHelpers.perform(job)
745 assert Enum.empty?(Notification.for_user(other_user))
748 test "notifications are deleted if a remote user is deleted" do
749 remote_user = insert(:user)
750 local_user = insert(:user)
753 "@context" => "https://www.w3.org/ns/activitystreams",
755 "actor" => remote_user.ap_id,
756 "id" => remote_user.ap_id <> "/activities/test",
757 "to" => [local_user.ap_id],
761 "content" => "Hello!",
765 "href" => local_user.ap_id,
766 "name" => "@#{local_user.nickname}"
769 "to" => [local_user.ap_id],
771 "attributedTo" => remote_user.ap_id
775 {:ok, _dm_activity} = Transmogrifier.handle_incoming(dm_message)
777 refute Enum.empty?(Notification.for_user(local_user))
779 delete_user_message = %{
780 "@context" => "https://www.w3.org/ns/activitystreams",
781 "id" => remote_user.ap_id <> "/activities/delete",
782 "actor" => remote_user.ap_id,
784 "object" => remote_user.ap_id
787 {:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
788 ObanHelpers.perform_all()
790 assert Enum.empty?(Notification.for_user(local_user))
793 test "move activity generates a notification" do
794 %{ap_id: old_ap_id} = old_user = insert(:user)
795 %{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
796 follower = insert(:user)
797 other_follower = insert(:user, %{allow_following_move: false})
799 User.follow(follower, old_user)
800 User.follow(other_follower, old_user)
802 Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
803 ObanHelpers.perform_all()
808 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
811 ] = Notification.for_user(follower)
816 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
819 ] = Notification.for_user(other_follower)
823 describe "for_user" do
824 test "it returns notifications for muted user without notifications" do
826 muted = insert(:user)
827 {:ok, _user_relationships} = User.mute(user, muted, false)
829 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
831 assert length(Notification.for_user(user)) == 1
834 test "it doesn't return notifications for muted user with notifications" do
836 muted = insert(:user)
837 {:ok, _user_relationships} = User.mute(user, muted)
839 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
841 assert Notification.for_user(user) == []
844 test "it doesn't return notifications for blocked user" do
846 blocked = insert(:user)
847 {:ok, _user_relationship} = User.block(user, blocked)
849 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
851 assert Notification.for_user(user) == []
854 test "it doesn't return notifications for blocked domain" do
856 blocked = insert(:user, ap_id: "http://some-domain.com")
857 {:ok, user} = User.block_domain(user, "some-domain.com")
859 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
861 assert Notification.for_user(user) == []
864 test "it doesn't return notifications for muted thread" do
866 another_user = insert(:user)
868 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
870 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
871 assert Notification.for_user(user) == []
874 test "it returns notifications from a muted user when with_muted is set" do
876 muted = insert(:user)
877 {:ok, _user_relationships} = User.mute(user, muted)
879 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
881 assert length(Notification.for_user(user, %{with_muted: true})) == 1
884 test "it doesn't return notifications from a blocked user when with_muted is set" do
886 blocked = insert(:user)
887 {:ok, _user_relationship} = User.block(user, blocked)
889 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
891 assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
894 test "it doesn't return notifications from a domain-blocked user when with_muted is set" do
896 blocked = insert(:user, ap_id: "http://some-domain.com")
897 {:ok, user} = User.block_domain(user, "some-domain.com")
899 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
901 assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
904 test "it returns notifications from muted threads when with_muted is set" do
906 another_user = insert(:user)
908 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
910 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
911 assert length(Notification.for_user(user, %{with_muted: true})) == 1