Merge branch 'fix/activity-deletion' into 'develop'
authorfeld <feld@feld.me>
Tue, 24 Mar 2020 19:10:32 +0000 (19:10 +0000)
committerrinpatch <rinpatch@sdf.org>
Tue, 31 Mar 2020 10:40:28 +0000 (13:40 +0300)
Fix activity deletion

Closes #1640

See merge request pleroma/pleroma!2328

lib/pleroma/web/activity_pub/activity_pub.ex
test/web/activity_pub/activity_pub_test.exs

index 60e74758f5f953c424a0f4e9c00bec9c404b6d9f..eaaaba775bcc7b5c05d02da24b10840cd49f6d4c 100644 (file)
@@ -584,6 +584,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 3dd3dd04dcd878959cbba77e38b9398d5cc3ce12..433859dab87eab70cc09df56d5f2e1ae2f40eee4 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)