v2 Suggestions: rudimentary API response
[akkoma] / lib / pleroma / web / mastodon_api / controllers / suggestion_controller.ex
index b941849f55a07f29d7258696a2b3499b4a2a559f..a34da98df183c0bbbda0be18a4258f1e84d62563 100644 (file)
@@ -4,6 +4,7 @@
 
 defmodule Pleroma.Web.MastodonAPI.SuggestionController do
   use Pleroma.Web, :controller
+  alias Pleroma.User
 
   require Logger
 
@@ -29,7 +30,7 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionController do
   def index2_operation do
     %OpenApiSpex.Operation{
       tags: ["Suggestions"],
-      summary: "Follow suggestions (Not implemented)",
+      summary: "Follow suggestions",
       operationId: "SuggestionController.index2",
       responses: %{
         200 => Pleroma.Web.ApiSpec.Helpers.empty_array_response()
@@ -42,6 +43,14 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionController do
     do: Pleroma.Web.MastodonAPI.MastodonAPIController.empty_array(conn, params)
 
   @doc "GET /api/v2/suggestions"
-  def index2(conn, params),
-    do: Pleroma.Web.MastodonAPI.MastodonAPIController.empty_array(conn, params)
+  def index2(conn, params) do
+    limit = Map.get(params, :limit, 40) |> min(80)
+
+    users =
+      %{is_suggested: true, limit: limit}
+      |> User.Query.build()
+      |> Pleroma.Repo.all()
+
+    render(conn, "index.json", %{users: users, source: :staff, skip_visibility_check: true})
+  end
 end