aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2017-09-10 11:51:01 +0200
committerRoger Braun <roger@rogerbraun.net>2017-09-10 11:51:01 +0200
commitfc10875895abd9add5a7834c4b5a64cc5b9401f8 (patch)
tree5a634eadc93187ddf47d074ac583057d2e62a931 /lib
parent96473dfac02d901e5b915ca56a34ce67b30c10d5 (diff)
downloadpleroma-fc10875895abd9add5a7834c4b5a64cc5b9401f8.tar.gz
Add attachments to mastoapi statuses.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 7b798506a..686ffd29d 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -24,6 +24,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || [])
favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || [])
+ attachments = render_many(object["attachment"] || [], StatusView, "attachment.json", as: :attachment)
+
%{
id: activity.id,
uri: object["id"],
@@ -42,11 +44,29 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
sensitive: sensitive,
spoiler_text: "",
visibility: "public",
- media_attachments: [], # fix
+ media_attachments: attachments,
mentions: mentions,
tags: [], # fix,
application: nil,
language: nil
}
end
+
+ def render("attachment.json", %{attachment: attachment}) do
+ [%{"mediaType" => media_type, "href" => href} | _] = attachment["url"]
+
+ type = cond do
+ String.contains?(media_type, "image") -> "image"
+ String.contains?(media_type, "video") -> "video"
+ true -> "unknown"
+ end
+
+ %{
+ id: attachment["uuid"],
+ url: href,
+ remote_url: href,
+ preview_url: href,
+ type: type
+ }
+ end
end