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