add bubble timeline (#100)
[akkoma] / lib / pleroma / web / mastodon_api / controllers / timeline_controller.ex
index 10c27989338af0dd3a6e2d5e3e5ac8d8fe373407..6200263744bc468d010872c960e8d571a15b8414 100644 (file)
@@ -26,8 +26,9 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
   plug(RateLimiter, [name: :timeline, bucket_name: :home_timeline] when action == :home)
   plug(RateLimiter, [name: :timeline, bucket_name: :hashtag_timeline] when action == :hashtag)
   plug(RateLimiter, [name: :timeline, bucket_name: :list_timeline] when action == :list)
+  plug(RateLimiter, [name: :timeline, bucket_name: :bubble_timeline] when action == :bubble)
 
-  plug(OAuthScopesPlug, %{scopes: ["read:statuses"]} when action in [:home, :direct])
+  plug(OAuthScopesPlug, %{scopes: ["read:statuses"]} when action in [:home, :direct, :bubble])
   plug(OAuthScopesPlug, %{scopes: ["read:lists"]} when action == :list)
 
   plug(
@@ -125,6 +126,33 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
     end
   end
 
+  # GET /api/v1/timelines/bubble
+  def bubble(%{assigns: %{user: user}} = conn, params) do
+    bubble_instances = Config.get([:instance, :local_bubble], [])
+
+    if is_nil(user) do
+      fail_on_bad_auth(conn)
+    else
+      activities =
+        params
+        |> Map.put(:type, ["Create"])
+        |> Map.put(:blocking_user, user)
+        |> Map.put(:muting_user, user)
+        |> Map.put(:reply_filtering_user, user)
+        |> Map.put(:instance, bubble_instances)
+        |> ActivityPub.fetch_public_activities()
+
+      conn
+      |> add_link_headers(activities)
+      |> render("index.json",
+        activities: activities,
+        for: user,
+        as: :activity,
+        with_muted: Map.get(params, :with_muted, false)
+      )
+    end
+  end
+
   defp fail_on_bad_auth(conn) do
     render_error(conn, :unauthorized, "authorization required for timeline view")
   end