Apply suggestion to lib/pleroma/web/activity_pub/transmogrifier.ex
authorlain <lain@soykaf.club>
Tue, 31 Mar 2020 17:28:18 +0000 (17:28 +0000)
committerlain <lain@soykaf.club>
Tue, 31 Mar 2020 17:28:18 +0000 (17:28 +0000)
lib/pleroma/web/activity_pub/transmogrifier.ex

index f82142979dc561f2ef2b66488ecaa1787f26e67b..a18ece6e748c1d7e58dbf5c90a7ca351bf9215ec 100644 (file)
@@ -1267,24 +1267,19 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     {:error, :no_context}
   end
 
-  defp maybe_add_recipients_from_object(%{"object" => object} = data) do
-    to = data["to"] || []
-    cc = data["cc"] || []
+  defp maybe_add_recipients_from_object(%{"to" => [_ | _], "cc" => [_ | _]} = data), do: {:ok, data}
 
-    if to == [] && cc == [] do
-      if object = Object.normalize(object) do
+  defp maybe_add_recipients_from_object(%{"object" => object} = data) do
+    case Object.normalize(object) do
+      %{data: {"actor" => actor}} -> 
         data =
           data
-          |> Map.put("to", [object.data["actor"]])
-          |> Map.put("cc", cc)
+          |> Map.put("to", [actor])
+          |> Map.put("cc", data["cc"] || [])
 
         {:ok, data}
-      else
-        {:error, "No actor on referenced object"}
-      end
-    else
-      {:ok, data}
-    end
+      nil -> {:error, :no_object}
+      _ -> {:error, :no_actor}
   end
 
   defp maybe_add_recipients_from_object(_) do