Ignore duplicate create activities.
This commit is contained in:
parent
ffa2f57c36
commit
297a2c7d3f
|
@ -25,7 +25,7 @@ def object(conn, %{"uuid" => uuid}) do
|
||||||
# TODO: Ensure that this inbox is a recipient of the message
|
# TODO: Ensure that this inbox is a recipient of the message
|
||||||
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
|
def inbox(%{assigns: %{valid_signature: true}} = conn, params) do
|
||||||
# File.write("/tmp/incoming.json", Poison.encode!(params))
|
# 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"]),
|
with {:ok, _user} <- ap_enabled_actor(params["actor"]),
|
||||||
nil <- Activity.get_by_ap_id(params["id"]),
|
nil <- Activity.get_by_ap_id(params["id"]),
|
||||||
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
||||||
|
|
|
@ -37,7 +37,8 @@ def fix_attachments(object) do
|
||||||
# - tags
|
# - tags
|
||||||
# - emoji
|
# - emoji
|
||||||
def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = object} = data) do
|
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"])
|
object = fix_object(data["object"])
|
||||||
params = %{
|
params = %{
|
||||||
to: data["to"],
|
to: data["to"],
|
||||||
|
@ -54,6 +55,7 @@ def handle_incoming(%{"type" => "Create", "object" => %{"type" => "Note"} = obje
|
||||||
|
|
||||||
ActivityPub.create(params)
|
ActivityPub.create(params)
|
||||||
else
|
else
|
||||||
|
%Activity{} = activity -> {:ok, activity}
|
||||||
_e -> :error
|
_e -> :error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
describe "handle_incoming" do
|
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
|
test "it works for incoming notices" do
|
||||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!
|
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue