8db3495262a0e44e0c3cf2deef6f462d8130d650
[akkoma] / test / notification_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.NotificationTest do
6 use Pleroma.DataCase
7
8 import Pleroma.Factory
9
10 alias Pleroma.Notification
11 alias Pleroma.Tests.ObanHelpers
12 alias Pleroma.User
13 alias Pleroma.Web.ActivityPub.Transmogrifier
14 alias Pleroma.Web.CommonAPI
15 alias Pleroma.Web.Streamer
16
17 describe "create_notifications" do
18 test "notifies someone when they are directly addressed" do
19 user = insert(:user)
20 other_user = insert(:user)
21 third_user = insert(:user)
22
23 {:ok, activity} =
24 CommonAPI.post(user, %{
25 "status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
26 })
27
28 {:ok, [notification, other_notification]} = Notification.create_notifications(activity)
29
30 notified_ids = Enum.sort([notification.user_id, other_notification.user_id])
31 assert notified_ids == [other_user.id, third_user.id]
32 assert notification.activity_id == activity.id
33 assert other_notification.activity_id == activity.id
34
35 assert [%Pleroma.Marker{unread_count: 2}] =
36 Pleroma.Marker.get_markers(other_user, ["notifications"])
37 end
38
39 test "it creates a notification for subscribed users" do
40 user = insert(:user)
41 subscriber = insert(:user)
42
43 User.subscribe(subscriber, user)
44
45 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
46 {:ok, [notification]} = Notification.create_notifications(status)
47
48 assert notification.user_id == subscriber.id
49 end
50
51 test "does not create a notification for subscribed users if status is a reply" do
52 user = insert(:user)
53 other_user = insert(:user)
54 subscriber = insert(:user)
55
56 User.subscribe(subscriber, other_user)
57
58 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
59
60 {:ok, _reply_activity} =
61 CommonAPI.post(other_user, %{
62 "status" => "test reply",
63 "in_reply_to_status_id" => activity.id
64 })
65
66 user_notifications = Notification.for_user(user)
67 assert length(user_notifications) == 1
68
69 subscriber_notifications = Notification.for_user(subscriber)
70 assert Enum.empty?(subscriber_notifications)
71 end
72 end
73
74 describe "create_notification" do
75 @tag needs_streamer: true
76 test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
77 user = insert(:user)
78 task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
79 task_user_notification = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
80 Streamer.add_socket("user", %{transport_pid: task.pid, assigns: %{user: user}})
81
82 Streamer.add_socket(
83 "user:notification",
84 %{transport_pid: task_user_notification.pid, assigns: %{user: user}}
85 )
86
87 activity = insert(:note_activity)
88
89 notify = Notification.create_notification(activity, user)
90 assert notify.user_id == user.id
91 Task.await(task)
92 Task.await(task_user_notification)
93 end
94
95 test "it creates a notification for user if the user blocks the activity author" do
96 activity = insert(:note_activity)
97 author = User.get_cached_by_ap_id(activity.data["actor"])
98 user = insert(:user)
99 {:ok, user} = User.block(user, author)
100
101 assert Notification.create_notification(activity, user)
102 end
103
104 test "it creates a notificatin for the user if the user mutes the activity author" do
105 muter = insert(:user)
106 muted = insert(:user)
107 {:ok, _} = User.mute(muter, muted)
108 muter = Repo.get(User, muter.id)
109 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
110
111 assert Notification.create_notification(activity, muter)
112 end
113
114 test "notification created if user is muted without notifications" do
115 muter = insert(:user)
116 muted = insert(:user)
117
118 {:ok, muter} = User.mute(muter, muted, false)
119
120 {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
121
122 assert Notification.create_notification(activity, muter)
123 end
124
125 test "it creates a notification for an activity from a muted thread" do
126 muter = insert(:user)
127 other_user = insert(:user)
128 {:ok, activity} = CommonAPI.post(muter, %{"status" => "hey"})
129 CommonAPI.add_mute(muter, activity)
130
131 {:ok, activity} =
132 CommonAPI.post(other_user, %{
133 "status" => "Hi @#{muter.nickname}",
134 "in_reply_to_status_id" => activity.id
135 })
136
137 assert Notification.create_notification(activity, muter)
138 end
139
140 test "it disables notifications from followers" do
141 follower = insert(:user)
142 followed = insert(:user, notification_settings: %{"followers" => false})
143 User.follow(follower, followed)
144 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
145 refute Notification.create_notification(activity, followed)
146 end
147
148 test "it disables notifications from non-followers" do
149 follower = insert(:user)
150 followed = insert(:user, notification_settings: %{"non_followers" => false})
151 {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
152 refute Notification.create_notification(activity, followed)
153 end
154
155 test "it disables notifications from people the user follows" do
156 follower = insert(:user, notification_settings: %{"follows" => false})
157 followed = insert(:user)
158 User.follow(follower, followed)
159 follower = Repo.get(User, follower.id)
160 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
161 refute Notification.create_notification(activity, follower)
162 end
163
164 test "it disables notifications from people the user does not follow" do
165 follower = insert(:user, notification_settings: %{"non_follows" => false})
166 followed = insert(:user)
167 {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
168 refute Notification.create_notification(activity, follower)
169 end
170
171 test "it doesn't create a notification for user if he is the activity author" do
172 activity = insert(:note_activity)
173 author = User.get_cached_by_ap_id(activity.data["actor"])
174
175 refute Notification.create_notification(activity, author)
176 end
177
178 test "it doesn't create a notification for follow-unfollow-follow chains" do
179 user = insert(:user)
180 followed_user = insert(:user)
181 {:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
182 Notification.create_notification(activity, followed_user)
183 CommonAPI.unfollow(user, followed_user)
184 {:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
185 refute Notification.create_notification(activity_dupe, followed_user)
186 end
187
188 test "it doesn't create duplicate notifications for follow+subscribed users" do
189 user = insert(:user)
190 subscriber = insert(:user)
191
192 {:ok, _, _, _} = CommonAPI.follow(subscriber, user)
193 User.subscribe(subscriber, user)
194 {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
195 {:ok, [_notif]} = Notification.create_notifications(status)
196 end
197
198 test "it doesn't create subscription notifications if the recipient cannot see the status" do
199 user = insert(:user)
200 subscriber = insert(:user)
201
202 User.subscribe(subscriber, user)
203
204 {:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
205
206 assert {:ok, []} == Notification.create_notifications(status)
207 end
208 end
209
210 describe "get notification" do
211 test "it gets a notification that belongs to the user" do
212 user = insert(:user)
213 other_user = insert(:user)
214
215 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
216
217 {:ok, [notification]} = Notification.create_notifications(activity)
218 {:ok, notification} = Notification.get(other_user, notification.id)
219
220 assert notification.user_id == other_user.id
221 end
222
223 test "it returns error if the notification doesn't belong to the user" do
224 user = insert(:user)
225 other_user = insert(:user)
226
227 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
228
229 {:ok, [notification]} = Notification.create_notifications(activity)
230 {:error, _notification} = Notification.get(user, notification.id)
231 end
232 end
233
234 describe "dismiss notification" do
235 test "it dismisses a notification that belongs to the user" do
236 user = insert(:user)
237 other_user = insert(:user)
238
239 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
240
241 {:ok, [notification]} = Notification.create_notifications(activity)
242 {:ok, notification} = Notification.dismiss(other_user, notification.id)
243
244 assert notification.user_id == other_user.id
245 end
246
247 test "it returns error if the notification doesn't belong to the user" do
248 user = insert(:user)
249 other_user = insert(:user)
250
251 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
252
253 {:ok, [notification]} = Notification.create_notifications(activity)
254 {:error, _notification} = Notification.dismiss(user, notification.id)
255 end
256 end
257
258 describe "clear notification" do
259 test "it clears all notifications belonging to the user" do
260 user = insert(:user)
261 other_user = insert(:user)
262 third_user = insert(:user)
263
264 {:ok, activity} =
265 CommonAPI.post(user, %{
266 "status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
267 })
268
269 {:ok, _notifs} = Notification.create_notifications(activity)
270
271 {:ok, activity} =
272 CommonAPI.post(user, %{
273 "status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
274 })
275
276 {:ok, _notifs} = Notification.create_notifications(activity)
277 Notification.clear(other_user)
278
279 assert Notification.for_user(other_user) == []
280 assert Notification.for_user(third_user) != []
281 end
282 end
283
284 describe "set_read_up_to()" do
285 test "it sets all notifications as read up to a specified notification ID" do
286 user = insert(:user)
287 other_user = insert(:user)
288
289 {:ok, _activity} =
290 CommonAPI.post(user, %{
291 "status" => "hey @#{other_user.nickname}!"
292 })
293
294 {:ok, _activity} =
295 CommonAPI.post(user, %{
296 "status" => "hey again @#{other_user.nickname}!"
297 })
298
299 [n2, n1] = notifs = Notification.for_user(other_user)
300 assert length(notifs) == 2
301
302 assert n2.id > n1.id
303
304 {:ok, _activity} =
305 CommonAPI.post(user, %{
306 "status" => "hey yet again @#{other_user.nickname}!"
307 })
308
309 Notification.set_read_up_to(other_user, n2.id)
310
311 [n3, n2, n1] = Notification.for_user(other_user)
312
313 assert n1.seen == true
314 assert n2.seen == true
315 assert n3.seen == false
316
317 assert %Pleroma.Marker{unread_count: 1} =
318 Pleroma.Repo.get_by(
319 Pleroma.Marker,
320 user_id: other_user.id,
321 timeline: "notifications"
322 )
323 end
324 end
325
326 describe "for_user_since/2" do
327 defp days_ago(days) do
328 NaiveDateTime.add(
329 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
330 -days * 60 * 60 * 24,
331 :second
332 )
333 end
334
335 test "Returns recent notifications" do
336 user1 = insert(:user)
337 user2 = insert(:user)
338
339 Enum.each(0..10, fn i ->
340 {:ok, _activity} =
341 CommonAPI.post(user1, %{
342 "status" => "hey ##{i} @#{user2.nickname}!"
343 })
344 end)
345
346 {old, new} = Enum.split(Notification.for_user(user2), 5)
347
348 Enum.each(old, fn notification ->
349 notification
350 |> cast(%{updated_at: days_ago(10)}, [:updated_at])
351 |> Pleroma.Repo.update!()
352 end)
353
354 recent_notifications_ids =
355 user2
356 |> Notification.for_user_since(
357 NaiveDateTime.add(NaiveDateTime.utc_now(), -5 * 86_400, :second)
358 )
359 |> Enum.map(& &1.id)
360
361 Enum.each(old, fn %{id: id} ->
362 refute id in recent_notifications_ids
363 end)
364
365 Enum.each(new, fn %{id: id} ->
366 assert id in recent_notifications_ids
367 end)
368 end
369 end
370
371 describe "notification target determination" do
372 test "it sends notifications to addressed users in new messages" do
373 user = insert(:user)
374 other_user = insert(:user)
375
376 {:ok, activity} =
377 CommonAPI.post(user, %{
378 "status" => "hey @#{other_user.nickname}!"
379 })
380
381 assert other_user in Notification.get_notified_from_activity(activity)
382 end
383
384 test "it sends notifications to mentioned users in new messages" do
385 user = insert(:user)
386 other_user = insert(:user)
387
388 create_activity = %{
389 "@context" => "https://www.w3.org/ns/activitystreams",
390 "type" => "Create",
391 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
392 "actor" => user.ap_id,
393 "object" => %{
394 "type" => "Note",
395 "content" => "message with a Mention tag, but no explicit tagging",
396 "tag" => [
397 %{
398 "type" => "Mention",
399 "href" => other_user.ap_id,
400 "name" => other_user.nickname
401 }
402 ],
403 "attributedTo" => user.ap_id
404 }
405 }
406
407 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
408
409 assert other_user in Notification.get_notified_from_activity(activity)
410 end
411
412 test "it does not send notifications to users who are only cc in new messages" do
413 user = insert(:user)
414 other_user = insert(:user)
415
416 create_activity = %{
417 "@context" => "https://www.w3.org/ns/activitystreams",
418 "type" => "Create",
419 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
420 "cc" => [other_user.ap_id],
421 "actor" => user.ap_id,
422 "object" => %{
423 "type" => "Note",
424 "content" => "hi everyone",
425 "attributedTo" => user.ap_id
426 }
427 }
428
429 {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
430
431 assert other_user not in Notification.get_notified_from_activity(activity)
432 end
433
434 test "it does not send notification to mentioned users in likes" do
435 user = insert(:user)
436 other_user = insert(:user)
437 third_user = insert(:user)
438
439 {:ok, activity_one} =
440 CommonAPI.post(user, %{
441 "status" => "hey @#{other_user.nickname}!"
442 })
443
444 {:ok, activity_two, _} = CommonAPI.favorite(activity_one.id, third_user)
445
446 assert other_user not in Notification.get_notified_from_activity(activity_two)
447 end
448
449 test "it does not send notification to mentioned users in announces" do
450 user = insert(:user)
451 other_user = insert(:user)
452 third_user = insert(:user)
453
454 {:ok, activity_one} =
455 CommonAPI.post(user, %{
456 "status" => "hey @#{other_user.nickname}!"
457 })
458
459 {:ok, activity_two, _} = CommonAPI.repeat(activity_one.id, third_user)
460
461 assert other_user not in Notification.get_notified_from_activity(activity_two)
462 end
463 end
464
465 describe "notification lifecycle" do
466 test "liking an activity results in 1 notification, then 0 if the activity is deleted" do
467 user = insert(:user)
468 other_user = insert(:user)
469
470 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
471
472 assert Enum.empty?(Notification.for_user(user))
473
474 {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
475
476 assert length(Notification.for_user(user)) == 1
477
478 {:ok, _} = CommonAPI.delete(activity.id, user)
479
480 assert Enum.empty?(Notification.for_user(user))
481 end
482
483 test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
484 user = insert(:user)
485 other_user = insert(:user)
486
487 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
488
489 assert Enum.empty?(Notification.for_user(user))
490
491 {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
492
493 assert length(Notification.for_user(user)) == 1
494
495 {:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
496
497 assert Enum.empty?(Notification.for_user(user))
498 end
499
500 test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
501 user = insert(:user)
502 other_user = insert(:user)
503
504 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
505
506 assert Enum.empty?(Notification.for_user(user))
507
508 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
509
510 assert length(Notification.for_user(user)) == 1
511
512 {:ok, _} = CommonAPI.delete(activity.id, user)
513
514 assert Enum.empty?(Notification.for_user(user))
515 end
516
517 test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
518 user = insert(:user)
519 other_user = insert(:user)
520
521 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
522
523 assert Enum.empty?(Notification.for_user(user))
524
525 {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
526
527 assert length(Notification.for_user(user)) == 1
528
529 {:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
530
531 assert Enum.empty?(Notification.for_user(user))
532 end
533
534 test "liking an activity which is already deleted does not generate a notification" do
535 user = insert(:user)
536 other_user = insert(:user)
537
538 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
539
540 assert Enum.empty?(Notification.for_user(user))
541
542 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
543
544 assert Enum.empty?(Notification.for_user(user))
545
546 {:error, _} = CommonAPI.favorite(activity.id, other_user)
547
548 assert Enum.empty?(Notification.for_user(user))
549 end
550
551 test "repeating an activity which is already deleted does not generate a notification" do
552 user = insert(:user)
553 other_user = insert(:user)
554
555 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
556
557 assert Enum.empty?(Notification.for_user(user))
558
559 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
560
561 assert Enum.empty?(Notification.for_user(user))
562
563 {:error, _} = CommonAPI.repeat(activity.id, other_user)
564
565 assert Enum.empty?(Notification.for_user(user))
566 end
567
568 test "replying to a deleted post without tagging does not generate a notification" do
569 user = insert(:user)
570 other_user = insert(:user)
571
572 {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
573 {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
574
575 {:ok, _reply_activity} =
576 CommonAPI.post(other_user, %{
577 "status" => "test reply",
578 "in_reply_to_status_id" => activity.id
579 })
580
581 assert Enum.empty?(Notification.for_user(user))
582 end
583
584 test "notifications are deleted if a local user is deleted" do
585 user = insert(:user)
586 other_user = insert(:user)
587
588 {:ok, _activity} =
589 CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}", "visibility" => "direct"})
590
591 refute Enum.empty?(Notification.for_user(other_user))
592
593 {:ok, job} = User.delete(user)
594 ObanHelpers.perform(job)
595
596 assert Enum.empty?(Notification.for_user(other_user))
597 end
598
599 test "notifications are deleted if a remote user is deleted" do
600 remote_user = insert(:user)
601 local_user = insert(:user)
602
603 dm_message = %{
604 "@context" => "https://www.w3.org/ns/activitystreams",
605 "type" => "Create",
606 "actor" => remote_user.ap_id,
607 "id" => remote_user.ap_id <> "/activities/test",
608 "to" => [local_user.ap_id],
609 "cc" => [],
610 "object" => %{
611 "type" => "Note",
612 "content" => "Hello!",
613 "tag" => [
614 %{
615 "type" => "Mention",
616 "href" => local_user.ap_id,
617 "name" => "@#{local_user.nickname}"
618 }
619 ],
620 "to" => [local_user.ap_id],
621 "cc" => [],
622 "attributedTo" => remote_user.ap_id
623 }
624 }
625
626 {:ok, _dm_activity} = Transmogrifier.handle_incoming(dm_message)
627
628 refute Enum.empty?(Notification.for_user(local_user))
629
630 delete_user_message = %{
631 "@context" => "https://www.w3.org/ns/activitystreams",
632 "id" => remote_user.ap_id <> "/activities/delete",
633 "actor" => remote_user.ap_id,
634 "type" => "Delete",
635 "object" => remote_user.ap_id
636 }
637
638 {:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
639 ObanHelpers.perform_all()
640
641 assert Enum.empty?(Notification.for_user(local_user))
642 end
643
644 test "move activity generates a notification" do
645 %{ap_id: old_ap_id} = old_user = insert(:user)
646 %{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id])
647 follower = insert(:user)
648 other_follower = insert(:user, %{allow_following_move: false})
649
650 User.follow(follower, old_user)
651 User.follow(other_follower, old_user)
652
653 Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
654 ObanHelpers.perform_all()
655
656 assert [
657 %{
658 activity: %{
659 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
660 }
661 }
662 ] = Notification.for_user(follower)
663
664 assert [
665 %{
666 activity: %{
667 data: %{"type" => "Move", "actor" => ^old_ap_id, "target" => ^new_ap_id}
668 }
669 }
670 ] = Notification.for_user(other_follower)
671 end
672 end
673
674 describe "for_user" do
675 test "it returns notifications for muted user without notifications" do
676 user = insert(:user)
677 muted = insert(:user)
678 {:ok, user} = User.mute(user, muted, false)
679
680 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
681
682 assert length(Notification.for_user(user)) == 1
683 end
684
685 test "it doesn't return notifications for muted user with notifications" do
686 user = insert(:user)
687 muted = insert(:user)
688 {:ok, user} = User.mute(user, muted)
689
690 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
691
692 assert Notification.for_user(user) == []
693 end
694
695 test "it doesn't return notifications for blocked user" do
696 user = insert(:user)
697 blocked = insert(:user)
698 {:ok, user} = User.block(user, blocked)
699
700 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
701
702 assert Notification.for_user(user) == []
703 end
704
705 test "it doesn't return notificatitons for blocked domain" do
706 user = insert(:user)
707 blocked = insert(:user, ap_id: "http://some-domain.com")
708 {:ok, user} = User.block_domain(user, "some-domain.com")
709
710 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
711
712 assert Notification.for_user(user) == []
713 end
714
715 test "it doesn't return notifications for muted thread" do
716 user = insert(:user)
717 another_user = insert(:user)
718
719 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
720
721 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
722 assert Notification.for_user(user) == []
723 end
724
725 test "it returns notifications from a muted user when with_muted is set" do
726 user = insert(:user)
727 muted = insert(:user)
728 {:ok, user} = User.mute(user, muted)
729
730 {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
731
732 assert length(Notification.for_user(user, %{with_muted: true})) == 1
733 end
734
735 test "it doesn't return notifications from a blocked user when with_muted is set" do
736 user = insert(:user)
737 blocked = insert(:user)
738 {:ok, user} = User.block(user, blocked)
739
740 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
741
742 assert length(Notification.for_user(user, %{with_muted: true})) == 0
743 end
744
745 test "it doesn't return notifications from a domain-blocked user when with_muted is set" do
746 user = insert(:user)
747 blocked = insert(:user, ap_id: "http://some-domain.com")
748 {:ok, user} = User.block_domain(user, "some-domain.com")
749
750 {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
751
752 assert length(Notification.for_user(user, %{with_muted: true})) == 0
753 end
754
755 test "it returns notifications from muted threads when with_muted is set" do
756 user = insert(:user)
757 another_user = insert(:user)
758
759 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
760
761 {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
762 assert length(Notification.for_user(user, %{with_muted: true})) == 1
763 end
764 end
765 end