From d2b1b4d6c818edf4881deae4c8cf202f6841e9f9 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Tue, 26 Jul 2022 12:37:22 +0100 Subject: [PATCH 1/2] include local instance in bubble timeline --- .../controllers/timeline_controller.ex | 6 ++++- .../controllers/timeline_controller_test.exs | 23 ++++--------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex index 620026374..216700e07 100644 --- a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex @@ -128,7 +128,11 @@ def public(%{assigns: %{user: user}} = conn, params) do # GET /api/v1/timelines/bubble def bubble(%{assigns: %{user: user}} = conn, params) do - bubble_instances = Config.get([:instance, :local_bubble], []) + bubble_instances = + Enum.uniq([ + Config.get([:instance, :local_bubble], []) ++ + [Pleroma.Web.Endpoint.host()] + ]) if is_nil(user) do fail_on_bad_auth(conn) diff --git a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs index 7ef08f258..5a3274401 100644 --- a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs @@ -997,15 +997,6 @@ test "with `%{local: true, federated: false}`, forbids unauthenticated access to describe "bubble" do setup do: oauth_access(["read:statuses"]) - test "it returns nothing if no bubble is configured", %{user: user, conn: conn} do - clear_config([:instance, :local_bubble], []) - {:ok, _} = CommonAPI.post(user, %{status: ".", visibility: "public"}) - - conn = get(conn, "/api/v1/timelines/bubble") - - assert [] = json_response_and_validate_schema(conn, :ok) - end - test "filtering", %{conn: conn, user: user} do clear_config([:instance, :local_bubble], []) local_user = insert(:user) @@ -1016,15 +1007,8 @@ test "filtering", %{conn: conn, user: user} do {:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"}) remote_activity = create_remote_activity(remote_user) - resp = - conn - |> get("/api/v1/timelines/bubble") - |> json_response_and_validate_schema(200) - |> Enum.map(& &1["id"]) - - assert Enum.empty?(resp) - - clear_config([:instance, :local_bubble], ["localhost:4001"]) + # If nothing, only include ours + clear_config([:instance, :local_bubble], []) one_instance = conn @@ -1034,7 +1018,8 @@ test "filtering", %{conn: conn, user: user} do assert local_activity.id in one_instance - clear_config([:instance, :local_bubble], ["localhost:4001", "example.com"]) + # If we have others, also include theirs + clear_config([:instance, :local_bubble], ["example.com"]) two_instances = conn -- 2.43.0 From a948a57162fb83ae2b83c0aeac0135a0d20a6cce Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Tue, 26 Jul 2022 12:53:05 +0100 Subject: [PATCH 2/2] fix tests --- .../web/mastodon_api/controllers/timeline_controller.ex | 4 ++-- .../web/mastodon_api/controllers/timeline_controller_test.exs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex index 216700e07..b9978c05b 100644 --- a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex @@ -129,10 +129,10 @@ def public(%{assigns: %{user: user}} = conn, params) do # GET /api/v1/timelines/bubble def bubble(%{assigns: %{user: user}} = conn, params) do bubble_instances = - Enum.uniq([ + Enum.uniq( Config.get([:instance, :local_bubble], []) ++ [Pleroma.Web.Endpoint.host()] - ]) + ) if is_nil(user) do fail_on_bad_auth(conn) diff --git a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs index 5a3274401..fe32a4955 100644 --- a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs @@ -999,7 +999,8 @@ test "with `%{local: true, federated: false}`, forbids unauthenticated access to test "filtering", %{conn: conn, user: user} do clear_config([:instance, :local_bubble], []) - local_user = insert(:user) + # our endpoint host has a port in it so let's set the AP ID + local_user = insert(:user, %{ap_id: "https://localhost/users/user"}) remote_user = insert(:user, %{ap_id: "https://example.com/users/remote_user"}) {:ok, user, local_user} = User.follow(user, local_user) {:ok, _user, remote_user} = User.follow(user, remote_user) -- 2.43.0