[Pleroma.Web.ActivityPub.Transmogrifier]: fix when attachment contain is just a Map [kroeg]

This commit is contained in:
Haelwenn (lanodan) Monnier 2018-09-21 12:57:31 +02:00
parent a4abb124ea
commit f8a0cb9c0b
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
1 changed files with 15 additions and 2 deletions

View File

@ -139,9 +139,9 @@ def fix_context(object) do
|> Map.put("conversation", context) |> Map.put("conversation", context)
end end
def fix_attachments(object) do def fix_attachments(%{"attachment" => attachment} = object) when is_list(attachment) do
attachments = attachments =
(object["attachment"] || []) attachment
|> Enum.map(fn data -> |> Enum.map(fn data ->
url = [%{"type" => "Link", "mediaType" => data["mediaType"], "href" => data["url"]}] url = [%{"type" => "Link", "mediaType" => data["mediaType"], "href" => data["url"]}]
Map.put(data, "url", url) Map.put(data, "url", url)
@ -151,6 +151,19 @@ def fix_attachments(object) do
|> Map.put("attachment", attachments) |> Map.put("attachment", attachments)
end end
def fix_attachments(%{"attachment" => attachment} = object) when is_map(attachment) do
attachment =
Map.put(attachment, "url", [
%{"type" => "Link", "mediaType" => attachment["mediaType"], "href" => attachment["url"]}
])
Map.put(object, "attachment", attachment)
end
def fix_attachments(object) do
object
end
def fix_emoji(object) do def fix_emoji(object) do
tags = object["tag"] || [] tags = object["tag"] || []
emoji = tags |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end) emoji = tags |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end)