Extend Mastodon API with public endpoint for getting Favorites timeline of any user (#789)
This commit is contained in:
parent
10c40e13d2
commit
9dd36e5bcb
7 changed files with 294 additions and 3 deletions
|
|
@ -38,6 +38,7 @@ defmodule Pleroma.User.Info do
|
|||
field(:salmon, :string, default: nil)
|
||||
field(:hide_followers, :boolean, default: false)
|
||||
field(:hide_follows, :boolean, default: false)
|
||||
field(:hide_favorites, :boolean, default: true)
|
||||
field(:pinned_activities, {:array, :string}, default: [])
|
||||
field(:flavour, :string, default: nil)
|
||||
|
||||
|
|
@ -202,6 +203,7 @@ defmodule Pleroma.User.Info do
|
|||
:banner,
|
||||
:hide_follows,
|
||||
:hide_followers,
|
||||
:hide_favorites,
|
||||
:background,
|
||||
:show_role
|
||||
])
|
||||
|
|
|
|||
|
|
@ -1087,6 +1087,43 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||
|> render("index.json", %{activities: activities, for: user, as: :activity})
|
||||
end
|
||||
|
||||
def user_favourites(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params) do
|
||||
with %User{} = user <- User.get_by_id(id),
|
||||
false <- user.info.hide_favorites do
|
||||
params =
|
||||
params
|
||||
|> Map.put("type", "Create")
|
||||
|> Map.put("favorited_by", user.ap_id)
|
||||
|> Map.put("blocking_user", for_user)
|
||||
|
||||
recipients =
|
||||
if for_user do
|
||||
["https://www.w3.org/ns/activitystreams#Public"] ++
|
||||
[for_user.ap_id | for_user.following]
|
||||
else
|
||||
["https://www.w3.org/ns/activitystreams#Public"]
|
||||
end
|
||||
|
||||
activities =
|
||||
recipients
|
||||
|> ActivityPub.fetch_activities(params)
|
||||
|> Enum.reverse()
|
||||
|
||||
conn
|
||||
|> add_link_headers(:favourites, activities)
|
||||
|> put_view(StatusView)
|
||||
|> render("index.json", %{activities: activities, for: for_user, as: :activity})
|
||||
else
|
||||
nil ->
|
||||
{:error, :not_found}
|
||||
|
||||
true ->
|
||||
conn
|
||||
|> put_status(403)
|
||||
|> json(%{error: "Can't get favorites"})
|
||||
end
|
||||
end
|
||||
|
||||
def bookmarks(%{assigns: %{user: user}} = conn, _) do
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
|
|
|
|||
|
|
@ -395,6 +395,8 @@ defmodule Pleroma.Web.Router do
|
|||
get("/accounts/:id", MastodonAPIController, :user)
|
||||
|
||||
get("/search", MastodonAPIController, :search)
|
||||
|
||||
get("/pleroma/accounts/:id/favourites", MastodonAPIController, :user_favourites)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -632,7 +632,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
|
||||
defp build_info_cng(user, params) do
|
||||
info_params =
|
||||
["no_rich_text", "locked", "hide_followers", "hide_follows", "show_role"]
|
||||
["no_rich_text", "locked", "hide_followers", "hide_follows", "hide_favorites", "show_role"]
|
||||
|> Enum.reduce(%{}, fn key, res ->
|
||||
if value = params[key] do
|
||||
Map.put(res, key, value == "true")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue