transmogrifier: Drop incoming create early if it already exists
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Wed, 23 Sep 2020 09:45:32 +0000 (11:45 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Wed, 23 Sep 2020 11:40:45 +0000 (13:40 +0200)
lib/pleroma/web/activity_pub/transmogrifier.ex
test/web/activity_pub/transmogrifier/question_handling_test.exs

index aa6a694639be8bd5f4dd276ddc6f2e855c7ba433..d7dd9fe6becf8ddab8088e8845a64fc34f2e1c9c 100644 (file)
@@ -515,15 +515,19 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   end
 
   def handle_incoming(
-        %{"type" => "Create", "object" => %{"type" => objtype}} = data,
+        %{"type" => "Create", "object" => %{"type" => objtype, "id" => obj_id}} = data,
         _options
       )
       when objtype in ~w{Question Answer ChatMessage Audio Video Event Article} do
     data = Map.put(data, "object", strip_internal_fields(data["object"]))
 
     with {:ok, %User{}} <- ObjectValidator.fetch_actor(data),
+         nil <- Activity.get_create_by_object_ap_id(obj_id),
          {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
       {:ok, activity}
+    else
+      %Activity{} = activity -> {:ok, activity}
+      e -> e
     end
   end
 
index 74ee7954382592231a5471467336e05878f2c345..d2822ce75b3e9155f5381ca498b64f732e261607 100644 (file)
@@ -157,12 +157,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
            }
   end
 
-  test "returns an error if received a second time" do
+  test "returns same activity if received a second time" do
     data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
 
     assert {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
 
-    assert {:error, {:validate_object, {:error, _}}} = Transmogrifier.handle_incoming(data)
+    assert {:ok, ^activity} = Transmogrifier.handle_incoming(data)
   end
 
   test "accepts a Question with no content" do