[Pleroma.Web.ActivityPub.Transmogrifier]: fix when attachment contain is just a Map...
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Fri, 21 Sep 2018 10:57:31 +0000 (12:57 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Thu, 27 Sep 2018 18:00:46 +0000 (20:00 +0200)
lib/pleroma/web/activity_pub/transmogrifier.ex

index 3af3efbb3779d91b2a1dcbf226ee5e22433e566d..8677bc2083ce341528debf334d3af0c44f47e919 100644 (file)
@@ -139,9 +139,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     |> Map.put("conversation", context)
   end
 
-  def fix_attachments(object) do
+  def fix_attachments(%{"attachment" => attachment} = object) when is_list(attachment) do
     attachments =
-      (object["attachment"] || [])
+      attachment
       |> Enum.map(fn data ->
         url = [%{"type" => "Link", "mediaType" => data["mediaType"], "href" => data["url"]}]
         Map.put(data, "url", url)
@@ -151,6 +151,19 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     |> Map.put("attachment", attachments)
   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
     tags = object["tag"] || []
     emoji = tags |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end)