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.

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