From 75fbcb985c432936cff7a6965ea8c961e0636873 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 3 Nov 2021 17:45:32 +0100 Subject: [PATCH] Only send Tombstone with Delete activity, not the object itself Signed-off-by: Thomas Citharel --- lib/federation/activity_pub/types/actors.ex | 5 ++++- lib/federation/activity_pub/types/comments.ex | 5 ++++- lib/federation/activity_pub/types/discussions.ex | 5 ++++- lib/federation/activity_pub/types/events.ex | 5 ++++- lib/federation/activity_pub/types/posts.ex | 5 ++++- lib/federation/activity_pub/types/resources.ex | 5 ++++- lib/federation/activity_pub/types/todo_lists.ex | 5 ++++- lib/federation/activity_pub/types/todos.ex | 5 ++++- test/federation/activity_pub/activity_pub_test.exs | 8 ++++---- 9 files changed, 36 insertions(+), 12 deletions(-) diff --git a/lib/federation/activity_pub/types/actors.ex b/lib/federation/activity_pub/types/actors.ex index 0ea7cb06f..253e9f159 100644 --- a/lib/federation/activity_pub/types/actors.ex +++ b/lib/federation/activity_pub/types/actors.ex @@ -92,7 +92,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Actors do activity_data = %{ "type" => "Delete", "actor" => actor_url, - "object" => Convertible.model_to_as(target_actor), + "object" => %{ + "type" => "Tombstone", + "id" => target_actor_url + }, "id" => target_actor_url <> "/delete", "to" => to, "cc" => cc diff --git a/lib/federation/activity_pub/types/comments.ex b/lib/federation/activity_pub/types/comments.ex index c8794b9a3..e510a537f 100644 --- a/lib/federation/activity_pub/types/comments.ex +++ b/lib/federation/activity_pub/types/comments.ex @@ -82,7 +82,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Comments do activity_data = %{ "type" => "Delete", "actor" => actor.url, - "object" => Convertible.model_to_as(comment), + "object" => %{ + "type" => "Tombstone", + "id" => url + }, "id" => url <> "/delete", "to" => ["https://www.w3.org/ns/activitystreams#Public"] } diff --git a/lib/federation/activity_pub/types/discussions.ex b/lib/federation/activity_pub/types/discussions.ex index ec82e0937..2644fb7ef 100644 --- a/lib/federation/activity_pub/types/discussions.ex +++ b/lib/federation/activity_pub/types/discussions.ex @@ -115,7 +115,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Discussions do activity_data = %{ "type" => "Delete", "actor" => actor.url, - "object" => Convertible.model_to_as(discussion), + "object" => %{ + "type" => "Tombstone", + "url" => url + }, "id" => url <> "/delete", "to" => [group.members_url] } diff --git a/lib/federation/activity_pub/types/events.ex b/lib/federation/activity_pub/types/events.ex index 0fdd3f32d..a23139fe3 100644 --- a/lib/federation/activity_pub/types/events.ex +++ b/lib/federation/activity_pub/types/events.ex @@ -73,7 +73,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do activity_data = %{ "type" => "Delete", "actor" => actor.url, - "object" => Convertible.model_to_as(event), + "object" => %{ + "type" => "Tombstone", + "id" => url + }, "to" => [actor.url <> "/followers", "https://www.w3.org/ns/activitystreams#Public"], "id" => url <> "/delete" } diff --git a/lib/federation/activity_pub/types/posts.ex b/lib/federation/activity_pub/types/posts.ex index 1bca51fee..ed7642fbd 100644 --- a/lib/federation/activity_pub/types/posts.ex +++ b/lib/federation/activity_pub/types/posts.ex @@ -77,7 +77,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Posts do activity_data = %{ "actor" => actor_url, "type" => "Delete", - "object" => Convertible.model_to_as(post), + "object" => %{ + "type" => "Tombstone", + "id" => url + }, "id" => url <> "/delete", "to" => [group_url, @public_ap, members_url] } diff --git a/lib/federation/activity_pub/types/resources.ex b/lib/federation/activity_pub/types/resources.ex index 9d5438b78..a6d965922 100644 --- a/lib/federation/activity_pub/types/resources.ex +++ b/lib/federation/activity_pub/types/resources.ex @@ -161,7 +161,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Resources do "actor" => actor_url, "attributedTo" => [group_url], "type" => "Delete", - "object" => Convertible.model_to_as(resource), + "object" => %{ + "type" => "Tombstone", + "id" => url + }, "id" => url <> "/delete", "to" => [members_url] } diff --git a/lib/federation/activity_pub/types/todo_lists.ex b/lib/federation/activity_pub/types/todo_lists.ex index fc2fa1bdc..c0b288afa 100644 --- a/lib/federation/activity_pub/types/todo_lists.ex +++ b/lib/federation/activity_pub/types/todo_lists.ex @@ -55,7 +55,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.TodoLists do activity_data = %{ "actor" => actor_url, "type" => "Delete", - "object" => Convertible.model_to_as(todo_list), + "object" => %{ + "type" => "Tombstone", + "id" => url + }, "id" => url <> "/delete", "to" => [group_url] } diff --git a/lib/federation/activity_pub/types/todos.ex b/lib/federation/activity_pub/types/todos.ex index 771b64863..0e97835e1 100644 --- a/lib/federation/activity_pub/types/todos.ex +++ b/lib/federation/activity_pub/types/todos.ex @@ -95,7 +95,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Todos do activity_data = %{ "actor" => actor_url, "type" => "Delete", - "object" => Convertible.model_to_as(url), + "object" => %{ + "type" => "Tombstone", + "id" => url + }, "id" => "#{url}/delete", "to" => [group_url] } diff --git a/test/federation/activity_pub/activity_pub_test.exs b/test/federation/activity_pub/activity_pub_test.exs index 59e6986d5..e5344ecee 100644 --- a/test/federation/activity_pub/activity_pub_test.exs +++ b/test/federation/activity_pub/activity_pub_test.exs @@ -121,7 +121,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do assert delete.data["type"] == "Delete" assert delete.data["actor"] == event.organizer_actor.url - assert delete.data["object"]["type"] == "Event" + assert delete.data["object"]["type"] == "Tombstone" assert delete.data["object"]["id"] == event.url assert Events.get_event_by_url(event.url) == nil @@ -137,7 +137,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do assert delete.data["type"] == "Delete" assert delete.data["actor"] == event.organizer_actor.url - assert delete.data["object"]["type"] == "Event" + assert delete.data["object"]["type"] == "Tombstone" assert delete.data["object"]["id"] == event.url assert delete.local == false @@ -155,7 +155,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do assert delete.data["type"] == "Delete" assert delete.data["actor"] == comment.actor.url - assert delete.data["object"]["type"] == "Note" + assert delete.data["object"]["type"] == "Tombstone" assert delete.data["object"]["id"] == comment.url refute is_nil(Discussions.get_comment_from_url(comment.url).deleted_at) @@ -486,7 +486,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do assert update_data.local assert update_data.data["type"] == "Delete" - assert update_data.data["object"]["type"] == "Document" + assert update_data.data["object"]["type"] == "Tombstone" assert update_data.data["object"]["id"] == url assert update_data.data["to"] == [group.members_url] assert update_data.data["actor"] == actor.url