Pleroma.Web.ActivityPub.Transmogrifier: fix_url when not a string/empty
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Thu, 1 Nov 2018 08:56:37 +0000 (09:56 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Thu, 1 Nov 2018 08:56:37 +0000 (09:56 +0100)
Thanks prismo.news, I hate it

lib/pleroma/web/activity_pub/transmogrifier.ex

index cbc800ad65c94b52e6b65b4064f97bf5e7524bfb..56918342cd438b59bae703bdf35e1a1c8faf760b 100644 (file)
@@ -57,6 +57,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     object
     |> fix_actor
     |> fix_attachments
+    |> fix_url
     |> fix_context
     |> fix_in_reply_to
     |> fix_emoji
@@ -171,6 +172,27 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
 
   def fix_attachments(object), do: object
 
+  def fix_url(%{"url" => url} = object) when is_map(url) do
+    object
+    |> Map.put("url", url["href"])
+  end
+
+  def fix_url(%{"url" => url} = object) when is_list(url) do
+    first_element = Enum.at(url, 0)
+
+    url_string =
+      cond do
+        is_bitstring(first_element) -> first_element
+        is_map(first_element) -> first_element["href"] || ""
+        true -> ""
+      end
+
+    object
+    |> Map.put("url", url_string)
+  end
+
+  def fix_url(object), do: object
+
   def fix_emoji(%{"tag" => tags} = object) when is_list(tags) do
     emoji = tags |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end)