Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

727 line
23KB

  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. defmodule Pleroma.NotificationTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Notification
  8. alias Pleroma.Tests.ObanHelpers
  9. alias Pleroma.User
  10. alias Pleroma.Web.ActivityPub.Transmogrifier
  11. alias Pleroma.Web.CommonAPI
  12. alias Pleroma.Web.Streamer
  13. describe "create_notifications" do
  14. test "notifies someone when they are directly addressed" do
  15. user = insert(:user)
  16. other_user = insert(:user)
  17. third_user = insert(:user)
  18. {:ok, activity} =
  19. CommonAPI.post(user, %{
  20. "status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
  21. })
  22. {:ok, [notification, other_notification]} = Notification.create_notifications(activity)
  23. notified_ids = Enum.sort([notification.user_id, other_notification.user_id])
  24. assert notified_ids == [other_user.id, third_user.id]
  25. assert notification.activity_id == activity.id
  26. assert other_notification.activity_id == activity.id
  27. end
  28. test "it creates a notification for subscribed users" do
  29. user = insert(:user)
  30. subscriber = insert(:user)
  31. User.subscribe(subscriber, user)
  32. {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
  33. {:ok, [notification]} = Notification.create_notifications(status)
  34. assert notification.user_id == subscriber.id
  35. end
  36. test "does not create a notification for subscribed users if status is a reply" do
  37. user = insert(:user)
  38. other_user = insert(:user)
  39. subscriber = insert(:user)
  40. User.subscribe(subscriber, other_user)
  41. {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
  42. {:ok, _reply_activity} =
  43. CommonAPI.post(other_user, %{
  44. "status" => "test reply",
  45. "in_reply_to_status_id" => activity.id
  46. })
  47. user_notifications = Notification.for_user(user)
  48. assert length(user_notifications) == 1
  49. subscriber_notifications = Notification.for_user(subscriber)
  50. assert Enum.empty?(subscriber_notifications)
  51. end
  52. end
  53. describe "create_notification" do
  54. @tag needs_streamer: true
  55. test "it creates a notification for user and send to the 'user' and the 'user:notification' stream" do
  56. user = insert(:user)
  57. task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
  58. task_user_notification = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
  59. Streamer.add_socket("user", %{transport_pid: task.pid, assigns: %{user: user}})
  60. Streamer.add_socket(
  61. "user:notification",
  62. %{transport_pid: task_user_notification.pid, assigns: %{user: user}}
  63. )
  64. activity = insert(:note_activity)
  65. notify = Notification.create_notification(activity, user)
  66. assert notify.user_id == user.id
  67. Task.await(task)
  68. Task.await(task_user_notification)
  69. end
  70. test "it creates a notification for user if the user blocks the activity author" do
  71. activity = insert(:note_activity)
  72. author = User.get_cached_by_ap_id(activity.data["actor"])
  73. user = insert(:user)
  74. {:ok, user} = User.block(user, author)
  75. assert Notification.create_notification(activity, user)
  76. end
  77. test "it creates a notificatin for the user if the user mutes the activity author" do
  78. muter = insert(:user)
  79. muted = insert(:user)
  80. {:ok, _} = User.mute(muter, muted)
  81. muter = Repo.get(User, muter.id)
  82. {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
  83. assert Notification.create_notification(activity, muter)
  84. end
  85. test "notification created if user is muted without notifications" do
  86. muter = insert(:user)
  87. muted = insert(:user)
  88. {:ok, muter} = User.mute(muter, muted, false)
  89. {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"})
  90. assert Notification.create_notification(activity, muter)
  91. end
  92. test "it creates a notification for an activity from a muted thread" do
  93. muter = insert(:user)
  94. other_user = insert(:user)
  95. {:ok, activity} = CommonAPI.post(muter, %{"status" => "hey"})
  96. CommonAPI.add_mute(muter, activity)
  97. {:ok, activity} =
  98. CommonAPI.post(other_user, %{
  99. "status" => "Hi @#{muter.nickname}",
  100. "in_reply_to_status_id" => activity.id
  101. })
  102. assert Notification.create_notification(activity, muter)
  103. end
  104. test "it disables notifications from followers" do
  105. follower = insert(:user)
  106. followed = insert(:user, notification_settings: %{"followers" => false})
  107. User.follow(follower, followed)
  108. {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
  109. refute Notification.create_notification(activity, followed)
  110. end
  111. test "it disables notifications from non-followers" do
  112. follower = insert(:user)
  113. followed = insert(:user, notification_settings: %{"non_followers" => false})
  114. {:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
  115. refute Notification.create_notification(activity, followed)
  116. end
  117. test "it disables notifications from people the user follows" do
  118. follower = insert(:user, notification_settings: %{"follows" => false})
  119. followed = insert(:user)
  120. User.follow(follower, followed)
  121. follower = Repo.get(User, follower.id)
  122. {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
  123. refute Notification.create_notification(activity, follower)
  124. end
  125. test "it disables notifications from people the user does not follow" do
  126. follower = insert(:user, notification_settings: %{"non_follows" => false})
  127. followed = insert(:user)
  128. {:ok, activity} = CommonAPI.post(followed, %{"status" => "hey @#{follower.nickname}"})
  129. refute Notification.create_notification(activity, follower)
  130. end
  131. test "it doesn't create a notification for user if he is the activity author" do
  132. activity = insert(:note_activity)
  133. author = User.get_cached_by_ap_id(activity.data["actor"])
  134. refute Notification.create_notification(activity, author)
  135. end
  136. test "it doesn't create a notification for follow-unfollow-follow chains" do
  137. user = insert(:user)
  138. followed_user = insert(:user)
  139. {:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
  140. Notification.create_notification(activity, followed_user)
  141. CommonAPI.unfollow(user, followed_user)
  142. {:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
  143. refute Notification.create_notification(activity_dupe, followed_user)
  144. end
  145. test "it doesn't create duplicate notifications for follow+subscribed users" do
  146. user = insert(:user)
  147. subscriber = insert(:user)
  148. {:ok, _, _, _} = CommonAPI.follow(subscriber, user)
  149. User.subscribe(subscriber, user)
  150. {:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
  151. {:ok, [_notif]} = Notification.create_notifications(status)
  152. end
  153. test "it doesn't create subscription notifications if the recipient cannot see the status" do
  154. user = insert(:user)
  155. subscriber = insert(:user)
  156. User.subscribe(subscriber, user)
  157. {:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
  158. assert {:ok, []} == Notification.create_notifications(status)
  159. end
  160. end
  161. describe "get notification" do
  162. test "it gets a notification that belongs to the user" do
  163. user = insert(:user)
  164. other_user = insert(:user)
  165. {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
  166. {:ok, [notification]} = Notification.create_notifications(activity)
  167. {:ok, notification} = Notification.get(other_user, notification.id)
  168. assert notification.user_id == other_user.id
  169. end
  170. test "it returns error if the notification doesn't belong to the user" do
  171. user = insert(:user)
  172. other_user = insert(:user)
  173. {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
  174. {:ok, [notification]} = Notification.create_notifications(activity)
  175. {:error, _notification} = Notification.get(user, notification.id)
  176. end
  177. end
  178. describe "dismiss notification" do
  179. test "it dismisses a notification that belongs to the user" do
  180. user = insert(:user)
  181. other_user = insert(:user)
  182. {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
  183. {:ok, [notification]} = Notification.create_notifications(activity)
  184. {:ok, notification} = Notification.dismiss(other_user, notification.id)
  185. assert notification.user_id == other_user.id
  186. end
  187. test "it returns error if the notification doesn't belong to the user" do
  188. user = insert(:user)
  189. other_user = insert(:user)
  190. {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
  191. {:ok, [notification]} = Notification.create_notifications(activity)
  192. {:error, _notification} = Notification.dismiss(user, notification.id)
  193. end
  194. end
  195. describe "clear notification" do
  196. test "it clears all notifications belonging to the user" do
  197. user = insert(:user)
  198. other_user = insert(:user)
  199. third_user = insert(:user)
  200. {:ok, activity} =
  201. CommonAPI.post(user, %{
  202. "status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
  203. })
  204. {:ok, _notifs} = Notification.create_notifications(activity)
  205. {:ok, activity} =
  206. CommonAPI.post(user, %{
  207. "status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
  208. })
  209. {:ok, _notifs} = Notification.create_notifications(activity)
  210. Notification.clear(other_user)
  211. assert Notification.for_user(other_user) == []
  212. assert Notification.for_user(third_user) != []
  213. end
  214. end
  215. describe "set_read_up_to()" do
  216. test "it sets all notifications as read up to a specified notification ID" do
  217. user = insert(:user)
  218. other_user = insert(:user)
  219. {:ok, _activity} =
  220. CommonAPI.post(user, %{
  221. "status" => "hey @#{other_user.nickname}!"
  222. })
  223. {:ok, _activity} =
  224. CommonAPI.post(user, %{
  225. "status" => "hey again @#{other_user.nickname}!"
  226. })
  227. [n2, n1] = notifs = Notification.for_user(other_user)
  228. assert length(notifs) == 2
  229. assert n2.id > n1.id
  230. {:ok, _activity} =
  231. CommonAPI.post(user, %{
  232. "status" => "hey yet again @#{other_user.nickname}!"
  233. })
  234. Notification.set_read_up_to(other_user, n2.id)
  235. [n3, n2, n1] = Notification.for_user(other_user)
  236. assert n1.seen == true
  237. assert n2.seen == true
  238. assert n3.seen == false
  239. end
  240. end
  241. describe "for_user_since/2" do
  242. defp days_ago(days) do
  243. NaiveDateTime.add(
  244. NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
  245. -days * 60 * 60 * 24,
  246. :second
  247. )
  248. end
  249. test "Returns recent notifications" do
  250. user1 = insert(:user)
  251. user2 = insert(:user)
  252. Enum.each(0..10, fn i ->
  253. {:ok, _activity} =
  254. CommonAPI.post(user1, %{
  255. "status" => "hey ##{i} @#{user2.nickname}!"
  256. })
  257. end)
  258. {old, new} = Enum.split(Notification.for_user(user2), 5)
  259. Enum.each(old, fn notification ->
  260. notification
  261. |> cast(%{updated_at: days_ago(10)}, [:updated_at])
  262. |> Pleroma.Repo.update!()
  263. end)
  264. recent_notifications_ids =
  265. user2
  266. |> Notification.for_user_since(
  267. NaiveDateTime.add(NaiveDateTime.utc_now(), -5 * 86_400, :second)
  268. )
  269. |> Enum.map(& &1.id)
  270. Enum.each(old, fn %{id: id} ->
  271. refute id in recent_notifications_ids
  272. end)
  273. Enum.each(new, fn %{id: id} ->
  274. assert id in recent_notifications_ids
  275. end)
  276. end
  277. end
  278. describe "notification target determination" do
  279. test "it sends notifications to addressed users in new messages" do
  280. user = insert(:user)
  281. other_user = insert(:user)
  282. {:ok, activity} =
  283. CommonAPI.post(user, %{
  284. "status" => "hey @#{other_user.nickname}!"
  285. })
  286. assert other_user in Notification.get_notified_from_activity(activity)
  287. end
  288. test "it sends notifications to mentioned users in new messages" do
  289. user = insert(:user)
  290. other_user = insert(:user)
  291. create_activity = %{
  292. "@context" => "https://www.w3.org/ns/activitystreams",
  293. "type" => "Create",
  294. "to" => ["https://www.w3.org/ns/activitystreams#Public"],
  295. "actor" => user.ap_id,
  296. "object" => %{
  297. "type" => "Note",
  298. "content" => "message with a Mention tag, but no explicit tagging",
  299. "tag" => [
  300. %{
  301. "type" => "Mention",
  302. "href" => other_user.ap_id,
  303. "name" => other_user.nickname
  304. }
  305. ],
  306. "attributedTo" => user.ap_id
  307. }
  308. }
  309. {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
  310. assert other_user in Notification.get_notified_from_activity(activity)
  311. end
  312. test "it does not send notifications to users who are only cc in new messages" do
  313. user = insert(:user)
  314. other_user = insert(:user)
  315. create_activity = %{
  316. "@context" => "https://www.w3.org/ns/activitystreams",
  317. "type" => "Create",
  318. "to" => ["https://www.w3.org/ns/activitystreams#Public"],
  319. "cc" => [other_user.ap_id],
  320. "actor" => user.ap_id,
  321. "object" => %{
  322. "type" => "Note",
  323. "content" => "hi everyone",
  324. "attributedTo" => user.ap_id
  325. }
  326. }
  327. {:ok, activity} = Transmogrifier.handle_incoming(create_activity)
  328. assert other_user not in Notification.get_notified_from_activity(activity)
  329. end
  330. test "it does not send notification to mentioned users in likes" do
  331. user = insert(:user)
  332. other_user = insert(:user)
  333. third_user = insert(:user)
  334. {:ok, activity_one} =
  335. CommonAPI.post(user, %{
  336. "status" => "hey @#{other_user.nickname}!"
  337. })
  338. {:ok, activity_two, _} = CommonAPI.favorite(activity_one.id, third_user)
  339. assert other_user not in Notification.get_notified_from_activity(activity_two)
  340. end
  341. test "it does not send notification to mentioned users in announces" do
  342. user = insert(:user)
  343. other_user = insert(:user)
  344. third_user = insert(:user)
  345. {:ok, activity_one} =
  346. CommonAPI.post(user, %{
  347. "status" => "hey @#{other_user.nickname}!"
  348. })
  349. {:ok, activity_two, _} = CommonAPI.repeat(activity_one.id, third_user)
  350. assert other_user not in Notification.get_notified_from_activity(activity_two)
  351. end
  352. end
  353. describe "notification lifecycle" do
  354. test "liking an activity results in 1 notification, then 0 if the activity is deleted" do
  355. user = insert(:user)
  356. other_user = insert(:user)
  357. {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
  358. assert Enum.empty?(Notification.for_user(user))
  359. {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
  360. assert length(Notification.for_user(user)) == 1
  361. {:ok, _} = CommonAPI.delete(activity.id, user)
  362. assert Enum.empty?(Notification.for_user(user))
  363. end
  364. test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
  365. user = insert(:user)
  366. other_user = insert(:user)
  367. {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
  368. assert Enum.empty?(Notification.for_user(user))
  369. {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
  370. assert length(Notification.for_user(user)) == 1
  371. {:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
  372. assert Enum.empty?(Notification.for_user(user))
  373. end
  374. test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
  375. user = insert(:user)
  376. other_user = insert(:user)
  377. {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
  378. assert Enum.empty?(Notification.for_user(user))
  379. {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
  380. assert length(Notification.for_user(user)) == 1
  381. {:ok, _} = CommonAPI.delete(activity.id, user)
  382. assert Enum.empty?(Notification.for_user(user))
  383. end
  384. test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
  385. user = insert(:user)
  386. other_user = insert(:user)
  387. {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
  388. assert Enum.empty?(Notification.for_user(user))
  389. {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
  390. assert length(Notification.for_user(user)) == 1
  391. {:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
  392. assert Enum.empty?(Notification.for_user(user))
  393. end
  394. test "liking an activity which is already deleted does not generate a notification" do
  395. user = insert(:user)
  396. other_user = insert(:user)
  397. {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
  398. assert Enum.empty?(Notification.for_user(user))
  399. {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
  400. assert Enum.empty?(Notification.for_user(user))
  401. {:error, _} = CommonAPI.favorite(activity.id, other_user)
  402. assert Enum.empty?(Notification.for_user(user))
  403. end
  404. test "repeating an activity which is already deleted does not generate a notification" do
  405. user = insert(:user)
  406. other_user = insert(:user)
  407. {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
  408. assert Enum.empty?(Notification.for_user(user))
  409. {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
  410. assert Enum.empty?(Notification.for_user(user))
  411. {:error, _} = CommonAPI.repeat(activity.id, other_user)
  412. assert Enum.empty?(Notification.for_user(user))
  413. end
  414. test "replying to a deleted post without tagging does not generate a notification" do
  415. user = insert(:user)
  416. other_user = insert(:user)
  417. {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
  418. {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
  419. {:ok, _reply_activity} =
  420. CommonAPI.post(other_user, %{
  421. "status" => "test reply",
  422. "in_reply_to_status_id" => activity.id
  423. })
  424. assert Enum.empty?(Notification.for_user(user))
  425. end
  426. test "notifications are deleted if a local user is deleted" do
  427. user = insert(:user)
  428. other_user = insert(:user)
  429. {:ok, _activity} =
  430. CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}", "visibility" => "direct"})
  431. refute Enum.empty?(Notification.for_user(other_user))
  432. {:ok, job} = User.delete(user)
  433. ObanHelpers.perform(job)
  434. assert Enum.empty?(Notification.for_user(other_user))
  435. end
  436. test "notifications are deleted if a remote user is deleted" do
  437. remote_user = insert(:user)
  438. local_user = insert(:user)
  439. dm_message = %{
  440. "@context" => "https://www.w3.org/ns/activitystreams",
  441. "type" => "Create",
  442. "actor" => remote_user.ap_id,
  443. "id" => remote_user.ap_id <> "/activities/test",
  444. "to" => [local_user.ap_id],
  445. "cc" => [],
  446. "object" => %{
  447. "type" => "Note",
  448. "content" => "Hello!",
  449. "tag" => [
  450. %{
  451. "type" => "Mention",
  452. "href" => local_user.ap_id,
  453. "name" => "@#{local_user.nickname}"
  454. }
  455. ],
  456. "to" => [local_user.ap_id],
  457. "cc" => [],
  458. "attributedTo" => remote_user.ap_id
  459. }
  460. }
  461. {:ok, _dm_activity} = Transmogrifier.handle_incoming(dm_message)
  462. refute Enum.empty?(Notification.for_user(local_user))
  463. delete_user_message = %{
  464. "@context" => "https://www.w3.org/ns/activitystreams",
  465. "id" => remote_user.ap_id <> "/activities/delete",
  466. "actor" => remote_user.ap_id,
  467. "type" => "Delete",
  468. "object" => remote_user.ap_id
  469. }
  470. {:ok, _delete_activity} = Transmogrifier.handle_incoming(delete_user_message)
  471. ObanHelpers.perform_all()
  472. assert Enum.empty?(Notification.for_user(local_user))
  473. end
  474. end
  475. describe "for_user" do
  476. test "it returns notifications for muted user without notifications" do
  477. user = insert(:user)
  478. muted = insert(:user)
  479. {:ok, user} = User.mute(user, muted, false)
  480. {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
  481. assert length(Notification.for_user(user)) == 1
  482. end
  483. test "it doesn't return notifications for muted user with notifications" do
  484. user = insert(:user)
  485. muted = insert(:user)
  486. {:ok, user} = User.mute(user, muted)
  487. {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
  488. assert Notification.for_user(user) == []
  489. end
  490. test "it doesn't return notifications for blocked user" do
  491. user = insert(:user)
  492. blocked = insert(:user)
  493. {:ok, user} = User.block(user, blocked)
  494. {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
  495. assert Notification.for_user(user) == []
  496. end
  497. test "it doesn't return notificatitons for blocked domain" do
  498. user = insert(:user)
  499. blocked = insert(:user, ap_id: "http://some-domain.com")
  500. {:ok, user} = User.block_domain(user, "some-domain.com")
  501. {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
  502. assert Notification.for_user(user) == []
  503. end
  504. test "it doesn't return notifications for muted thread" do
  505. user = insert(:user)
  506. another_user = insert(:user)
  507. {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
  508. {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
  509. assert Notification.for_user(user) == []
  510. end
  511. test "it returns notifications from a muted user when with_muted is set" do
  512. user = insert(:user)
  513. muted = insert(:user)
  514. {:ok, user} = User.mute(user, muted)
  515. {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
  516. assert length(Notification.for_user(user, %{with_muted: true})) == 1
  517. end
  518. test "it doesn't return notifications from a blocked user when with_muted is set" do
  519. user = insert(:user)
  520. blocked = insert(:user)
  521. {:ok, user} = User.block(user, blocked)
  522. {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
  523. assert length(Notification.for_user(user, %{with_muted: true})) == 0
  524. end
  525. test "it doesn't return notifications from a domain-blocked user when with_muted is set" do
  526. user = insert(:user)
  527. blocked = insert(:user, ap_id: "http://some-domain.com")
  528. {:ok, user} = User.block_domain(user, "some-domain.com")
  529. {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
  530. assert length(Notification.for_user(user, %{with_muted: true})) == 0
  531. end
  532. test "it returns notifications from muted threads when with_muted is set" do
  533. user = insert(:user)
  534. another_user = insert(:user)
  535. {:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
  536. {:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
  537. assert length(Notification.for_user(user, %{with_muted: true})) == 1
  538. end
  539. end
  540. end