Merge branch 'ap-improvements' into 'master'

ActivityPub bug fixes

Closes #889

See merge request framasoft/mobilizon!1094
This commit is contained in:
Thomas Citharel 2021-11-04 08:36:38 +00:00
commit f6aaf493c0
10 changed files with 49 additions and 12 deletions

View File

@ -28,6 +28,19 @@ defmodule Mobilizon.Federation.ActivityPub.Publisher do
Relay.publish(activity) Relay.publish(activity)
end end
recipients =
if public && Config.get([:instance, :allow_relay]) do
followers_url = Relay.get_actor().followers_url
Logger.debug(
"Public activity, so adding relay followers URL to recipients: #{inspect(followers_url)}"
)
recipients ++ [followers_url]
else
recipients
end
recipients = Enum.uniq(recipients) recipients = Enum.uniq(recipients)
{recipients, followers} = convert_followers_in_recipients(recipients) {recipients, followers} = convert_followers_in_recipients(recipients)

View File

@ -92,7 +92,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Actors do
activity_data = %{ activity_data = %{
"type" => "Delete", "type" => "Delete",
"actor" => actor_url, "actor" => actor_url,
"object" => Convertible.model_to_as(target_actor), "object" => %{
"type" => "Tombstone",
"id" => target_actor_url
},
"id" => target_actor_url <> "/delete", "id" => target_actor_url <> "/delete",
"to" => to, "to" => to,
"cc" => cc "cc" => cc

View File

@ -82,7 +82,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Comments do
activity_data = %{ activity_data = %{
"type" => "Delete", "type" => "Delete",
"actor" => actor.url, "actor" => actor.url,
"object" => Convertible.model_to_as(comment), "object" => %{
"type" => "Tombstone",
"id" => url
},
"id" => url <> "/delete", "id" => url <> "/delete",
"to" => ["https://www.w3.org/ns/activitystreams#Public"] "to" => ["https://www.w3.org/ns/activitystreams#Public"]
} }

View File

@ -115,7 +115,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Discussions do
activity_data = %{ activity_data = %{
"type" => "Delete", "type" => "Delete",
"actor" => actor.url, "actor" => actor.url,
"object" => Convertible.model_to_as(discussion), "object" => %{
"type" => "Tombstone",
"url" => url
},
"id" => url <> "/delete", "id" => url <> "/delete",
"to" => [group.members_url] "to" => [group.members_url]
} }

View File

@ -73,7 +73,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
activity_data = %{ activity_data = %{
"type" => "Delete", "type" => "Delete",
"actor" => actor.url, "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"], "to" => [actor.url <> "/followers", "https://www.w3.org/ns/activitystreams#Public"],
"id" => url <> "/delete" "id" => url <> "/delete"
} }

View File

@ -77,7 +77,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Posts do
activity_data = %{ activity_data = %{
"actor" => actor_url, "actor" => actor_url,
"type" => "Delete", "type" => "Delete",
"object" => Convertible.model_to_as(post), "object" => %{
"type" => "Tombstone",
"id" => url
},
"id" => url <> "/delete", "id" => url <> "/delete",
"to" => [group_url, @public_ap, members_url] "to" => [group_url, @public_ap, members_url]
} }

View File

@ -161,7 +161,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Resources do
"actor" => actor_url, "actor" => actor_url,
"attributedTo" => [group_url], "attributedTo" => [group_url],
"type" => "Delete", "type" => "Delete",
"object" => Convertible.model_to_as(resource), "object" => %{
"type" => "Tombstone",
"id" => url
},
"id" => url <> "/delete", "id" => url <> "/delete",
"to" => [members_url] "to" => [members_url]
} }

View File

@ -55,7 +55,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.TodoLists do
activity_data = %{ activity_data = %{
"actor" => actor_url, "actor" => actor_url,
"type" => "Delete", "type" => "Delete",
"object" => Convertible.model_to_as(todo_list), "object" => %{
"type" => "Tombstone",
"id" => url
},
"id" => url <> "/delete", "id" => url <> "/delete",
"to" => [group_url] "to" => [group_url]
} }

View File

@ -95,7 +95,10 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Todos do
activity_data = %{ activity_data = %{
"actor" => actor_url, "actor" => actor_url,
"type" => "Delete", "type" => "Delete",
"object" => Convertible.model_to_as(url), "object" => %{
"type" => "Tombstone",
"id" => url
},
"id" => "#{url}/delete", "id" => "#{url}/delete",
"to" => [group_url] "to" => [group_url]
} }

View File

@ -121,7 +121,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
assert delete.data["type"] == "Delete" assert delete.data["type"] == "Delete"
assert delete.data["actor"] == event.organizer_actor.url 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.data["object"]["id"] == event.url
assert Events.get_event_by_url(event.url) == nil 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["type"] == "Delete"
assert delete.data["actor"] == event.organizer_actor.url 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.data["object"]["id"] == event.url
assert delete.local == false assert delete.local == false
@ -155,7 +155,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
assert delete.data["type"] == "Delete" assert delete.data["type"] == "Delete"
assert delete.data["actor"] == comment.actor.url 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 assert delete.data["object"]["id"] == comment.url
refute is_nil(Discussions.get_comment_from_url(comment.url).deleted_at) 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.local
assert update_data.data["type"] == "Delete" 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["object"]["id"] == url
assert update_data.data["to"] == [group.members_url] assert update_data.data["to"] == [group.members_url]
assert update_data.data["actor"] == actor.url assert update_data.data["actor"] == actor.url