v2 Suggestions: rudimentary API response
This commit is contained in:
parent
7e1caddc58
commit
b17360cd7c
8 changed files with 103 additions and 5 deletions
|
|
@ -149,6 +149,7 @@ defmodule Pleroma.User do
|
|||
field(:last_active_at, :naive_datetime)
|
||||
field(:disclose_client, :boolean, default: true)
|
||||
field(:pinned_objects, :map, default: %{})
|
||||
field(:is_suggested, :boolean, default: false)
|
||||
|
||||
embeds_one(
|
||||
:notification_settings,
|
||||
|
|
|
|||
|
|
@ -167,6 +167,10 @@ defmodule Pleroma.User.Query do
|
|||
where(query, [u], u.is_confirmed == false)
|
||||
end
|
||||
|
||||
defp compose_query({:is_suggested, bool}, query) do
|
||||
where(query, [u], u.is_suggested == ^bool)
|
||||
end
|
||||
|
||||
defp compose_query({:followers, %User{id: id}}, query) do
|
||||
query
|
||||
|> where([u], u.id != ^id)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
28
lib/pleroma/web/mastodon_api/views/suggestion_view.ex
Normal file
28
lib/pleroma/web/mastodon_api/views/suggestion_view.ex
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.SuggestionView do
|
||||
use Pleroma.Web, :view
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
||||
@source_types [:staff, :global, :past_interactions]
|
||||
|
||||
def render("index.json", %{users: users} = opts) do
|
||||
Enum.map(users, fn user ->
|
||||
opts =
|
||||
opts
|
||||
|> Map.put(:user, user)
|
||||
|> Map.delete(:users)
|
||||
|
||||
render("show.json", opts)
|
||||
end)
|
||||
end
|
||||
|
||||
def render("show.json", %{source: source, user: _user} = opts) when source in @source_types do
|
||||
%{
|
||||
source: source,
|
||||
account: AccountView.render("show.json", opts)
|
||||
}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue