Verified Commit 5e86a280 authored by Haelwenn's avatar Haelwenn
Browse files

transmogrifier: Drop incoming create early if it already exists

parent 02f12ec6
Pipeline #31333 passed with stages
in 17 minutes and 34 seconds
......@@ -515,15 +515,19 @@ def handle_incoming(
def handle_incoming(
%{"type" => "Create", "object" => %{"type" => objtype}} = data,
%{"type" => "Create", "object" => %{"type" => objtype, "id" => obj_id}} = data,
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}
%Activity{} = activity -> {:ok, activity}
e -> e
......@@ -157,12 +157,12 @@ test "Mastodon Question activity with custom emojis" do
test "returns an error if received a second time" do
test "returns same activity if received a second time" do
data =!("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)
test "accepts a Question with no content" do
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment