[#2456] Added support for embed_relationships param, nailed down endpoints which should support it. Fixed :source_mutes relationships subset fetching.
This commit is contained in:
parent
b960a9430d
commit
63a1a82f38
7 changed files with 99 additions and 13 deletions
|
|
@ -103,4 +103,9 @@ defmodule Pleroma.Web.ControllerHelper do
|
|||
def put_if_exist(map, _key, nil), do: map
|
||||
|
||||
def put_if_exist(map, key, value), do: Map.put(map, key, value)
|
||||
|
||||
def embed_relationships?(params) do
|
||||
# To do: change to `truthy_param?(params["embed_relationships"])` once PleromaFE supports it
|
||||
not explicitly_falsy_param?(params["embed_relationships"])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||
add_link_headers: 2,
|
||||
truthy_param?: 1,
|
||||
assign_account_by_id: 2,
|
||||
embed_relationships?: 1,
|
||||
json_response: 3
|
||||
]
|
||||
|
||||
|
|
@ -269,7 +270,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||
|
||||
conn
|
||||
|> add_link_headers(followers)
|
||||
|> render("index.json", for: for_user, users: followers, as: :user)
|
||||
# https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223
|
||||
|> render("index.json",
|
||||
for: for_user,
|
||||
users: followers,
|
||||
as: :user,
|
||||
embed_relationships: embed_relationships?(params)
|
||||
)
|
||||
end
|
||||
|
||||
@doc "GET /api/v1/accounts/:id/following"
|
||||
|
|
@ -288,7 +295,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||
|
||||
conn
|
||||
|> add_link_headers(followers)
|
||||
|> render("index.json", for: for_user, users: followers, as: :user)
|
||||
# https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223
|
||||
|> render("index.json",
|
||||
for: for_user,
|
||||
users: followers,
|
||||
as: :user,
|
||||
embed_relationships: embed_relationships?(params)
|
||||
)
|
||||
end
|
||||
|
||||
@doc "GET /api/v1/accounts/:id/lists"
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
|||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web
|
||||
alias Pleroma.Web.ControllerHelper
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.MastodonAPI.StatusView
|
||||
|
||||
|
|
@ -32,7 +33,13 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
|||
|
||||
conn
|
||||
|> put_view(AccountView)
|
||||
|> render("index.json", users: accounts, for: user, as: :user)
|
||||
# https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223
|
||||
|> render("index.json",
|
||||
users: accounts,
|
||||
for: user,
|
||||
as: :user,
|
||||
embed_relationships: ControllerHelper.embed_relationships?(params)
|
||||
)
|
||||
end
|
||||
|
||||
def search2(conn, params), do: do_search(:v2, conn, params)
|
||||
|
|
@ -75,6 +82,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
|||
offset: params[:offset],
|
||||
type: params[:type],
|
||||
author: get_author(params),
|
||||
embed_relationships: ControllerHelper.embed_relationships?(params),
|
||||
for_user: user
|
||||
]
|
||||
|> Enum.filter(&elem(&1, 1))
|
||||
|
|
@ -86,7 +94,9 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
|
|||
AccountView.render("index.json",
|
||||
users: accounts,
|
||||
for: options[:for_user],
|
||||
as: :user
|
||||
as: :user,
|
||||
# https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223
|
||||
embed_relationships: options[:embed_relationships]
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,22 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
def render("index.json", %{users: users} = opts) do
|
||||
reading_user = opts[:for]
|
||||
|
||||
relationships_opt =
|
||||
cond do
|
||||
Map.has_key?(opts, :relationships) ->
|
||||
opts[:relationships]
|
||||
|
||||
is_nil(reading_user) || !opts[:embed_relationships] ->
|
||||
UserRelationship.view_relationships_option(nil, [])
|
||||
|
||||
true ->
|
||||
UserRelationship.view_relationships_option(reading_user, users)
|
||||
end
|
||||
|
||||
opts = Map.put(opts, :relationships, relationships_opt)
|
||||
|
||||
users
|
||||
|> render_many(AccountView, "show.json", opts)
|
||||
|> Enum.filter(&Enum.any?/1)
|
||||
|
|
@ -175,6 +191,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
}
|
||||
end)
|
||||
|
||||
relationship =
|
||||
if opts[:embed_relationships] do
|
||||
render("relationship.json", %{
|
||||
user: opts[:for],
|
||||
target: user,
|
||||
relationships: opts[:relationships]
|
||||
})
|
||||
else
|
||||
%{}
|
||||
end
|
||||
|
||||
%{
|
||||
id: to_string(user.id),
|
||||
username: username_from_nickname(user.nickname),
|
||||
|
|
@ -213,7 +240,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
|||
hide_followers: user.hide_followers,
|
||||
hide_follows: user.hide_follows,
|
||||
hide_favorites: user.hide_favorites,
|
||||
relationship: %{},
|
||||
relationship: relationship,
|
||||
skip_thread_containment: user.skip_thread_containment,
|
||||
background_image: image_url(user.background) |> MediaProxy.url()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
|
|||
|> Enum.filter(& &1)
|
||||
|> Kernel.++(move_activities_targets)
|
||||
|
||||
UserRelationship.view_relationships_option(reading_user, actors, source_mutes_only: true)
|
||||
UserRelationship.view_relationships_option(reading_user, actors, subset: :source_mutes)
|
||||
end
|
||||
|
||||
opts =
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||
|> Enum.map(&get_user(&1.data["actor"], false))
|
||||
|> Enum.filter(& &1)
|
||||
|
||||
UserRelationship.view_relationships_option(reading_user, actors, source_mutes_only: true)
|
||||
UserRelationship.view_relationships_option(reading_user, actors, subset: :source_mutes)
|
||||
end
|
||||
|
||||
opts =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue