1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.StreamerTest do
11 alias Pleroma.Chat.MessageReference
12 alias Pleroma.Conversation.Participation
16 alias Pleroma.Web.CommonAPI
17 alias Pleroma.Web.Streamer
18 alias Pleroma.Web.StreamerView
20 @moduletag needs_streamer: true, capture_log: true
22 setup do: clear_config([:instance, :skip_thread_containment])
24 describe "get_topic/_ (unauthenticated)" do
25 test "allows public" do
26 assert {:ok, "public"} = Streamer.get_topic("public", nil, nil)
27 assert {:ok, "public:local"} = Streamer.get_topic("public:local", nil, nil)
28 assert {:ok, "public:media"} = Streamer.get_topic("public:media", nil, nil)
29 assert {:ok, "public:local:media"} = Streamer.get_topic("public:local:media", nil, nil)
32 test "allows instance streams" do
33 assert {:ok, "public:remote:lain.com"} =
34 Streamer.get_topic("public:remote", nil, nil, %{"instance" => "lain.com"})
36 assert {:ok, "public:remote:media:lain.com"} =
37 Streamer.get_topic("public:remote:media", nil, nil, %{"instance" => "lain.com"})
40 test "allows hashtag streams" do
41 assert {:ok, "hashtag:cofe"} = Streamer.get_topic("hashtag", nil, nil, %{"tag" => "cofe"})
44 test "disallows user streams" do
45 assert {:error, _} = Streamer.get_topic("user", nil, nil)
46 assert {:error, _} = Streamer.get_topic("user:notification", nil, nil)
47 assert {:error, _} = Streamer.get_topic("direct", nil, nil)
50 test "disallows list streams" do
51 assert {:error, _} = Streamer.get_topic("list", nil, nil, %{"list" => 42})
55 describe "get_topic/_ (authenticated)" do
56 setup do: oauth_access(["read"])
58 test "allows public streams (regardless of OAuth token scopes)", %{
60 token: read_oauth_token
62 with oauth_token <- [nil, read_oauth_token] do
63 assert {:ok, "public"} = Streamer.get_topic("public", user, oauth_token)
64 assert {:ok, "public:local"} = Streamer.get_topic("public:local", user, oauth_token)
65 assert {:ok, "public:media"} = Streamer.get_topic("public:media", user, oauth_token)
67 assert {:ok, "public:local:media"} =
68 Streamer.get_topic("public:local:media", user, oauth_token)
72 test "allows user streams (with proper OAuth token scopes)", %{
74 token: read_oauth_token
76 %{token: read_notifications_token} = oauth_access(["read:notifications"], user: user)
77 %{token: read_statuses_token} = oauth_access(["read:statuses"], user: user)
78 %{token: badly_scoped_token} = oauth_access(["irrelevant:scope"], user: user)
80 expected_user_topic = "user:#{user.id}"
81 expected_notification_topic = "user:notification:#{user.id}"
82 expected_direct_topic = "direct:#{user.id}"
83 expected_pleroma_chat_topic = "user:pleroma_chat:#{user.id}"
85 for valid_user_token <- [read_oauth_token, read_statuses_token] do
86 assert {:ok, ^expected_user_topic} = Streamer.get_topic("user", user, valid_user_token)
88 assert {:ok, ^expected_direct_topic} =
89 Streamer.get_topic("direct", user, valid_user_token)
91 assert {:ok, ^expected_pleroma_chat_topic} =
92 Streamer.get_topic("user:pleroma_chat", user, valid_user_token)
95 for invalid_user_token <- [read_notifications_token, badly_scoped_token],
96 user_topic <- ["user", "direct", "user:pleroma_chat"] do
97 assert {:error, :unauthorized} = Streamer.get_topic(user_topic, user, invalid_user_token)
100 for valid_notification_token <- [read_oauth_token, read_notifications_token] do
101 assert {:ok, ^expected_notification_topic} =
102 Streamer.get_topic("user:notification", user, valid_notification_token)
105 for invalid_notification_token <- [read_statuses_token, badly_scoped_token] do
106 assert {:error, :unauthorized} =
107 Streamer.get_topic("user:notification", user, invalid_notification_token)
111 test "allows hashtag streams (regardless of OAuth token scopes)", %{
113 token: read_oauth_token
115 for oauth_token <- [nil, read_oauth_token] do
116 assert {:ok, "hashtag:cofe"} =
117 Streamer.get_topic("hashtag", user, oauth_token, %{"tag" => "cofe"})
121 test "disallows registering to another user's stream", %{user: user, token: read_oauth_token} do
122 another_user = insert(:user)
123 assert {:error, _} = Streamer.get_topic("user:#{another_user.id}", user, read_oauth_token)
126 Streamer.get_topic("user:notification:#{another_user.id}", user, read_oauth_token)
128 assert {:error, _} = Streamer.get_topic("direct:#{another_user.id}", user, read_oauth_token)
131 test "allows list stream that are owned by the user (with `read` or `read:lists` scopes)", %{
133 token: read_oauth_token
135 %{token: read_lists_token} = oauth_access(["read:lists"], user: user)
136 %{token: invalid_token} = oauth_access(["irrelevant:scope"], user: user)
137 {:ok, list} = List.create("Test", user)
139 assert {:error, _} = Streamer.get_topic("list:#{list.id}", user, read_oauth_token)
141 for valid_token <- [read_oauth_token, read_lists_token] do
142 assert {:ok, _} = Streamer.get_topic("list", user, valid_token, %{"list" => list.id})
145 assert {:error, _} = Streamer.get_topic("list", user, invalid_token, %{"list" => list.id})
148 test "disallows list stream that are not owned by the user", %{user: user, token: oauth_token} do
149 another_user = insert(:user)
150 {:ok, list} = List.create("Test", another_user)
152 assert {:error, _} = Streamer.get_topic("list:#{list.id}", user, oauth_token)
153 assert {:error, _} = Streamer.get_topic("list", user, oauth_token, %{"list" => list.id})
157 describe "user streams" do
159 %{user: user, token: token} = oauth_access(["read"])
160 notify = insert(:notification, user: user, activity: build(:note_activity))
161 {:ok, %{user: user, notify: notify, token: token}}
164 test "it streams the user's post in the 'user' stream", %{user: user, token: oauth_token} do
165 Streamer.get_topic_and_add_socket("user", user, oauth_token)
166 {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
168 assert_receive {:render_with_user, _, _, ^activity}
169 refute Streamer.filtered_by_user?(user, activity)
172 test "it streams boosts of the user in the 'user' stream", %{user: user, token: oauth_token} do
173 Streamer.get_topic_and_add_socket("user", user, oauth_token)
175 other_user = insert(:user)
176 {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
177 {:ok, announce} = CommonAPI.repeat(activity.id, user)
179 assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce}
180 refute Streamer.filtered_by_user?(user, announce)
183 test "it does not stream announces of the user's own posts in the 'user' stream", %{
187 Streamer.get_topic_and_add_socket("user", user, oauth_token)
189 other_user = insert(:user)
190 {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
191 {:ok, announce} = CommonAPI.repeat(activity.id, other_user)
193 assert Streamer.filtered_by_user?(user, announce)
196 test "it does stream notifications announces of the user's own posts in the 'user' stream", %{
200 Streamer.get_topic_and_add_socket("user", user, oauth_token)
202 other_user = insert(:user)
203 {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
204 {:ok, announce} = CommonAPI.repeat(activity.id, other_user)
208 |> Repo.get_by(%{user_id: user.id, activity_id: announce.id})
209 |> Repo.preload(:activity)
211 refute Streamer.filtered_by_user?(user, notification)
214 test "it streams boosts of mastodon user in the 'user' stream", %{
218 Streamer.get_topic_and_add_socket("user", user, oauth_token)
220 other_user = insert(:user)
221 {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
224 File.read!("test/fixtures/mastodon-announce.json")
226 |> Map.put("object", activity.data["object"])
227 |> Map.put("actor", user.ap_id)
229 {:ok, %Pleroma.Activity{data: _data, local: false} = announce} =
230 Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(data)
232 assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce}
233 refute Streamer.filtered_by_user?(user, announce)
236 test "it sends notify to in the 'user' stream", %{
241 Streamer.get_topic_and_add_socket("user", user, oauth_token)
242 Streamer.stream("user", notify)
244 assert_receive {:render_with_user, _, _, ^notify}
245 refute Streamer.filtered_by_user?(user, notify)
248 test "it sends notify to in the 'user:notification' stream", %{
253 Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
254 Streamer.stream("user:notification", notify)
256 assert_receive {:render_with_user, _, _, ^notify}
257 refute Streamer.filtered_by_user?(user, notify)
260 test "it sends chat messages to the 'user:pleroma_chat' stream", %{
264 other_user = insert(:user)
266 {:ok, create_activity} =
267 CommonAPI.post_chat_message(other_user, user, "hey cirno", idempotency_key: "123")
269 object = Object.normalize(create_activity, fetch: false)
270 chat = Chat.get(user.id, other_user.ap_id)
271 cm_ref = MessageReference.for_chat_and_object(chat, object)
272 cm_ref = %{cm_ref | chat: chat, object: object}
274 Streamer.get_topic_and_add_socket("user:pleroma_chat", user, oauth_token)
275 Streamer.stream("user:pleroma_chat", {user, cm_ref})
277 text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref})
279 assert text =~ "hey cirno"
280 assert_receive {:text, ^text}
283 test "it sends chat messages to the 'user' stream", %{user: user, token: oauth_token} do
284 other_user = insert(:user)
286 {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno")
287 object = Object.normalize(create_activity, fetch: false)
288 chat = Chat.get(user.id, other_user.ap_id)
289 cm_ref = MessageReference.for_chat_and_object(chat, object)
290 cm_ref = %{cm_ref | chat: chat, object: object}
292 Streamer.get_topic_and_add_socket("user", user, oauth_token)
293 Streamer.stream("user", {user, cm_ref})
295 text = StreamerView.render("chat_update.json", %{chat_message_reference: cm_ref})
297 assert text =~ "hey cirno"
298 assert_receive {:text, ^text}
301 test "it sends chat message notifications to the 'user:notification' stream", %{
305 other_user = insert(:user)
307 {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey")
310 Repo.get_by(Pleroma.Notification, user_id: user.id, activity_id: create_activity.id)
311 |> Repo.preload(:activity)
313 Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
314 Streamer.stream("user:notification", notify)
316 assert_receive {:render_with_user, _, _, ^notify}
317 refute Streamer.filtered_by_user?(user, notify)
320 test "it doesn't send notify to the 'user:notification' stream when a user is blocked", %{
324 blocked = insert(:user)
325 {:ok, _user_relationship} = User.block(user, blocked)
327 Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
329 {:ok, activity} = CommonAPI.post(user, %{status: ":("})
330 {:ok, _} = CommonAPI.favorite(blocked, activity.id)
335 test "it doesn't send notify to the 'user:notification' stream when a thread is muted", %{
339 user2 = insert(:user)
341 {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
342 {:ok, _} = CommonAPI.add_mute(user, activity)
344 Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
346 {:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
349 assert Streamer.filtered_by_user?(user, favorite_activity)
352 test "it sends favorite to 'user:notification' stream'", %{
356 user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
358 {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
359 Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
360 {:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
362 assert_receive {:render_with_user, _, "notification.json", notif}
363 assert notif.activity.id == favorite_activity.id
364 refute Streamer.filtered_by_user?(user, notif)
367 test "it doesn't send the 'user:notification' stream' when a domain is blocked", %{
371 user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
373 {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
374 {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
375 Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
376 {:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id)
379 assert Streamer.filtered_by_user?(user, favorite_activity)
382 test "it sends follow activities to the 'user:notification' stream", %{
386 user_url = user.ap_id
387 user2 = insert(:user)
390 File.read!("test/fixtures/users_mock/localhost.json")
391 |> String.replace("{{nickname}}", user.nickname)
394 Tesla.Mock.mock_global(fn
395 %{method: :get, url: ^user_url} ->
396 %Tesla.Env{status: 200, body: body}
399 Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
400 {:ok, _follower, _followed, follow_activity} = CommonAPI.follow(user2, user)
402 assert_receive {:render_with_user, _, "notification.json", notif}
403 assert notif.activity.id == follow_activity.id
404 refute Streamer.filtered_by_user?(user, notif)
407 test "it sends follow relationships updates to the 'user' stream", %{
412 user_url = user.ap_id
413 other_user = insert(:user)
414 other_user_id = other_user.id
417 File.read!("test/fixtures/users_mock/localhost.json")
418 |> String.replace("{{nickname}}", user.nickname)
421 Tesla.Mock.mock_global(fn
422 %{method: :get, url: ^user_url} ->
423 %Tesla.Env{status: 200, body: body}
426 Streamer.get_topic_and_add_socket("user", user, oauth_token)
427 {:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(user, other_user)
429 assert_receive {:text, event}
431 assert %{"event" => "pleroma:follow_relationships_update", "payload" => payload} =
436 "follower_count" => 0,
437 "following_count" => 0,
441 "follower_count" => 0,
442 "following_count" => 0,
443 "id" => ^other_user_id
445 "state" => "follow_pending"
446 } = Jason.decode!(payload)
448 assert_receive {:text, event}
450 assert %{"event" => "pleroma:follow_relationships_update", "payload" => payload} =
455 "follower_count" => 0,
456 "following_count" => 1,
460 "follower_count" => 1,
461 "following_count" => 0,
462 "id" => ^other_user_id
464 "state" => "follow_accept"
465 } = Jason.decode!(payload)
469 describe "public streams" do
470 test "it sends to public (authenticated)" do
471 %{user: user, token: oauth_token} = oauth_access(["read"])
472 other_user = insert(:user)
474 Streamer.get_topic_and_add_socket("public", user, oauth_token)
476 {:ok, activity} = CommonAPI.post(other_user, %{status: "Test"})
477 assert_receive {:render_with_user, _, _, ^activity}
478 refute Streamer.filtered_by_user?(other_user, activity)
481 test "it sends to public (unauthenticated)" do
484 Streamer.get_topic_and_add_socket("public", nil, nil)
486 {:ok, activity} = CommonAPI.post(user, %{status: "Test"})
487 activity_id = activity.id
488 assert_receive {:text, event}
489 assert %{"event" => "update", "payload" => payload} = Jason.decode!(event)
490 assert %{"id" => ^activity_id} = Jason.decode!(payload)
492 {:ok, _} = CommonAPI.delete(activity.id, user)
493 assert_receive {:text, event}
494 assert %{"event" => "delete", "payload" => ^activity_id} = Jason.decode!(event)
497 test "handles deletions" do
498 %{user: user, token: oauth_token} = oauth_access(["read"])
499 other_user = insert(:user)
500 {:ok, activity} = CommonAPI.post(other_user, %{status: "Test"})
502 Streamer.get_topic_and_add_socket("public", user, oauth_token)
504 {:ok, _} = CommonAPI.delete(activity.id, other_user)
505 activity_id = activity.id
506 assert_receive {:text, event}
507 assert %{"event" => "delete", "payload" => ^activity_id} = Jason.decode!(event)
511 describe "thread_containment/2" do
512 test "it filters to user if recipients invalid and thread containment is enabled" do
513 Pleroma.Config.put([:instance, :skip_thread_containment], false)
514 author = insert(:user)
515 %{user: user, token: oauth_token} = oauth_access(["read"])
516 User.follow(user, author, :follow_accept)
519 insert(:note_activity,
523 data: %{"to" => ["TEST-FFF"]}
527 Streamer.get_topic_and_add_socket("public", user, oauth_token)
528 Streamer.stream("public", activity)
529 assert_receive {:render_with_user, _, _, ^activity}
530 assert Streamer.filtered_by_user?(user, activity)
533 test "it sends message if recipients invalid and thread containment is disabled" do
534 Pleroma.Config.put([:instance, :skip_thread_containment], true)
535 author = insert(:user)
536 %{user: user, token: oauth_token} = oauth_access(["read"])
537 User.follow(user, author, :follow_accept)
540 insert(:note_activity,
544 data: %{"to" => ["TEST-FFF"]}
548 Streamer.get_topic_and_add_socket("public", user, oauth_token)
549 Streamer.stream("public", activity)
551 assert_receive {:render_with_user, _, _, ^activity}
552 refute Streamer.filtered_by_user?(user, activity)
555 test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
556 Pleroma.Config.put([:instance, :skip_thread_containment], false)
557 author = insert(:user)
558 user = insert(:user, skip_thread_containment: true)
559 %{token: oauth_token} = oauth_access(["read"], user: user)
560 User.follow(user, author, :follow_accept)
563 insert(:note_activity,
567 data: %{"to" => ["TEST-FFF"]}
571 Streamer.get_topic_and_add_socket("public", user, oauth_token)
572 Streamer.stream("public", activity)
574 assert_receive {:render_with_user, _, _, ^activity}
575 refute Streamer.filtered_by_user?(user, activity)
580 setup do: oauth_access(["read"])
582 test "it filters messages involving blocked users", %{user: user, token: oauth_token} do
583 blocked_user = insert(:user)
584 {:ok, _user_relationship} = User.block(user, blocked_user)
586 Streamer.get_topic_and_add_socket("public", user, oauth_token)
587 {:ok, activity} = CommonAPI.post(blocked_user, %{status: "Test"})
588 assert_receive {:render_with_user, _, _, ^activity}
589 assert Streamer.filtered_by_user?(user, activity)
592 test "it filters messages transitively involving blocked users", %{
596 blockee = insert(:user)
597 friend = insert(:user)
599 Streamer.get_topic_and_add_socket("public", blocker, blocker_token)
601 {:ok, _user_relationship} = User.block(blocker, blockee)
603 {:ok, activity_one} = CommonAPI.post(friend, %{status: "hey! @#{blockee.nickname}"})
605 assert_receive {:render_with_user, _, _, ^activity_one}
606 assert Streamer.filtered_by_user?(blocker, activity_one)
608 {:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"})
610 assert_receive {:render_with_user, _, _, ^activity_two}
611 assert Streamer.filtered_by_user?(blocker, activity_two)
613 {:ok, activity_three} = CommonAPI.post(blockee, %{status: "hey! @#{blocker.nickname}"})
615 assert_receive {:render_with_user, _, _, ^activity_three}
616 assert Streamer.filtered_by_user?(blocker, activity_three)
621 setup do: oauth_access(["read"])
623 test "it doesn't send unwanted DMs to list", %{user: user_a, token: user_a_token} do
624 user_b = insert(:user)
625 user_c = insert(:user)
627 {:ok, user_a, user_b} = User.follow(user_a, user_b)
629 {:ok, list} = List.create("Test", user_a)
630 {:ok, list} = List.follow(list, user_b)
632 Streamer.get_topic_and_add_socket("list", user_a, user_a_token, %{"list" => list.id})
635 CommonAPI.post(user_b, %{
636 status: "@#{user_c.nickname} Test",
643 test "it doesn't send unwanted private posts to list", %{user: user_a, token: user_a_token} do
644 user_b = insert(:user)
646 {:ok, list} = List.create("Test", user_a)
647 {:ok, list} = List.follow(list, user_b)
649 Streamer.get_topic_and_add_socket("list", user_a, user_a_token, %{"list" => list.id})
652 CommonAPI.post(user_b, %{
654 visibility: "private"
660 test "it sends wanted private posts to list", %{user: user_a, token: user_a_token} do
661 user_b = insert(:user)
663 {:ok, user_a, user_b} = User.follow(user_a, user_b)
665 {:ok, list} = List.create("Test", user_a)
666 {:ok, list} = List.follow(list, user_b)
668 Streamer.get_topic_and_add_socket("list", user_a, user_a_token, %{"list" => list.id})
671 CommonAPI.post(user_b, %{
673 visibility: "private"
676 assert_receive {:render_with_user, _, _, ^activity}
677 refute Streamer.filtered_by_user?(user_a, activity)
681 describe "muted reblogs" do
682 setup do: oauth_access(["read"])
684 test "it filters muted reblogs", %{user: user1, token: user1_token} do
685 user2 = insert(:user)
686 user3 = insert(:user)
687 CommonAPI.follow(user1, user2)
688 CommonAPI.hide_reblogs(user1, user2)
690 {:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"})
692 Streamer.get_topic_and_add_socket("user", user1, user1_token)
693 {:ok, announce_activity} = CommonAPI.repeat(create_activity.id, user2)
694 assert_receive {:render_with_user, _, _, ^announce_activity}
695 assert Streamer.filtered_by_user?(user1, announce_activity)
698 test "it filters reblog notification for reblog-muted actors", %{
702 user2 = insert(:user)
703 CommonAPI.follow(user1, user2)
704 CommonAPI.hide_reblogs(user1, user2)
706 {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
707 Streamer.get_topic_and_add_socket("user", user1, user1_token)
708 {:ok, _announce_activity} = CommonAPI.repeat(create_activity.id, user2)
710 assert_receive {:render_with_user, _, "notification.json", notif}
711 assert Streamer.filtered_by_user?(user1, notif)
714 test "it send non-reblog notification for reblog-muted actors", %{
718 user2 = insert(:user)
719 CommonAPI.follow(user1, user2)
720 CommonAPI.hide_reblogs(user1, user2)
722 {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
723 Streamer.get_topic_and_add_socket("user", user1, user1_token)
724 {:ok, _favorite_activity} = CommonAPI.favorite(user2, create_activity.id)
726 assert_receive {:render_with_user, _, "notification.json", notif}
727 refute Streamer.filtered_by_user?(user1, notif)
731 describe "muted threads" do
732 test "it filters posts from muted threads" do
734 %{user: user2, token: user2_token} = oauth_access(["read"])
735 Streamer.get_topic_and_add_socket("user", user2, user2_token)
737 {:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
738 {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
739 {:ok, _} = CommonAPI.add_mute(user2, activity)
741 assert_receive {:render_with_user, _, _, ^activity}
742 assert Streamer.filtered_by_user?(user2, activity)
746 describe "direct streams" do
747 setup do: oauth_access(["read"])
749 test "it sends conversation update to the 'direct' stream", %{user: user, token: oauth_token} do
750 another_user = insert(:user)
752 Streamer.get_topic_and_add_socket("direct", user, oauth_token)
754 {:ok, _create_activity} =
755 CommonAPI.post(another_user, %{
756 status: "hey @#{user.nickname}",
760 assert_receive {:text, received_event}
762 assert %{"event" => "conversation", "payload" => received_payload} =
763 Jason.decode!(received_event)
765 assert %{"last_status" => last_status} = Jason.decode!(received_payload)
766 [participation] = Participation.for_user(user)
767 assert last_status["pleroma"]["direct_conversation_id"] == participation.id
770 test "it doesn't send conversation update to the 'direct' stream when the last message in the conversation is deleted",
771 %{user: user, token: oauth_token} do
772 another_user = insert(:user)
774 Streamer.get_topic_and_add_socket("direct", user, oauth_token)
776 {:ok, create_activity} =
777 CommonAPI.post(another_user, %{
778 status: "hi @#{user.nickname}",
782 create_activity_id = create_activity.id
783 assert_receive {:render_with_user, _, _, ^create_activity}
784 assert_receive {:text, received_conversation1}
785 assert %{"event" => "conversation", "payload" => _} = Jason.decode!(received_conversation1)
787 {:ok, _} = CommonAPI.delete(create_activity_id, another_user)
789 assert_receive {:text, received_event}
791 assert %{"event" => "delete", "payload" => ^create_activity_id} =
792 Jason.decode!(received_event)
797 test "it sends conversation update to the 'direct' stream when a message is deleted", %{
801 another_user = insert(:user)
802 Streamer.get_topic_and_add_socket("direct", user, oauth_token)
804 {:ok, create_activity} =
805 CommonAPI.post(another_user, %{
806 status: "hi @#{user.nickname}",
810 {:ok, create_activity2} =
811 CommonAPI.post(another_user, %{
812 status: "hi @#{user.nickname} 2",
813 in_reply_to_status_id: create_activity.id,
817 assert_receive {:render_with_user, _, _, ^create_activity}
818 assert_receive {:render_with_user, _, _, ^create_activity2}
819 assert_receive {:text, received_conversation1}
820 assert %{"event" => "conversation", "payload" => _} = Jason.decode!(received_conversation1)
821 assert_receive {:text, received_conversation1}
822 assert %{"event" => "conversation", "payload" => _} = Jason.decode!(received_conversation1)
824 {:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
826 assert_receive {:text, received_event}
827 assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
829 assert_receive {:text, received_event}
831 assert %{"event" => "conversation", "payload" => received_payload} =
832 Jason.decode!(received_event)
834 assert %{"last_status" => last_status} = Jason.decode!(received_payload)
835 assert last_status["id"] == to_string(create_activity.id)