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
49 assert [%Pleroma.Marker{unread_count: 2}] =
50 Pleroma.Marker.get_markers(other_user, ["notifications"])
53 test "it creates a notification for subscribed users" do
55 subscriber = insert(:user)
57 User.subscribe(subscriber, user)
59 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
60 {:ok, [notification]} = Notification.create_notifications(status)
62 assert notification.user_id == subscriber.id
65 test "does not create a notification for subscribed users if status is a reply" do
67 other_user = insert(:user)
68 subscriber = insert(:user)
70 User.subscribe(subscriber, other_user)
72 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
74 {:ok, _reply_activity} =
75 CommonAPI.post(other_user, %{
76 "status" => "test reply",
77 "in_reply_to_status_id" => activity.id
80 user_notifications = Notification.for_user(user)
81 assert length(user_notifications) == 1
83 subscriber_notifications = Notification.for_user(subscriber)
84 assert Enum.empty?(subscriber_notifications)
88 describe "CommonApi.post/2 notification-related functionality" do
89 test_with_mock "creates but does NOT send notification to blocker user",
94 blocker = insert(:user)
95 {:ok, _user_relationship} = User.block(blocker, user)
97 {:ok, _activity} = CommonAPI.post(user, %{"status" => "hey @#{blocker.nickname}!"})
99 blocker_id = blocker.id
100 assert [%Notification{user_id: ^blocker_id}] = Repo.all(Notification)
101 refute called(Push.send(:_))
104 test_with_mock "creates but does NOT send notification to notification-muter user",
109 muter = insert(:user)
110 {:ok, _user_relationships} = User.mute(muter, user)
112 {:ok, _activity} = CommonAPI.post(user, %{"status" => "hey @#{muter.nickname}!"})
115 assert [%Notification{user_id: ^muter_id}] = Repo.all(Notification)
116 refute called(Push.send(:_))
119 test_with_mock "creates but does NOT send notification to thread-muter user",
124 thread_muter = insert(:user)
126 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{thread_muter.nickname}!"})
128 {:ok, _} = CommonAPI.add_mute(thread_muter, activity)
130 {:ok, _same_context_activity} =
131 CommonAPI.post(user, %{
132 "status" => "hey-hey-hey @#{thread_muter.nickname}!",
133 "in_reply_to_status_id" => activity.id
136 [pre_mute_notification, post_mute_notification] =
137 Repo.all(from(n in Notification, where: n.user_id == ^thread_muter.id, order_by: n.id))
139 pre_mute_notification_id = pre_mute_notification.id
140 post_mute_notification_id = post_mute_notification.id
145 %Notification{id: ^pre_mute_notification_id} -> true
154 %Notification{id: ^post_mute_notification_id} -> true
162 describe "create_notification" do
163 @tag needs_streamer: true
164 test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
166 task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
167 task_user_notification = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
168 Streamer.add_socket("user", %{transport_pid: task.pid, assigns: %{user: user}})
172 %{transport_pid: task_user_notification.pid, assigns: %{user: user}}
175 activity = insert(:note_activity)
177 notify = Notification.create_notification(activity, user)
178 assert notify.user_id == user.id
180 Task.await(task_user_notification)
183 test "it creates a notification for user if the user blocks the activity author" do
184 activity = insert(:note_activity)
185 author = User.get_cached_by_ap_id(activity.data["actor"])
187 {:ok, _user_relationship} = User.block(user, author)
189 assert Notification.create_notification(activity, user)
192 test "it creates a notification for the user if the user mutes the activity author" do
193 muter = insert(:user)
194 muted = insert(:user)
195 {:ok, _} = User.mute(muter, muted)
196 muter = Repo.get(User, muter.id)
197 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
199 assert Notification.create_notification(activity, muter)
202 test "notification created if user is muted without notifications" do
203 muter = insert(:user)
204 muted = insert(:user)
206 {:ok, _user_relationships} = User.mute(muter, muted, false)
208 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
210 assert Notification.create_notification(activity, muter)
213 test "it creates a notification for an activity from a muted thread" do
214 muter = insert(:user)
215 other_user = insert(:user)
216 {:ok, activity} = CommonAPI.post(muter, %{"status" => "hey"})
217 CommonAPI.add_mute(muter, activity)
220 CommonAPI.post(other_user, %{
221 "status" => "Hi @#{muter.nickname}",
222 "in_reply_to_status_id" => activity.id
225 assert Notification.create_notification(activity, muter)
228 test "it disables notifications from followers" do
229 follower = insert(:user)
232 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{followers: false})
234 User.follow(follower, followed)
235 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
236 refute Notification.create_notification(activity, followed)
239 test "it disables notifications from non-followers" do
240 follower = insert(:user)
244 notification_settings: %Pleroma.User.NotificationSetting{non_followers: false}
247 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
248 refute Notification.create_notification(activity, followed)
251 test "it disables notifications from people the user follows" do
253 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{follows: false})
255 followed = insert(:user)
256 User.follow(follower, followed)
257 follower = Repo.get(User, follower.id)
258 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
259 refute Notification.create_notification(activity, follower)
262 test "it disables notifications from people the user does not follow" do
264 insert(:user, notification_settings: %Pleroma.User.NotificationSetting{non_follows: false})
266 followed = insert(:user)
267 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
268 refute Notification.create_notification(activity, follower)
271 test "it doesn't create a notification for user if he is the activity author" do
272 activity = insert(:note_activity)
273 author = User.get_cached_by_ap_id(activity.data["actor"])
275 refute Notification.create_notification(activity, author)
278 test "it doesn't create a notification for follow-unfollow-follow chains" do
280 followed_user = insert(:user)
281 {:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
282 Notification.create_notification(activity, followed_user)
283 CommonAPI.unfollow(user, followed_user)
284 {:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
285 refute Notification.create_notification(activity_dupe, followed_user)
288 test "it doesn't create duplicate notifications for follow+subscribed users" do
290 subscriber = insert(:user)
292 {:ok, _, _, _} = CommonAPI.follow(subscriber, user)
293 User.subscribe(subscriber, user)
294 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
295 {:ok, [_notif]} = Notification.create_notifications(status)
298 test "it doesn't create subscription notifications if the recipient cannot see the status" do
300 subscriber = insert(:user)
302 User.subscribe(subscriber, user)
304 {:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
306 assert {:ok, []} == Notification.create_notifications(status)
310 describe "get notification" do
311 test "it gets a notification that belongs to the user" do
313 other_user = insert(:user)
315 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
317 {:ok, [notification]} = Notification.create_notifications(activity)
318 {:ok, notification} = Notification.get(other_user, notification.id)
320 assert notification.user_id == other_user.id
323 test "it returns error if the notification doesn't belong to the user" do
325 other_user = insert(:user)
327 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
329 {:ok, [notification]} = Notification.create_notifications(activity)
330 {:error, _notification} = Notification.get(user, notification.id)
334 describe "dismiss notification" do
335 test "it dismisses a notification that belongs to the user" do
337 other_user = insert(:user)
339 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
341 {:ok, [notification]} = Notification.create_notifications(activity)
342 {:ok, notification} = Notification.dismiss(other_user, notification.id)
344 assert notification.user_id == other_user.id
347 test "it returns error if the notification doesn't belong to the user" do
349 other_user = insert(:user)
351 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
353 {:ok, [notification]} = Notification.create_notifications(activity)
354 {:error, _notification} = Notification.dismiss(user, notification.id)
358 describe "clear notification" do
359 test "it clears all notifications belonging to the user" do
361 other_user = insert(:user)
362 third_user = insert(:user)
365 CommonAPI.post(user, %{
366 "status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
369 {:ok, _notifs} = Notification.create_notifications(activity)
372 CommonAPI.post(user, %{
373 "status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
376 {:ok, _notifs} = Notification.create_notifications(activity)
377 Notification.clear(other_user)
379 assert Notification.for_user(other_user) == []
380 assert Notification.for_user(third_user) != []
384 describe "set_read_up_to()" do
385 test "it sets all notifications as read up to a specified notification ID" do
387 other_user = insert(:user)
390 CommonAPI.post(user, %{
391 "status" => "hey @#{other_user.nickname}!"
395 CommonAPI.post(user, %{
396 "status" => "hey again @#{other_user.nickname}!"
399 [n2, n1] = notifs = Notification.for_user(other_user)
400 assert length(notifs) == 2
405 CommonAPI.post(user, %{
406 "status" => "hey yet again @#{other_user.nickname}!"
409 Notification.set_read_up_to(other_user, n2.id)
411 [n3, n2, n1] = Notification.for_user(other_user)
413 assert n1.seen == true
414 assert n2.seen == true
415 assert n3.seen == false
417 assert %Pleroma.Marker{} =
421 user_id: other_user.id,
422 timeline: "notifications"
425 assert m.last_read_id == to_string(n2.id)
429 describe "for_user_since/2" do
430 defp days_ago(days) do
432 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
433 -days * 60 * 60 * 24,
438 test "Returns recent notifications" do
439 user1 = insert(:user)
440 user2 = insert(:user)
442 Enum.each(0..10, fn i ->
444 CommonAPI.post(user1, %{
445 "status" => "hey ##{i} @#{user2.nickname}!"
449 {old, new} = Enum.split(Notification.for_user(user2), 5)
451 Enum.each(old, fn notification ->
453 |> cast(%{updated_at: days_ago(10)}, [:updated_at])
454 |> Pleroma.Repo.update!()
457 recent_notifications_ids =
459 |> Notification.for_user_since(
460 NaiveDateTime.add(NaiveDateTime.utc_now(), -5 * 86_400, :second)
464 Enum.each(old, fn %{id: id} ->
465 refute id in recent_notifications_ids
468 Enum.each(new, fn %{id: id} ->
469 assert id in recent_notifications_ids
474 describe "notification target determination / get_notified_from_activity/2" do
475 test "it sends notifications to addressed users in new messages" do
477 other_user = insert(:user)
480 CommonAPI.post(user, %{
481 "status" => "hey @#{other_user.nickname}!"
484 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
486 assert other_user in enabled_receivers
489 test "it sends notifications to mentioned users in new messages" do
491 other_user = insert(:user)
494 "@context" => "https://www.w3.org/ns/activitystreams",
496 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
497 "actor" => user.ap_id,
500 "content" => "message with a Mention tag, but no explicit tagging",
504 "href" => other_user.ap_id,
505 "name" => other_user.nickname
508 "attributedTo" => user.ap_id
512 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
514 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
516 assert other_user in enabled_receivers
519 test "it does not send notifications to users who are only cc in new messages" do
521 other_user = insert(:user)
524 "@context" => "https://www.w3.org/ns/activitystreams",
526 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
527 "cc" => [other_user.ap_id],
528 "actor" => user.ap_id,
531 "content" => "hi everyone",
532 "attributedTo" => user.ap_id
536 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
538 {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(activity)
540 assert other_user not in enabled_receivers
543 test "it does not send notification to mentioned users in likes" do
545 other_user = insert(:user)
546 third_user = insert(:user)
548 {:ok, activity_one} =
549 CommonAPI.post(user, %{
550 "status" => "hey @#{other_user.nickname}!"
553 {:ok, activity_two, _} = CommonAPI.favorite(activity_one.id, third_user)
555 {enabled_receivers, _disabled_receivers} =
556 Notification.get_notified_from_activity(activity_two)
558 assert other_user not in enabled_receivers
561 test "it does not send notification to mentioned users in announces" do
563 other_user = insert(:user)
564 third_user = insert(:user)
566 {:ok, activity_one} =
567 CommonAPI.post(user, %{
568 "status" => "hey @#{other_user.nickname}!"
571 {:ok, activity_two, _} = CommonAPI.repeat(activity_one.id, third_user)
573 {enabled_receivers, _disabled_receivers} =
574 Notification.get_notified_from_activity(activity_two)
576 assert other_user not in enabled_receivers
579 test "it returns blocking recipient in disabled recipients list" do
581 other_user = insert(:user)
582 {:ok, _user_relationship} = User.block(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 notification-muting recipient in disabled recipients list" do
594 other_user = insert(:user)
595 {:ok, _user_relationships} = User.mute(other_user, user)
597 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
599 {enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
601 assert [] == enabled_receivers
602 assert [other_user] == disabled_receivers
605 test "it returns thread-muting recipient in disabled recipients list" do
607 other_user = insert(:user)
609 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
611 {:ok, _} = CommonAPI.add_mute(other_user, activity)
613 {:ok, same_context_activity} =
614 CommonAPI.post(user, %{
615 "status" => "hey-hey-hey @#{other_user.nickname}!",
616 "in_reply_to_status_id" => activity.id
619 {enabled_receivers, disabled_receivers} =
620 Notification.get_notified_from_activity(same_context_activity)
622 assert [other_user] == disabled_receivers
623 refute other_user in enabled_receivers
627 describe "notification lifecycle" do
628 test "liking an activity results in 1 notification, then 0 if the activity is deleted" do
630 other_user = insert(:user)
632 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
634 assert Enum.empty?(Notification.for_user(user))
636 {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
638 assert length(Notification.for_user(user)) == 1
640 {:ok, _} = CommonAPI.delete(activity.id, user)
642 assert Enum.empty?(Notification.for_user(user))
645 test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
647 other_user = insert(:user)
649 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
651 assert Enum.empty?(Notification.for_user(user))
653 {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
655 assert length(Notification.for_user(user)) == 1
657 {:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
659 assert Enum.empty?(Notification.for_user(user))
662 test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
664 other_user = insert(:user)
666 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
668 assert Enum.empty?(Notification.for_user(user))
670 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
672 assert length(Notification.for_user(user)) == 1
674 {:ok, _} = CommonAPI.delete(activity.id, user)
676 assert Enum.empty?(Notification.for_user(user))
679 test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
681 other_user = insert(:user)
683 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
685 assert Enum.empty?(Notification.for_user(user))
687 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
689 assert length(Notification.for_user(user)) == 1
691 {:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
693 assert Enum.empty?(Notification.for_user(user))
696 test "liking an activity which is already deleted does not generate a notification" do
698 other_user = insert(:user)
700 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
702 assert Enum.empty?(Notification.for_user(user))
704 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
706 assert Enum.empty?(Notification.for_user(user))
708 {:error, _} = CommonAPI.favorite(activity.id, other_user)
710 assert Enum.empty?(Notification.for_user(user))
713 test "repeating an activity which is already deleted does not generate a notification" do
715 other_user = insert(:user)
717 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
719 assert Enum.empty?(Notification.for_user(user))
721 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
723 assert Enum.empty?(Notification.for_user(user))
725 {:error, _} = CommonAPI.repeat(activity.id, other_user)
727 assert Enum.empty?(Notification.for_user(user))
730 test "replying to a deleted post without tagging does not generate a notification" do
732 other_user = insert(:user)
734 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
735 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
737 {:ok, _reply_activity} =
738 CommonAPI.post(other_user, %{
739 "status" => "test reply",
740 "in_reply_to_status_id" => activity.id
743 assert Enum.empty?(Notification.for_user(user))
746 test "notifications are deleted if a local user is deleted" do
748 other_user = insert(:user)
751 CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}", "visibility" => "direct"})
753 refute Enum.empty?(Notification.for_user(other_user))
755 {:ok, job} = User.delete(user)
756 ObanHelpers.perform(job)
758 assert Enum.empty?(Notification.for_user(other_user))
761 test "notifications are deleted if a remote user is deleted" do
762 remote_user = insert(:user)
763 local_user = insert(:user)
766 "@context" => "https://www.w3.org/ns/activitystreams",
768 "actor" => remote_user.ap_id,
769 "id" => remote_user.ap_id <> "/activities/test",
770 "to" => [local_user.ap_id],
774 "content" => "Hello!",
778 "href" => local_user.ap_id,
779 "name" => "@#{local_user.nickname}"
782 "to" => [local_user.ap_id],
784 "attributedTo" => remote_user.ap_id
788 {:ok, _dm_activity} = Transmogrifier.handle_incoming(dm_message)
790 refute Enum.empty?(Notification.for_user(local_user))
792 delete_user_message = %{
793 "@context" => "https://www.w3.org/ns/activitystreams",
794 "id" => remote_user.ap_id <> "/activities/delete",
795 "actor" => remote_user.ap_id,
797 "object" => remote_user.ap_id
800 remote_user_url = remote_user.ap_id
803 %{method: :get, url: ^remote_user_url} ->
804 %Tesla.Env{status: 404, body: ""}
807 {:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
808 ObanHelpers.perform_all()
810 assert Enum.empty?(Notification.for_user(local_user))
813 @tag capture_log: true
814 test "move activity generates a notification" do
815 %{ap_id: old_ap_id} = old_user = insert(:user)
816 %{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
817 follower = insert(:user)
818 other_follower = insert(:user, %{allow_following_move: false})
820 User.follow(follower, old_user)
821 User.follow(other_follower, old_user)
823 old_user_url = old_user.ap_id
826 File.read!("test/fixtures/users_mock/localhost.json")
827 |> String.replace("{{nickname}}", old_user.nickname)
831 %{method: :get, url: ^old_user_url} ->
832 %Tesla.Env{status: 200, body: body}
835 Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
836 ObanHelpers.perform_all()
841 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
844 ] = Notification.for_user(follower)
849 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
852 ] = Notification.for_user(other_follower)
856 describe "for_user" do
857 test "it returns notifications for muted user without notifications" do
859 muted = insert(:user)
860 {:ok, _user_relationships} = User.mute(user, muted, false)
862 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
864 assert length(Notification.for_user(user)) == 1
867 test "it doesn't return notifications for muted user with notifications" do
869 muted = insert(:user)
870 {:ok, _user_relationships} = User.mute(user, muted)
872 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
874 assert Notification.for_user(user) == []
877 test "it doesn't return notifications for blocked user" do
879 blocked = insert(:user)
880 {:ok, _user_relationship} = User.block(user, blocked)
882 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
884 assert Notification.for_user(user) == []
887 test "it doesn't return notifications for blocked domain" do
889 blocked = insert(:user, ap_id: "http://some-domain.com")
890 {:ok, user} = User.block_domain(user, "some-domain.com")
892 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
894 assert Notification.for_user(user) == []
897 test "it doesn't return notifications for muted thread" do
899 another_user = insert(:user)
901 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
903 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
904 assert Notification.for_user(user) == []
907 test "it returns notifications from a muted user when with_muted is set" do
909 muted = insert(:user)
910 {:ok, _user_relationships} = User.mute(user, muted)
912 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
914 assert length(Notification.for_user(user, %{with_muted: true})) == 1
917 test "it doesn't return notifications from a blocked user when with_muted is set" do
919 blocked = insert(:user)
920 {:ok, _user_relationship} = User.block(user, blocked)
922 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
924 assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
927 test "it doesn't return notifications from a domain-blocked user when with_muted is set" do
929 blocked = insert(:user, ap_id: "http://some-domain.com")
930 {:ok, user} = User.block_domain(user, "some-domain.com")
932 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
934 assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
937 test "it returns notifications from muted threads when with_muted is set" do
939 another_user = insert(:user)
941 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
943 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
944 assert length(Notification.for_user(user, %{with_muted: true})) == 1