Transmogrifier: Save correct ids for incoming deletes.
authorlain <lain@soykaf.club>
Thu, 10 Oct 2019 15:17:33 +0000 (17:17 +0200)
committerlain <lain@soykaf.club>
Thu, 10 Oct 2019 15:17:33 +0000 (17:17 +0200)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
test/web/activity_pub/transmogrifier_test.exs

index 9f29087df4438fa26f499c869158f12cedc327eb..3a0c382ca9f2b2ca9946436a7f4be26eee5da24b 100644 (file)
@@ -409,7 +409,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     end
   end
 
-  def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do
+  def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, options \\ []) do
+    local = Keyword.get(options, :local, true)
+    activity_id = Keyword.get(options, :activity_id, nil)
+
     user = User.get_cached_by_ap_id(actor)
     to = (object.data["to"] || []) ++ (object.data["cc"] || [])
 
@@ -420,7 +423,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
            "object" => id,
            "to" => to,
            "deleted_activity_id" => activity && activity.id
-         },
+         }
+         |> maybe_put("id", activity_id),
          {:ok, activity} <- insert(data, local, false),
          stream_out_participations(object, user),
          _ <- decrease_replies_count_if_reply(object),
index 872ed0eb225f757ca8e38c70100bed7ce818d399..620b54d3b92848ad76a84685afa957ef4bcb333b 100644 (file)
@@ -637,7 +637,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   # an error or a tombstone.  This would allow us to verify that a deletion actually took
   # place.
   def handle_incoming(
-        %{"type" => "Delete", "object" => object_id, "actor" => actor, "id" => _id} = data,
+        %{"type" => "Delete", "object" => object_id, "actor" => actor, "id" => id} = data,
         _options
       ) do
     object_id = Utils.get_ap_id(object_id)
@@ -646,7 +646,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
          {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
          {:ok, object} <- get_obj_helper(object_id),
          :ok <- Containment.contain_origin(actor.ap_id, object.data),
-         {:ok, activity} <- ActivityPub.delete(object, false) do
+         {:ok, activity} <- ActivityPub.delete(object, local: false, activity_id: id) do
       {:ok, activity}
     else
       nil ->
index 50c0bfb8428e1a29c807af1a417d77009ae6d5e7..4f9c4af339e09f9d6a2e1664c634bd69164bfd93 100644 (file)
@@ -696,8 +696,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
         |> Map.put("object", object)
         |> Map.put("actor", activity.data["actor"])
 
-      {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
+      {:ok, %Activity{local: false, data: %{"id" => id}}} = Transmogrifier.handle_incoming(data)
 
+      assert id == data["id"]
       refute Activity.get_by_id(activity.id)
     end