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.MastodonAPI.TimelineControllerTest do
6 use Pleroma.Web.ConnCase
12 alias Pleroma.Web.CommonAPI
15 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
20 setup do: oauth_access(["read:statuses"])
22 test "does NOT embed account/pleroma/relationship in statuses", %{
26 other_user = insert(:user)
28 {:ok, _} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
32 |> assign(:user, user)
33 |> get("/api/v1/timelines/home")
34 |> json_response_and_validate_schema(200)
36 assert Enum.all?(response, fn n ->
37 get_in(n, ["account", "pleroma", "relationship"]) == %{}
41 test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
42 {:ok, public_activity} = CommonAPI.post(user, %{status: ".", visibility: "public"})
43 {:ok, direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
45 {:ok, unlisted_activity} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
47 {:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
49 conn = get(conn, "/api/v1/timelines/home?exclude_visibilities[]=direct")
51 assert status_ids = json_response_and_validate_schema(conn, :ok) |> Enum.map(& &1["id"])
52 assert public_activity.id in status_ids
53 assert unlisted_activity.id in status_ids
54 assert private_activity.id in status_ids
55 refute direct_activity.id in status_ids
58 test "muted emotions", %{user: user, conn: conn} do
59 other_user = insert(:user)
60 {:ok, activity} = CommonAPI.post(user, %{status: "."})
62 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
63 User.mute(user, other_user)
67 |> assign(:user, user)
68 |> get("/api/v1/timelines/home")
69 |> json_response_and_validate_schema(200)
74 "emoji_reactions" => []
81 |> assign(:user, user)
82 |> get("/api/v1/timelines/home?with_muted=true")
83 |> json_response_and_validate_schema(200)
88 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
94 test "filtering", %{conn: conn, user: user} do
95 local_user = insert(:user)
96 {:ok, user, local_user} = User.follow(user, local_user)
97 {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"})
98 with_media = create_with_media_activity(local_user)
100 remote_user = insert(:user, local: false)
101 {:ok, _user, remote_user} = User.follow(user, remote_user)
102 remote_activity = create_remote_activity(remote_user)
106 |> get("/api/v1/timelines/home")
107 |> json_response_and_validate_schema(200)
108 |> Enum.map(& &1["id"])
110 assert local_activity.id in without_filter_ids
111 assert remote_activity.id in without_filter_ids
112 assert with_media.id in without_filter_ids
116 |> get("/api/v1/timelines/home?local=true")
117 |> json_response_and_validate_schema(200)
118 |> Enum.map(& &1["id"])
120 assert local_activity.id in only_local_ids
121 refute remote_activity.id in only_local_ids
122 assert with_media.id in only_local_ids
124 only_local_media_ids =
126 |> get("/api/v1/timelines/home?local=true&only_media=true")
127 |> json_response_and_validate_schema(200)
128 |> Enum.map(& &1["id"])
130 refute local_activity.id in only_local_media_ids
131 refute remote_activity.id in only_local_media_ids
132 assert with_media.id in only_local_media_ids
136 |> get("/api/v1/timelines/home?remote=true")
137 |> json_response_and_validate_schema(200)
138 |> Enum.map(& &1["id"])
140 refute local_activity.id in remote_ids
141 assert remote_activity.id in remote_ids
142 refute with_media.id in remote_ids
145 |> get("/api/v1/timelines/home?remote=true&only_media=true")
146 |> json_response_and_validate_schema(200) == []
149 |> get("/api/v1/timelines/home?remote=true&local=true")
150 |> json_response_and_validate_schema(200) == []
155 @tag capture_log: true
156 test "the public timeline", %{conn: conn} do
159 {:ok, activity} = CommonAPI.post(user, %{status: "test"})
160 with_media = create_with_media_activity(user)
162 remote = insert(:note_activity, local: false)
165 |> get("/api/v1/timelines/public?local=False")
166 |> json_response_and_validate_schema(:ok)
171 |> get("/api/v1/timelines/public?local=True")
172 |> json_response_and_validate_schema(:ok)
173 |> Enum.map(& &1["id"])
175 assert activity.id in local_ids
176 assert with_media.id in local_ids
177 refute remote.id in local_ids
181 |> get("/api/v1/timelines/public?local=True")
182 |> json_response_and_validate_schema(:ok)
183 |> Enum.map(& &1["id"])
185 assert activity.id in local_ids
186 assert with_media.id in local_ids
187 refute remote.id in local_ids
191 |> get("/api/v1/timelines/public?local=True&only_media=true")
192 |> json_response_and_validate_schema(:ok)
193 |> Enum.map(& &1["id"])
195 refute activity.id in local_ids
196 assert with_media.id in local_ids
197 refute remote.id in local_ids
201 |> get("/api/v1/timelines/public?local=1")
202 |> json_response_and_validate_schema(:ok)
203 |> Enum.map(& &1["id"])
205 assert activity.id in local_ids
206 assert with_media.id in local_ids
207 refute remote.id in local_ids
209 remote_id = remote.id
211 assert [%{"id" => ^remote_id}] =
213 |> get("/api/v1/timelines/public?remote=true")
214 |> json_response_and_validate_schema(:ok)
216 with_media_id = with_media.id
218 assert [%{"id" => ^with_media_id}] =
220 |> get("/api/v1/timelines/public?only_media=true")
221 |> json_response_and_validate_schema(:ok)
224 |> get("/api/v1/timelines/public?remote=true&only_media=true")
225 |> json_response_and_validate_schema(:ok) == []
227 # does not contain repeats
228 {:ok, _} = CommonAPI.repeat(activity.id, user)
232 |> get("/api/v1/timelines/public?local=true")
233 |> json_response_and_validate_schema(:ok)
236 test "the public timeline includes only public statuses for an authenticated user" do
237 %{user: user, conn: conn} = oauth_access(["read:statuses"])
239 {:ok, _activity} = CommonAPI.post(user, %{status: "test"})
240 {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "private"})
241 {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "unlisted"})
242 {:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
244 res_conn = get(conn, "/api/v1/timelines/public")
245 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
248 test "doesn't return replies if follower is posting with blocked user" do
249 %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
250 [blockee, friend] = insert_list(2, :user)
251 {:ok, blocker, friend} = User.follow(blocker, friend)
252 {:ok, _} = User.block(blocker, blockee)
254 conn = assign(conn, :user, blocker)
256 {:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
258 {:ok, reply_from_blockee} =
259 CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
261 {:ok, _reply_from_friend} =
262 CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
264 # Still shows replies from yourself
265 {:ok, %{id: reply_from_me}} =
266 CommonAPI.post(blocker, %{status: "status", in_reply_to_status_id: reply_from_blockee})
269 get(conn, "/api/v1/timelines/public")
270 |> json_response_and_validate_schema(200)
272 assert length(response) == 2
273 [%{"id" => ^reply_from_me}, %{"id" => ^activity_id}] = response
276 test "doesn't return posts from users who blocked you when :blockers_visible is disabled" do
277 clear_config([:activitypub, :blockers_visible], false)
279 %{conn: conn, user: blockee} = oauth_access(["read:statuses"])
280 blocker = insert(:user)
281 {:ok, _} = User.block(blocker, blockee)
283 conn = assign(conn, :user, blockee)
285 {:ok, _} = CommonAPI.post(blocker, %{status: "hey!"})
288 get(conn, "/api/v1/timelines/public")
289 |> json_response_and_validate_schema(200)
291 assert length(response) == 0
294 test "doesn't return replies if follow is posting with users from blocked domain" do
295 %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
296 friend = insert(:user)
297 blockee = insert(:user, ap_id: "https://example.com/users/blocked")
298 {:ok, blocker, friend} = User.follow(blocker, friend)
299 {:ok, blocker} = User.block_domain(blocker, "example.com")
301 conn = assign(conn, :user, blocker)
303 {:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
305 {:ok, reply_from_blockee} =
306 CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
308 {:ok, _reply_from_friend} =
309 CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
311 res_conn = get(conn, "/api/v1/timelines/public")
313 activities = json_response_and_validate_schema(res_conn, 200)
314 [%{"id" => ^activity_id}] = activities
317 test "can be filtered by instance", %{conn: conn} do
318 user = insert(:user, ap_id: "https://lain.com/users/lain")
319 insert(:note_activity, local: false)
320 insert(:note_activity, local: false)
322 {:ok, _} = CommonAPI.post(user, %{status: "test"})
324 conn = get(conn, "/api/v1/timelines/public?instance=lain.com")
326 assert length(json_response_and_validate_schema(conn, :ok)) == 1
329 test "muted emotions", %{conn: conn} do
331 token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
335 |> assign(:user, user)
336 |> assign(:token, token)
338 other_user = insert(:user)
339 {:ok, activity} = CommonAPI.post(user, %{status: "."})
341 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
342 User.mute(user, other_user)
346 |> get("/api/v1/timelines/public")
347 |> json_response_and_validate_schema(200)
352 "emoji_reactions" => []
359 |> get("/api/v1/timelines/public?with_muted=true")
360 |> json_response_and_validate_schema(200)
365 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
371 test "should return local-only posts for authenticated users" do
373 %{user: _reader, conn: conn} = oauth_access(["read:statuses"])
375 {:ok, %{id: id}} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
379 |> get("/api/v1/timelines/public")
380 |> json_response_and_validate_schema(200)
382 assert [%{"id" => ^id}] = result
385 test "should not return local-only posts for users without read:statuses" do
387 %{user: _reader, conn: conn} = oauth_access([])
389 {:ok, _activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
393 |> get("/api/v1/timelines/public")
394 |> json_response_and_validate_schema(200)
399 test "should not return local-only posts for anonymous users" do
402 {:ok, _activity} = CommonAPI.post(user, %{status: "#2hu #2HU", visibility: "local"})
406 |> get("/api/v1/timelines/public")
407 |> json_response_and_validate_schema(200)
413 defp local_and_remote_activities do
414 insert(:note_activity)
415 insert(:note_activity, local: false)
419 describe "public with restrict unauthenticated timeline for local and federated timelines" do
420 setup do: local_and_remote_activities()
422 setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
424 setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
426 test "if user is unauthenticated", %{conn: conn} do
427 res_conn = get(conn, "/api/v1/timelines/public?local=true")
429 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
430 "error" => "authorization required for timeline view"
433 res_conn = get(conn, "/api/v1/timelines/public?local=false")
435 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
436 "error" => "authorization required for timeline view"
440 test "if user is authenticated" do
441 %{conn: conn} = oauth_access(["read:statuses"])
443 res_conn = get(conn, "/api/v1/timelines/public?local=true")
444 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
446 res_conn = get(conn, "/api/v1/timelines/public?local=false")
447 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
451 describe "public with restrict unauthenticated timeline for local" do
452 setup do: local_and_remote_activities()
454 setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
456 test "if user is unauthenticated", %{conn: conn} do
457 res_conn = get(conn, "/api/v1/timelines/public?local=true")
459 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
460 "error" => "authorization required for timeline view"
463 res_conn = get(conn, "/api/v1/timelines/public?local=false")
464 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
467 test "if user is authenticated", %{conn: _conn} do
468 %{conn: conn} = oauth_access(["read:statuses"])
470 res_conn = get(conn, "/api/v1/timelines/public?local=true")
471 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
473 res_conn = get(conn, "/api/v1/timelines/public?local=false")
474 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
478 describe "public with restrict unauthenticated timeline for remote" do
479 setup do: local_and_remote_activities()
481 setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
483 test "if user is unauthenticated", %{conn: conn} do
484 res_conn = get(conn, "/api/v1/timelines/public?local=true")
485 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
487 res_conn = get(conn, "/api/v1/timelines/public?local=false")
489 assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
490 "error" => "authorization required for timeline view"
494 test "if user is authenticated", %{conn: _conn} do
495 %{conn: conn} = oauth_access(["read:statuses"])
497 res_conn = get(conn, "/api/v1/timelines/public?local=true")
498 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
500 res_conn = get(conn, "/api/v1/timelines/public?local=false")
501 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
506 test "direct timeline", %{conn: conn} do
507 user_one = insert(:user)
508 user_two = insert(:user)
510 {:ok, user_two, user_one} = User.follow(user_two, user_one)
513 CommonAPI.post(user_one, %{
514 status: "Hi @#{user_two.nickname}!",
518 {:ok, _follower_only} =
519 CommonAPI.post(user_one, %{
520 status: "Hi @#{user_two.nickname}!",
521 visibility: "private"
526 |> assign(:user, user_two)
527 |> assign(:token, insert(:oauth_token, user: user_two, scopes: ["read:statuses"]))
529 # Only direct should be visible here
530 res_conn = get(conn_user_two, "api/v1/timelines/direct")
532 assert [status] = json_response_and_validate_schema(res_conn, :ok)
534 assert %{"visibility" => "direct"} = status
535 assert status["url"] != direct.data["id"]
537 # User should be able to see their own direct message
540 |> assign(:user, user_one)
541 |> assign(:token, insert(:oauth_token, user: user_one, scopes: ["read:statuses"]))
542 |> get("api/v1/timelines/direct")
544 [status] = json_response_and_validate_schema(res_conn, :ok)
546 assert %{"visibility" => "direct"} = status
548 # Both should be visible here
549 res_conn = get(conn_user_two, "api/v1/timelines/home")
551 [_s1, _s2] = json_response_and_validate_schema(res_conn, :ok)
554 Enum.each(1..20, fn _ ->
556 CommonAPI.post(user_one, %{
557 status: "Hi @#{user_two.nickname}!",
562 res_conn = get(conn_user_two, "api/v1/timelines/direct")
564 statuses = json_response_and_validate_schema(res_conn, :ok)
565 assert length(statuses) == 20
567 max_id = List.last(statuses)["id"]
569 res_conn = get(conn_user_two, "api/v1/timelines/direct?max_id=#{max_id}")
571 assert [status] = json_response_and_validate_schema(res_conn, :ok)
573 assert status["url"] != direct.data["id"]
576 test "doesn't include DMs from blocked users" do
577 %{user: blocker, conn: conn} = oauth_access(["read:statuses"])
578 blocked = insert(:user)
579 other_user = insert(:user)
580 {:ok, _user_relationship} = User.block(blocker, blocked)
582 {:ok, _blocked_direct} =
583 CommonAPI.post(blocked, %{
584 status: "Hi @#{blocker.nickname}!",
589 CommonAPI.post(other_user, %{
590 status: "Hi @#{blocker.nickname}!",
594 res_conn = get(conn, "api/v1/timelines/direct")
596 [status] = json_response_and_validate_schema(res_conn, :ok)
597 assert status["id"] == direct.id
602 setup do: oauth_access(["read:lists"])
604 test "does not contain retoots", %{user: user, conn: conn} do
605 other_user = insert(:user)
606 {:ok, activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
607 {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is stupid."})
608 {:ok, _} = CommonAPI.repeat(activity_one.id, other_user)
610 {:ok, list} = Pleroma.List.create("name", user)
611 {:ok, list} = Pleroma.List.follow(list, other_user)
613 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
615 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
617 assert id == to_string(activity_two.id)
620 test "works with pagination", %{user: user, conn: conn} do
621 other_user = insert(:user)
622 {:ok, list} = Pleroma.List.create("name", user)
623 {:ok, list} = Pleroma.List.follow(list, other_user)
625 Enum.each(1..30, fn i ->
626 CommonAPI.post(other_user, %{status: "post number #{i}"})
630 get(conn, "/api/v1/timelines/list/#{list.id}?limit=1")
631 |> json_response_and_validate_schema(:ok)
633 assert length(res) == 1
638 get(conn, "/api/v1/timelines/list/#{list.id}?max_id=#{first["id"]}&limit=30")
639 |> json_response_and_validate_schema(:ok)
641 assert length(res) == 29
644 test "list timeline", %{user: user, conn: conn} do
645 other_user = insert(:user)
646 {:ok, _activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
647 {:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
648 {:ok, list} = Pleroma.List.create("name", user)
649 {:ok, list} = Pleroma.List.follow(list, other_user)
651 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
653 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
655 assert id == to_string(activity_two.id)
658 test "list timeline does not leak non-public statuses for unfollowed users", %{
662 other_user = insert(:user)
663 {:ok, activity_one} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
665 {:ok, _activity_two} =
666 CommonAPI.post(other_user, %{
667 status: "Marisa is cute.",
668 visibility: "private"
671 {:ok, list} = Pleroma.List.create("name", user)
672 {:ok, list} = Pleroma.List.follow(list, other_user)
674 conn = get(conn, "/api/v1/timelines/list/#{list.id}")
676 assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
678 assert id == to_string(activity_one.id)
681 test "muted emotions", %{user: user, conn: conn} do
682 user2 = insert(:user)
683 user3 = insert(:user)
684 {:ok, activity} = CommonAPI.post(user2, %{status: "."})
686 {:ok, _} = CommonAPI.react_with_emoji(activity.id, user3, "🎅")
687 User.mute(user, user3)
689 {:ok, list} = Pleroma.List.create("name", user)
690 {:ok, list} = Pleroma.List.follow(list, user2)
694 |> get("/api/v1/timelines/list/#{list.id}")
695 |> json_response_and_validate_schema(200)
700 "emoji_reactions" => []
707 |> get("/api/v1/timelines/list/#{list.id}?with_muted=true")
708 |> json_response_and_validate_schema(200)
713 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
719 test "filtering", %{user: user, conn: conn} do
720 {:ok, list} = Pleroma.List.create("name", user)
722 local_user = insert(:user)
723 {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Marisa is stupid."})
724 with_media = create_with_media_activity(local_user)
725 {:ok, list} = Pleroma.List.follow(list, local_user)
727 remote_user = insert(:user, local: false)
728 remote_activity = create_remote_activity(remote_user)
729 {:ok, list} = Pleroma.List.follow(list, remote_user)
733 |> get("/api/v1/timelines/list/#{list.id}")
734 |> json_response_and_validate_schema(200)
735 |> Enum.map(& &1["id"])
737 assert local_activity.id in all_ids
738 assert with_media.id in all_ids
739 assert remote_activity.id in all_ids
743 |> get("/api/v1/timelines/list/#{list.id}?local=true")
744 |> json_response_and_validate_schema(200)
745 |> Enum.map(& &1["id"])
747 assert local_activity.id in only_local_ids
748 assert with_media.id in only_local_ids
749 refute remote_activity.id in only_local_ids
751 only_local_media_ids =
753 |> get("/api/v1/timelines/list/#{list.id}?local=true&only_media=true")
754 |> json_response_and_validate_schema(200)
755 |> Enum.map(& &1["id"])
757 refute local_activity.id in only_local_media_ids
758 assert with_media.id in only_local_media_ids
759 refute remote_activity.id in only_local_media_ids
763 |> get("/api/v1/timelines/list/#{list.id}?remote=true")
764 |> json_response_and_validate_schema(200)
765 |> Enum.map(& &1["id"])
767 refute local_activity.id in remote_ids
768 refute with_media.id in remote_ids
769 assert remote_activity.id in remote_ids
772 |> get("/api/v1/timelines/list/#{list.id}?remote=true&only_media=true")
773 |> json_response_and_validate_schema(200) == []
777 |> get("/api/v1/timelines/list/#{list.id}?only_media=true")
778 |> json_response_and_validate_schema(200)
779 |> Enum.map(& &1["id"])
781 refute local_activity.id in only_media_ids
782 assert with_media.id in only_media_ids
783 refute remote_activity.id in only_media_ids
786 |> get("/api/v1/timelines/list/#{list.id}?only_media=true&local=true&remote=true")
787 |> json_response_and_validate_schema(200) == []
791 describe "hashtag" do
792 setup do: oauth_access(["n/a"])
794 @tag capture_log: true
795 test "hashtag timeline", %{conn: conn} do
796 following = insert(:user)
798 {:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
799 with_media = create_with_media_activity(following)
801 remote = insert(:user, local: false)
802 remote_activity = create_remote_activity(remote)
806 |> get("/api/v1/timelines/tag/2hu")
807 |> json_response_and_validate_schema(:ok)
808 |> Enum.map(& &1["id"])
810 assert activity.id in all_ids
811 assert with_media.id in all_ids
812 assert remote_activity.id in all_ids
814 # works for different capitalization too
817 |> get("/api/v1/timelines/tag/2HU")
818 |> json_response_and_validate_schema(:ok)
819 |> Enum.map(& &1["id"])
821 assert activity.id in all_ids
822 assert with_media.id in all_ids
823 assert remote_activity.id in all_ids
827 |> get("/api/v1/timelines/tag/2hu?local=true")
828 |> json_response_and_validate_schema(:ok)
829 |> Enum.map(& &1["id"])
831 assert activity.id in local_ids
832 assert with_media.id in local_ids
833 refute remote_activity.id in local_ids
837 |> get("/api/v1/timelines/tag/2hu?remote=true")
838 |> json_response_and_validate_schema(:ok)
839 |> Enum.map(& &1["id"])
841 refute activity.id in remote_ids
842 refute with_media.id in remote_ids
843 assert remote_activity.id in remote_ids
847 |> get("/api/v1/timelines/tag/2hu?only_media=true")
848 |> json_response_and_validate_schema(:ok)
849 |> Enum.map(& &1["id"])
851 refute activity.id in media_ids
852 assert with_media.id in media_ids
853 refute remote_activity.id in media_ids
857 |> get("/api/v1/timelines/tag/2hu?only_media=true&local=true")
858 |> json_response_and_validate_schema(:ok)
859 |> Enum.map(& &1["id"])
861 refute activity.id in media_local_ids
862 assert with_media.id in media_local_ids
863 refute remote_activity.id in media_local_ids
867 |> get("/api/v1/timelines/tag/2hu?only_media=true&local=true&remote=true")
868 |> json_response_and_validate_schema(:ok)
869 |> Enum.map(& &1["id"])
871 refute activity.id in ids
872 refute with_media.id in ids
873 refute remote_activity.id in ids
876 |> get("/api/v1/timelines/tag/2hu?only_media=true&remote=true")
877 |> json_response_and_validate_schema(:ok) == []
880 test "multi-hashtag timeline", %{conn: conn} do
883 {:ok, activity_test} = CommonAPI.post(user, %{status: "#test"})
884 {:ok, activity_test1} = CommonAPI.post(user, %{status: "#test #test1"})
885 {:ok, activity_none} = CommonAPI.post(user, %{status: "#test #none"})
887 any_test = get(conn, "/api/v1/timelines/tag/test?any[]=test1")
889 [status_none, status_test1, status_test] = json_response_and_validate_schema(any_test, :ok)
891 assert to_string(activity_test.id) == status_test["id"]
892 assert to_string(activity_test1.id) == status_test1["id"]
893 assert to_string(activity_none.id) == status_none["id"]
895 restricted_test = get(conn, "/api/v1/timelines/tag/test?all[]=test1&none[]=none")
897 assert [status_test1] == json_response_and_validate_schema(restricted_test, :ok)
899 all_test = get(conn, "/api/v1/timelines/tag/test?all[]=none")
901 assert [status_none] == json_response_and_validate_schema(all_test, :ok)
904 test "muted emotions", %{conn: conn} do
906 token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
910 |> assign(:user, user)
911 |> assign(:token, token)
913 other_user = insert(:user)
914 {:ok, activity} = CommonAPI.post(user, %{status: "test #2hu"})
916 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
917 User.mute(user, other_user)
921 |> get("/api/v1/timelines/tag/2hu")
922 |> json_response_and_validate_schema(200)
927 "emoji_reactions" => []
934 |> get("/api/v1/timelines/tag/2hu?with_muted=true")
935 |> json_response_and_validate_schema(200)
940 "emoji_reactions" => [%{"count" => 1, "me" => false, "name" => "🎅"}]
947 describe "hashtag timeline handling of :restrict_unauthenticated setting" do
950 {:ok, activity1} = CommonAPI.post(user, %{status: "test #tag1"})
951 {:ok, _activity2} = CommonAPI.post(user, %{status: "test #tag1"})
954 |> Ecto.Changeset.change(%{local: false})
955 |> Pleroma.Repo.update()
957 base_uri = "/api/v1/timelines/tag/tag1"
958 error_response = %{"error" => "authorization required for timeline view"}
960 %{base_uri: base_uri, error_response: error_response}
963 defp ensure_authenticated_access(base_uri) do
964 %{conn: auth_conn} = oauth_access(["read:statuses"])
966 res_conn = get(auth_conn, "#{base_uri}?local=true")
967 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
969 res_conn = get(auth_conn, "#{base_uri}?local=false")
970 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
973 test "with default settings on private instances, returns 403 for unauthenticated users", %{
976 error_response: error_response
978 clear_config([:instance, :public], false)
979 clear_config([:restrict_unauthenticated, :timelines])
981 for local <- [true, false] do
982 res_conn = get(conn, "#{base_uri}?local=#{local}")
984 assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
987 ensure_authenticated_access(base_uri)
990 test "with `%{local: true, federated: true}`, returns 403 for unauthenticated users", %{
993 error_response: error_response
995 clear_config([:restrict_unauthenticated, :timelines, :local], true)
996 clear_config([:restrict_unauthenticated, :timelines, :federated], true)
998 for local <- [true, false] do
999 res_conn = get(conn, "#{base_uri}?local=#{local}")
1001 assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
1004 ensure_authenticated_access(base_uri)
1007 test "with `%{local: false, federated: true}`, forbids unauthenticated access to federated timeline",
1008 %{conn: conn, base_uri: base_uri, error_response: error_response} do
1009 clear_config([:restrict_unauthenticated, :timelines, :local], false)
1010 clear_config([:restrict_unauthenticated, :timelines, :federated], true)
1012 res_conn = get(conn, "#{base_uri}?local=true")
1013 assert length(json_response_and_validate_schema(res_conn, 200)) == 1
1015 res_conn = get(conn, "#{base_uri}?local=false")
1016 assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
1018 ensure_authenticated_access(base_uri)
1021 test "with `%{local: true, federated: false}`, forbids unauthenticated access to public timeline",
1022 %{conn: conn, base_uri: base_uri, error_response: error_response} do
1023 # (but not to local public activities which are delivered as part of federated timeline)
1024 clear_config([:restrict_unauthenticated, :timelines, :local], true)
1025 clear_config([:restrict_unauthenticated, :timelines, :federated], false)
1027 res_conn = get(conn, "#{base_uri}?local=true")
1028 assert json_response_and_validate_schema(res_conn, :unauthorized) == error_response
1030 # Note: local activities get delivered as part of federated timeline
1031 res_conn = get(conn, "#{base_uri}?local=false")
1032 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
1034 ensure_authenticated_access(base_uri)
1038 describe "bubble" do
1039 setup do: oauth_access(["read:statuses"])
1041 test "filtering", %{conn: conn, user: user} do
1042 clear_config([:instance, :local_bubble], [])
1043 # our endpoint host has a port in it so let's set the AP ID
1044 local_user = insert(:user, %{ap_id: "https://localhost/users/user"})
1045 remote_user = insert(:user, %{ap_id: "https://example.com/users/remote_user"})
1046 {:ok, user, local_user} = User.follow(user, local_user)
1047 {:ok, _user, remote_user} = User.follow(user, remote_user)
1049 {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"})
1050 remote_activity = create_remote_activity(remote_user)
1052 # If nothing, only include ours
1053 clear_config([:instance, :local_bubble], [])
1057 |> get("/api/v1/timelines/bubble")
1058 |> json_response_and_validate_schema(200)
1059 |> Enum.map(& &1["id"])
1061 assert local_activity.id in one_instance
1063 # If we have others, also include theirs
1064 clear_config([:instance, :local_bubble], ["example.com"])
1068 |> get("/api/v1/timelines/bubble")
1069 |> json_response_and_validate_schema(200)
1070 |> Enum.map(& &1["id"])
1072 assert local_activity.id in two_instances
1073 assert remote_activity.id in two_instances
1077 defp create_remote_activity(user) do
1082 "https://www.w3.org/ns/activitystreams#Public",
1083 User.ap_followers(user)
1089 insert(:note_activity, %{
1092 "https://www.w3.org/ns/activitystreams#Public",
1093 User.ap_followers(user)
1100 defp create_with_media_activity(user) do
1101 obj = insert(:attachment_note, user: user)
1103 insert(:note_activity, %{
1105 recipients: ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(user)],