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 user2 = insert(:user)
388 Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
389 {:ok, _follower, _followed, follow_activity} = CommonAPI.follow(user2, user)
391 assert_receive {:render_with_user, _, "notification.json", notif}
392 assert notif.activity.id == follow_activity.id
393 refute Streamer.filtered_by_user?(user, notif)
396 test "it sends follow relationships updates to the 'user' stream", %{
401 other_user = insert(:user)
402 other_user_id = other_user.id
404 Streamer.get_topic_and_add_socket("user", user, oauth_token)
405 {:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(user, other_user)
407 assert_receive {:text, event}
409 assert %{"event" => "pleroma:follow_relationships_update", "payload" => payload} =
414 "follower_count" => 0,
415 "following_count" => 0,
419 "follower_count" => 0,
420 "following_count" => 0,
421 "id" => ^other_user_id
423 "state" => "follow_pending"
424 } = Jason.decode!(payload)
426 assert_receive {:text, event}
428 assert %{"event" => "pleroma:follow_relationships_update", "payload" => payload} =
433 "follower_count" => 0,
434 "following_count" => 1,
438 "follower_count" => 1,
439 "following_count" => 0,
440 "id" => ^other_user_id
442 "state" => "follow_accept"
443 } = Jason.decode!(payload)
447 describe "public streams" do
448 test "it sends to public (authenticated)" do
449 %{user: user, token: oauth_token} = oauth_access(["read"])
450 other_user = insert(:user)
452 Streamer.get_topic_and_add_socket("public", user, oauth_token)
454 {:ok, activity} = CommonAPI.post(other_user, %{status: "Test"})
455 assert_receive {:render_with_user, _, _, ^activity}
456 refute Streamer.filtered_by_user?(other_user, activity)
459 test "it sends to public (unauthenticated)" do
462 Streamer.get_topic_and_add_socket("public", nil, nil)
464 {:ok, activity} = CommonAPI.post(user, %{status: "Test"})
465 activity_id = activity.id
466 assert_receive {:text, event}
467 assert %{"event" => "update", "payload" => payload} = Jason.decode!(event)
468 assert %{"id" => ^activity_id} = Jason.decode!(payload)
470 {:ok, _} = CommonAPI.delete(activity.id, user)
471 assert_receive {:text, event}
472 assert %{"event" => "delete", "payload" => ^activity_id} = Jason.decode!(event)
475 test "handles deletions" do
476 %{user: user, token: oauth_token} = oauth_access(["read"])
477 other_user = insert(:user)
478 {:ok, activity} = CommonAPI.post(other_user, %{status: "Test"})
480 Streamer.get_topic_and_add_socket("public", user, oauth_token)
482 {:ok, _} = CommonAPI.delete(activity.id, other_user)
483 activity_id = activity.id
484 assert_receive {:text, event}
485 assert %{"event" => "delete", "payload" => ^activity_id} = Jason.decode!(event)
489 describe "thread_containment/2" do
490 test "it filters to user if recipients invalid and thread containment is enabled" do
491 clear_config([:instance, :skip_thread_containment], false)
492 author = insert(:user)
493 %{user: user, token: oauth_token} = oauth_access(["read"])
494 User.follow(user, author, :follow_accept)
497 insert(:note_activity,
501 data: %{"to" => ["TEST-FFF"]}
505 Streamer.get_topic_and_add_socket("public", user, oauth_token)
506 Streamer.stream("public", activity)
507 assert_receive {:render_with_user, _, _, ^activity}
508 assert Streamer.filtered_by_user?(user, activity)
511 test "it sends message if recipients invalid and thread containment is disabled" do
512 clear_config([:instance, :skip_thread_containment], true)
513 author = insert(:user)
514 %{user: user, token: oauth_token} = oauth_access(["read"])
515 User.follow(user, author, :follow_accept)
518 insert(:note_activity,
522 data: %{"to" => ["TEST-FFF"]}
526 Streamer.get_topic_and_add_socket("public", user, oauth_token)
527 Streamer.stream("public", activity)
529 assert_receive {:render_with_user, _, _, ^activity}
530 refute Streamer.filtered_by_user?(user, activity)
533 test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
534 clear_config([:instance, :skip_thread_containment], false)
535 author = insert(:user)
536 user = insert(:user, skip_thread_containment: true)
537 %{token: oauth_token} = oauth_access(["read"], user: user)
538 User.follow(user, author, :follow_accept)
541 insert(:note_activity,
545 data: %{"to" => ["TEST-FFF"]}
549 Streamer.get_topic_and_add_socket("public", user, oauth_token)
550 Streamer.stream("public", activity)
552 assert_receive {:render_with_user, _, _, ^activity}
553 refute Streamer.filtered_by_user?(user, activity)
558 setup do: oauth_access(["read"])
560 test "it filters messages involving blocked users", %{user: user, token: oauth_token} do
561 blocked_user = insert(:user)
562 {:ok, _user_relationship} = User.block(user, blocked_user)
564 Streamer.get_topic_and_add_socket("public", user, oauth_token)
565 {:ok, activity} = CommonAPI.post(blocked_user, %{status: "Test"})
566 assert_receive {:render_with_user, _, _, ^activity}
567 assert Streamer.filtered_by_user?(user, activity)
570 test "it filters messages transitively involving blocked users", %{
574 blockee = insert(:user)
575 friend = insert(:user)
577 Streamer.get_topic_and_add_socket("public", blocker, blocker_token)
579 {:ok, _user_relationship} = User.block(blocker, blockee)
581 {:ok, activity_one} = CommonAPI.post(friend, %{status: "hey! @#{blockee.nickname}"})
583 assert_receive {:render_with_user, _, _, ^activity_one}
584 assert Streamer.filtered_by_user?(blocker, activity_one)
586 {:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"})
588 assert_receive {:render_with_user, _, _, ^activity_two}
589 assert Streamer.filtered_by_user?(blocker, activity_two)
591 {:ok, activity_three} = CommonAPI.post(blockee, %{status: "hey! @#{blocker.nickname}"})
593 assert_receive {:render_with_user, _, _, ^activity_three}
594 assert Streamer.filtered_by_user?(blocker, activity_three)
599 setup do: oauth_access(["read"])
601 test "it doesn't send unwanted DMs to list", %{user: user_a, token: user_a_token} do
602 user_b = insert(:user)
603 user_c = insert(:user)
605 {:ok, user_a, user_b} = User.follow(user_a, user_b)
607 {:ok, list} = List.create("Test", user_a)
608 {:ok, list} = List.follow(list, user_b)
610 Streamer.get_topic_and_add_socket("list", user_a, user_a_token, %{"list" => list.id})
613 CommonAPI.post(user_b, %{
614 status: "@#{user_c.nickname} Test",
621 test "it doesn't send unwanted private posts to list", %{user: user_a, token: user_a_token} do
622 user_b = insert(:user)
624 {:ok, list} = List.create("Test", user_a)
625 {:ok, list} = List.follow(list, user_b)
627 Streamer.get_topic_and_add_socket("list", user_a, user_a_token, %{"list" => list.id})
630 CommonAPI.post(user_b, %{
632 visibility: "private"
638 test "it sends wanted private posts to list", %{user: user_a, token: user_a_token} do
639 user_b = insert(:user)
641 {:ok, user_a, user_b} = User.follow(user_a, user_b)
643 {:ok, list} = List.create("Test", user_a)
644 {:ok, list} = List.follow(list, user_b)
646 Streamer.get_topic_and_add_socket("list", user_a, user_a_token, %{"list" => list.id})
649 CommonAPI.post(user_b, %{
651 visibility: "private"
654 assert_receive {:render_with_user, _, _, ^activity}
655 refute Streamer.filtered_by_user?(user_a, activity)
659 describe "muted reblogs" do
660 setup do: oauth_access(["read"])
662 test "it filters muted reblogs", %{user: user1, token: user1_token} do
663 user2 = insert(:user)
664 user3 = insert(:user)
665 CommonAPI.follow(user1, user2)
666 CommonAPI.hide_reblogs(user1, user2)
668 {:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"})
670 Streamer.get_topic_and_add_socket("user", user1, user1_token)
671 {:ok, announce_activity} = CommonAPI.repeat(create_activity.id, user2)
672 assert_receive {:render_with_user, _, _, ^announce_activity}
673 assert Streamer.filtered_by_user?(user1, announce_activity)
676 test "it filters reblog notification for reblog-muted actors", %{
680 user2 = insert(:user)
681 CommonAPI.follow(user1, user2)
682 CommonAPI.hide_reblogs(user1, user2)
684 {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
685 Streamer.get_topic_and_add_socket("user", user1, user1_token)
686 {:ok, _announce_activity} = CommonAPI.repeat(create_activity.id, user2)
688 assert_receive {:render_with_user, _, "notification.json", notif}
689 assert Streamer.filtered_by_user?(user1, notif)
692 test "it send non-reblog notification for reblog-muted actors", %{
696 user2 = insert(:user)
697 CommonAPI.follow(user1, user2)
698 CommonAPI.hide_reblogs(user1, user2)
700 {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
701 Streamer.get_topic_and_add_socket("user", user1, user1_token)
702 {:ok, _favorite_activity} = CommonAPI.favorite(user2, create_activity.id)
704 assert_receive {:render_with_user, _, "notification.json", notif}
705 refute Streamer.filtered_by_user?(user1, notif)
709 describe "muted threads" do
710 test "it filters posts from muted threads" do
712 %{user: user2, token: user2_token} = oauth_access(["read"])
713 Streamer.get_topic_and_add_socket("user", user2, user2_token)
715 {:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
716 {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
717 {:ok, _} = CommonAPI.add_mute(user2, activity)
719 assert_receive {:render_with_user, _, _, ^activity}
720 assert Streamer.filtered_by_user?(user2, activity)
724 describe "direct streams" do
725 setup do: oauth_access(["read"])
727 test "it sends conversation update to the 'direct' stream", %{user: user, token: oauth_token} do
728 another_user = insert(:user)
730 Streamer.get_topic_and_add_socket("direct", user, oauth_token)
732 {:ok, _create_activity} =
733 CommonAPI.post(another_user, %{
734 status: "hey @#{user.nickname}",
738 assert_receive {:text, received_event}
740 assert %{"event" => "conversation", "payload" => received_payload} =
741 Jason.decode!(received_event)
743 assert %{"last_status" => last_status} = Jason.decode!(received_payload)
744 [participation] = Participation.for_user(user)
745 assert last_status["pleroma"]["direct_conversation_id"] == participation.id
748 test "it doesn't send conversation update to the 'direct' stream when the last message in the conversation is deleted",
749 %{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: "hi @#{user.nickname}",
760 create_activity_id = create_activity.id
761 assert_receive {:render_with_user, _, _, ^create_activity}
762 assert_receive {:text, received_conversation1}
763 assert %{"event" => "conversation", "payload" => _} = Jason.decode!(received_conversation1)
765 {:ok, _} = CommonAPI.delete(create_activity_id, another_user)
767 assert_receive {:text, received_event}
769 assert %{"event" => "delete", "payload" => ^create_activity_id} =
770 Jason.decode!(received_event)
776 test "it sends conversation update to the 'direct' stream when a message is deleted", %{
780 another_user = insert(:user)
781 Streamer.get_topic_and_add_socket("direct", user, oauth_token)
783 {:ok, create_activity} =
784 CommonAPI.post(another_user, %{
785 status: "hi @#{user.nickname}",
789 {:ok, create_activity2} =
790 CommonAPI.post(another_user, %{
791 status: "hi @#{user.nickname} 2",
792 in_reply_to_status_id: create_activity.id,
796 assert_receive {:render_with_user, _, _, ^create_activity}
797 assert_receive {:render_with_user, _, _, ^create_activity2}
798 assert_receive {:text, received_conversation1}
799 assert %{"event" => "conversation", "payload" => _} = Jason.decode!(received_conversation1)
800 assert_receive {:text, received_conversation1}
801 assert %{"event" => "conversation", "payload" => _} = Jason.decode!(received_conversation1)
803 {:ok, _} = CommonAPI.delete(create_activity2.id, another_user)
805 assert_receive {:text, received_event}
806 assert %{"event" => "delete", "payload" => _} = Jason.decode!(received_event)
808 assert_receive {:text, received_event}
810 assert %{"event" => "conversation", "payload" => received_payload} =
811 Jason.decode!(received_event)
813 assert %{"last_status" => last_status} = Jason.decode!(received_payload)
814 assert last_status["id"] == to_string(create_activity.id)