aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2019-01-21 00:53:41 +0100
committerWilliam Pitcock <nenolod@dereferenced.org>2019-01-26 14:18:23 +0000
commit39863236ebba227d8e742680b739d18d2d211fb0 (patch)
treeb2a6cff3fc0e4a0b6b5b1958b19151893ba5cc7b /lib
parent3f64379b1382f2e26cacd28da230c67bf68656a0 (diff)
downloadpleroma-39863236ebba227d8e742680b739d18d2d211fb0.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 86607e7af..9d3fa532d 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -1329,22 +1329,23 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> Enum.at(0)
end
- def status_card(conn, %{"id" => status_id}) do
+ def get_status_card(status_id) do
with %Activity{} = activity <- Repo.get(Activity, status_id),
true <- ActivityPub.is_public?(activity),
page_url <- status_first_external_url(activity.data["object"]["content"]),
{:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do
- card =
- rich_media
- |> Map.take([:image, :title, :url, :description])
- |> Map.put(:type, "link")
-
- json(conn, card)
+ rich_media
+ |> Map.take([:image, :title, :url, :description])
+ |> Map.put(:type, "link")
else
- _ -> json(conn, %{})
+ _ -> %{}
end
end
+ def status_card(conn, %{"id" => status_id}) do
+ json(conn, get_status_card(status_id))
+ end
+
def try_render(conn, target, params)
when is_binary(target) do
res = render(conn, target, params)