Add a fake option to lazy_put_actvity_defaults
authorrinpatch <rinpatch@sdf.org>
Sat, 30 Mar 2019 10:57:54 +0000 (13:57 +0300)
committerrinpatch <rinpatch@sdf.org>
Sat, 30 Mar 2019 10:57:54 +0000 (13:57 +0300)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/utils.ex

index b459fd8827a8db3b2b69b91d7bc19adc1b8623a5..a94040d01a3384977d83c69b824f1f77897e63ca 100644 (file)
@@ -115,7 +115,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   def insert(map, local \\ true, fake \\ false) when is_map(map) do
     with nil <- Activity.normalize(map),
-         map <- lazy_put_activity_defaults(map),
+         map <- lazy_put_activity_defaults(map, fake),
          :ok <- check_actor_is_active(map["actor"]),
          {_, true} <- {:remote_limit_error, check_remote_limit(map)},
          {:ok, map} <- MRF.filter(map),
index 2e9ffe41c40f5b2fa33049d94f7544cd450af5a0..3959e9bd9db2ec8338f9409eb6198a2b6c6a11ab 100644 (file)
@@ -175,21 +175,29 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   Adds an id and a published data if they aren't there,
   also adds it to an included object
   """
-  def lazy_put_activity_defaults(map) 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}
+  def lazy_put_activity_defaults(map, fake \\ false) do
+    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
+      end
     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