Don't render media meta if nil

This commit is contained in:
Alex Gleason 2021-05-12 16:16:10 -05:00
parent 4c060ae733
commit 02b9436494
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -9,6 +9,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.HTML alias Pleroma.HTML
alias Pleroma.Maps
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.User alias Pleroma.User
@ -406,6 +407,7 @@ def render("attachment.json", %{attachment: attachment}) do
media_type = attachment_url["mediaType"] || attachment_url["mimeType"] || "image" media_type = attachment_url["mediaType"] || attachment_url["mimeType"] || "image"
href = attachment_url["href"] |> MediaProxy.url() href = attachment_url["href"] |> MediaProxy.url()
href_preview = attachment_url["href"] |> MediaProxy.preview_url() href_preview = attachment_url["href"] |> MediaProxy.preview_url()
meta = render("attachment_meta.json", %{attachment: attachment})
type = type =
cond do cond do
@ -426,9 +428,9 @@ def render("attachment.json", %{attachment: attachment}) do
type: type, type: type,
description: attachment["name"], description: attachment["name"],
pleroma: %{mime_type: media_type}, pleroma: %{mime_type: media_type},
meta: render("attachment_meta.json", %{attachment: attachment}),
blurhash: attachment["blurhash"] blurhash: attachment["blurhash"]
} }
|> Maps.put_if_present(:meta, meta)
end end
def render("attachment_meta.json", %{ def render("attachment_meta.json", %{
@ -444,7 +446,7 @@ def render("attachment_meta.json", %{
} }
end end
def render("attachment_meta.json", _), do: %{} def render("attachment_meta.json", _), do: nil
def render("context.json", %{activity: activity, activities: activities, user: user}) do def render("context.json", %{activity: activity, activities: activities, user: user}) do
%{ancestors: ancestors, descendants: descendants} = %{ancestors: ancestors, descendants: descendants} =