include local instance in bubble timeline (#117)
authorfloatingghost <hannah@coffee-and-dreams.uk>
Tue, 26 Jul 2022 12:22:49 +0000 (12:22 +0000)
committerfloatingghost <hannah@coffee-and-dreams.uk>
Tue, 26 Jul 2022 12:22:49 +0000 (12:22 +0000)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/117

lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex
test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs

index 6200263744bc468d010872c960e8d571a15b8414..b9978c05bb54b0d30b1f8a40672bf0ae19329b3d 100644 (file)
@@ -128,7 +128,11 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController 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)
index 7ef08f258aaf68e12e17331bf1a21c2d05855fdd..fe32a49554878601534e54d71dda7ce1b65c02d8 100644 (file)
@@ -997,18 +997,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
   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)
+      # 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)
@@ -1016,15 +1008,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest 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 +1019,8 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest 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