Render peertube videos in mastodon.
authorlain <lain@soykaf.club>
Sun, 25 Mar 2018 15:07:40 +0000 (17:07 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Tue, 21 Aug 2018 16:24:10 +0000 (18:24 +0200)
lib/pleroma/web/mastodon_api/views/status_view.ex

index 5dbd59dd9476692f433f4dbe178258753518905e..9625da822d23a464a03cf13a8cb239b277eb61af 100644 (file)
@@ -99,8 +99,9 @@ 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)
+    attachment_data = object["attachment"] || []
+    attachment_data = attachment_data ++ if object["type"] == "Video", do: [object], else: []
+    attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment)
 
     created_at = Utils.to_masto_date(object["published"])
 
@@ -151,7 +152,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
   end
 
   def render("attachment.json", %{attachment: attachment}) do
-    [%{"mediaType" => media_type, "href" => href} | _] = attachment["url"]
+    [attachment | _] = attachment["url"]
+    media_type = attachment["mediaType"] || attachment["mimeType"]
+    href = attachment["href"]
 
     type =
       cond do