Add /api/v1/followed_tags
[akkoma] / lib / pleroma / web / mastodon_api / controllers / tag_controller.ex
index b8995eb00c8f8ae866701ca8850dc10bd75ec01b..ca5ee48ac151ab82470b8d01cb1c17952d9d9a31 100644 (file)
@@ -4,9 +4,24 @@ defmodule Pleroma.Web.MastodonAPI.TagController do
 
   alias Pleroma.User
   alias Pleroma.Hashtag
+  alias Pleroma.Pagination
+
+  import Pleroma.Web.ControllerHelper,
+    only: [
+      add_link_headers: 2
+    ]
 
   plug(Pleroma.Web.ApiSpec.CastAndValidate)
-  plug(Pleroma.Web.Plugs.OAuthScopesPlug, %{scopes: ["read"]} when action in [:show])
+
+  plug(
+    Pleroma.Web.Plugs.OAuthScopesPlug,
+    %{scopes: ["read"]} when action in [:show]
+  )
+
+  plug(
+    Pleroma.Web.Plugs.OAuthScopesPlug,
+    %{scopes: ["read:follows"]} when action in [:show_followed]
+  )
 
   plug(
     Pleroma.Web.Plugs.OAuthScopesPlug,
@@ -44,4 +59,19 @@ defmodule Pleroma.Web.MastodonAPI.TagController do
       _ -> render_error(conn, :not_found, "Hashtag not found")
     end
   end
+
+  def show_followed(conn, params) do
+    with %{assigns: %{user: %User{} = user}} <- conn do
+      params = Map.put(params, :id_type, :integer)
+
+      hashtags =
+        user
+        |> User.HashtagFollow.followed_hashtags_query()
+        |> Pagination.fetch_paginated(params)
+
+      conn
+      |> add_link_headers(hashtags)
+      |> render("index.json", tags: hashtags, for_user: user)
+    end
+  end
 end