insert object defaults for fake activities and make credo happy
authorrinpatch <rinpatch@sdf.org>
Mon, 1 Apr 2019 09:16:51 +0000 (12:16 +0300)
committerrinpatch <rinpatch@sdf.org>
Mon, 1 Apr 2019 09:16:51 +0000 (12:16 +0300)
lib/pleroma/html.ex
lib/pleroma/web/activity_pub/utils.ex

index f19b42b42c470250f9be48b3b13358b7d74a4f33..1e48749a854b3795d2e7c2aba32b6fe790d6dd47 100644 (file)
@@ -49,7 +49,7 @@ defmodule Pleroma.HTML do
   def ensure_scrubbed_html(
         content,
         scrubbers,
-        _fake = false
+        false = _fake
       ) do
     {:commit, filter_tags(content, scrubbers)}
   end
@@ -57,7 +57,7 @@ defmodule Pleroma.HTML do
   def ensure_scrubbed_html(
         content,
         scrubbers,
-        _fake = true
+        true = _fake
       ) do
     {:ignore, filter_tags(content, scrubbers)}
   end
index 3959e9bd9db2ec8338f9409eb6198a2b6c6a11ab..feb73518eba118b444ed710417f4e5e0b4fe906f 100644 (file)
@@ -176,35 +176,45 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   also adds it to an included object
   """
   def lazy_put_activity_defaults(map, fake \\ false) do
-    unless fake do
-      %{data: %{"id" => context}, id: context_id} = create_context(map["context"])
+    map =
+      unless fake do
+        %{data: %{"id" => context}, id: context_id} = create_context(map["context"])
 
-      map =
         map
         |> Map.put_new_lazy("id", &generate_activity_id/0)
         |> Map.put_new_lazy("published", &make_date/0)
         |> Map.put_new("context", context)
         |> Map.put_new("context_id", context_id)
-
-      if is_map(map["object"]) do
-        object = lazy_put_object_defaults(map["object"], map)
-        %{map | "object" => object}
       else
         map
+        |> Map.put_new("id", "pleroma:fakeid")
+        |> Map.put_new_lazy("published", &make_date/0)
+        |> Map.put_new("context", "pleroma:fakecontext")
+        |> Map.put_new("context_id", -1)
       end
+
+    if is_map(map["object"]) do
+      object = lazy_put_object_defaults(map["object"], map, fake)
+      %{map | "object" => object}
     else
       map
-      |> Map.put_new("id", "pleroma:fakeid")
-      |> Map.put_new_lazy("published", &make_date/0)
-      |> Map.put_new("context", "pleroma:fakecontext")
-      |> Map.put_new("context_id", -1)
     end
   end
 
   @doc """
   Adds an id and published date if they aren't there.
   """
-  def lazy_put_object_defaults(map, activity \\ %{}) do
+  def lazy_put_object_defaults(map, activity \\ %{}, fake)
+
+  def lazy_put_object_defaults(map, activity, true = _fake) do
+    map
+    |> Map.put_new_lazy("published", &make_date/0)
+    |> Map.put_new("id", "pleroma:fakeid")
+    |> Map.put_new("context", activity["context"])
+    |> Map.put_new("context_id", activity["context_id"])
+  end
+
+  def lazy_put_object_defaults(map, activity, _fake) do
     map
     |> Map.put_new_lazy("id", &generate_object_id/0)
     |> Map.put_new_lazy("published", &make_date/0)