transmogrifier: Use a cond, add proactive support for arrays
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Tue, 25 Sep 2018 15:12:29 +0000 (17:12 +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 8b0d65b6f51ffaa05edaeca927ffed8fa0fd9073..ed5df6f7bd773f267e4944cc35dae07587f17e36 100644 (file)
@@ -99,12 +99,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object)
       when not is_nil(in_reply_to) do
     in_reply_to_id =
-      if is_bitstring(in_reply_to) do
-        in_reply_to
-      else
-        if is_map(in_reply_to) && in_reply_to["id"] do
-          in_reply_to["id"]
-        end
+      cond do
+        is_bitstring(in_reply_to) -> in_reply_to
+        is_map(in_reply_to) && is_bitstring(in_reply_to["id"]) -> in_reply_to["id"]
+        is_list(in_reply_to) && is_bitstring(Enum.at(in_reply_to, 0)) -> Enum.at(in_reply_to, 0)
+        # Maybe I should output an error too?
+        true -> ""
       end
 
     case ActivityPub.fetch_object_from_id(in_reply_to_id) do