Fix activity deletion
authorEgor Kislitsyn <egor@kislitsyn.com>
Tue, 24 Mar 2020 13:38:18 +0000 (17:38 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Tue, 24 Mar 2020 13:38:18 +0000 (17:38 +0400)
lib/pleroma/web/activity_pub/activity_pub.ex
test/web/activity_pub/activity_pub_test.exs

index 30e2828404a9b522997715f644e83e76e1261491..9742319251f6412b8da6dfdfb89edd5116308f7a 100644 (file)
@@ -583,6 +583,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     end
   end
 
+  defp do_delete(%Object{data: %{"type" => "Tombstone", "id" => ap_id}}, _) do
+    activity =
+      ap_id
+      |> Activity.Queries.by_object_id()
+      |> Activity.Queries.by_type("Delete")
+      |> Repo.one()
+
+    {:ok, activity}
+  end
+
   @spec block(User.t(), User.t(), String.t() | nil, boolean()) ::
           {:ok, Activity.t()} | {:error, any()}
   def block(blocker, blocked, activity_id \\ nil, local \\ true) do
index a43dd34f01fa79ddb0889f05eb8d40243e9cfe58..049b14498ec6bd69c40e50160451bc96b9aaf249 100644 (file)
@@ -1425,6 +1425,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       assert Repo.get(Object, object.id).data["type"] == "Tombstone"
     end
 
+    test "it doesn't fail when an activity was already deleted" do
+      {:ok, delete} = insert(:note_activity) |> Object.normalize() |> ActivityPub.delete()
+
+      assert {:ok, ^delete} = delete |> Object.normalize() |> ActivityPub.delete()
+    end
+
     test "decrements user note count only for public activities" do
       user = insert(:user, note_count: 10)