diff options
author | rinpatch <rinpatch@sdf.org> | 2020-09-25 12:44:33 +0000 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2020-09-25 12:44:33 +0000 |
commit | f67c967c4a614262a6409f94ad74754b09dc0e64 (patch) | |
tree | 8b1ac691b03797d19fc3c7baa6b8f14b350abee2 | |
parent | c788593f7ffbf87a1fd8032f7b481bfd12091d83 (diff) | |
parent | 5e86a2809e37100b54e0fc88db79245e13f684aa (diff) | |
download | pleroma-f67c967c4a614262a6409f94ad74754b09dc0e64.tar.gz |
Merge branch 'features/incoming-create-exists' into 'develop'
transmogrifier: Drop incoming create early if it already exists
See merge request pleroma/pleroma!3026
-rw-r--r-- | lib/pleroma/web/activity_pub/transmogrifier.ex | 6 | ||||
-rw-r--r-- | test/web/activity_pub/transmogrifier/question_handling_test.exs | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index aa6a69463..d7dd9fe6b 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -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 diff --git a/test/web/activity_pub/transmogrifier/question_handling_test.exs b/test/web/activity_pub/transmogrifier/question_handling_test.exs index 74ee79543..d2822ce75 100644 --- a/test/web/activity_pub/transmogrifier/question_handling_test.exs +++ b/test/web/activity_pub/transmogrifier/question_handling_test.exs @@ -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 |