forked from AkkomaGang/akkoma
Web.MastodonAPI.MastodonAPIController: generic get_status_card/1 function for MastoAPI 2.6.x
Mastodon API 2.6.x added a card key to the Status object so the Card can be shown in the timeline without an extra request at each status.
This commit is contained in:
parent
3f64379b13
commit
39863236eb
1 changed files with 9 additions and 8 deletions
|
@ -1329,22 +1329,23 @@ defp status_first_external_url(content) do
|
||||||
|> Enum.at(0)
|
|> Enum.at(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_card(conn, %{"id" => status_id}) do
|
def get_status_card(status_id) do
|
||||||
with %Activity{} = activity <- Repo.get(Activity, status_id),
|
with %Activity{} = activity <- Repo.get(Activity, status_id),
|
||||||
true <- ActivityPub.is_public?(activity),
|
true <- ActivityPub.is_public?(activity),
|
||||||
page_url <- status_first_external_url(activity.data["object"]["content"]),
|
page_url <- status_first_external_url(activity.data["object"]["content"]),
|
||||||
{:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do
|
{:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do
|
||||||
card =
|
rich_media
|
||||||
rich_media
|
|> Map.take([:image, :title, :url, :description])
|
||||||
|> Map.take([:image, :title, :url, :description])
|
|> Map.put(:type, "link")
|
||||||
|> Map.put(:type, "link")
|
|
||||||
|
|
||||||
json(conn, card)
|
|
||||||
else
|
else
|
||||||
_ -> json(conn, %{})
|
_ -> %{}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def status_card(conn, %{"id" => status_id}) do
|
||||||
|
json(conn, get_status_card(status_id))
|
||||||
|
end
|
||||||
|
|
||||||
def try_render(conn, target, params)
|
def try_render(conn, target, params)
|
||||||
when is_binary(target) do
|
when is_binary(target) do
|
||||||
res = render(conn, target, params)
|
res = render(conn, target, params)
|
||||||
|
|
Loading…
Reference in a new issue