Ignore duplicate create activities.
authorlain <lain@soykaf.club>
Mon, 19 Feb 2018 16:37:45 +0000 (17:37 +0100)
committerlain <lain@soykaf.club>
Mon, 19 Feb 2018 16:37:45 +0000 (17:37 +0100)
lib/pleroma/web/activity_pub/activity_pub_controller.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
test/web/activity_pub/transmogrifier_test.exs

index 1a6d7ec7af925a83db0c57208234eca6ffbf88df..835e8bd9de586cb206a115a9cdc9751d48d99c69 100644 (file)
@@ -25,7 +25,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
   # TODO: Ensure that this inbox is a recipient of the message
   def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
     # File.write("/tmp/incoming.json", Poison.encode!(params))
-    Logger.info(Poison.encode!(params, [pretty: 2]))
+    Logger.info(Poison.encode!(params, [pretty: 2]))
     with {:ok, _user} <- ap_enabled_actor(params["actor"]),
          nil <- Activity.get_by_ap_id(params["id"]),
          {:ok, activity} <- Transmogrifier.handle_incoming(params) do
index 075250aa5e8f8d2517dcd2ac5e02992e58572da7..e53957fbf5f5bbb2cee9fc8cbe3ff9c50013a9e8 100644 (file)
@@ -37,7 +37,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   # - tags
   # - emoji
   def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
-    with %User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
+    with nil <- Activity.get_create_activity_by_object_ap_id(object["id"]),
+         %User{} = user <- User.get_or_fetch_by_ap_id(data["actor"]) do
       object = fix_object(data["object"])
       params = %{
         to: data["to"],
@@ -54,6 +55,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
 
       ActivityPub.create(params)
     else
+      %Activity{} = activity -> {:ok, activity}
       _e -> :error
     end
   end
index 45e284157c7321c138c67ce814ea36e75b538d7f..11c6bbe1c57f7781cee03cffe2f1df45baca735f 100644 (file)
@@ -10,6 +10,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
   alias Pleroma.Web.CommonAPI
 
   describe "handle_incoming" do
+    test "it ignores an incoming notice if we already have it" do
+      activity = insert(:note_activity)
+
+      data = File.read!("test/fixtures/mastodon-post-activity.json")
+      |> Poison.decode!
+      |> Map.put("object", activity.data["object"])
+
+      {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
+
+      assert activity == returned_activity
+    end
+
     test "it works for incoming notices" do
       data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!