Fix events & posts not being sent to group followers

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-02-04 12:28:53 +01:00
parent 0db39af37e
commit 177341b491
6 changed files with 89 additions and 48 deletions

View File

@@ -94,18 +94,13 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
to =
if event.visibility == :public,
do: ["https://www.w3.org/ns/activitystreams#Public"],
else: [event.organizer_actor.followers_url]
else: [attributed_to_or_default(event).followers_url]
%{
"type" => "Event",
"to" => to,
"cc" => [],
"attributedTo" =>
if(is_nil(event.attributed_to) or not Ecto.assoc_loaded?(event.attributed_to),
do: nil,
else: event.attributed_to.url
) ||
event.organizer_actor.url,
"attributedTo" => attributed_to_or_default(event).url,
"name" => event.title,
"actor" =>
if(Ecto.assoc_loaded?(event.organizer_actor), do: event.organizer_actor.url, else: nil),
@@ -135,6 +130,15 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
|> maybe_add_inline_media(event)
end
@spec attributed_to_or_default(Event.t()) :: Actor.t()
defp attributed_to_or_default(event) do
if(is_nil(event.attributed_to) or not Ecto.assoc_loaded?(event.attributed_to),
do: nil,
else: event.attributed_to
) ||
event.organizer_actor
end
# Get only elements that we have in EventOptions
@spec get_options(map) :: map
defp get_options(object) do

View File

@@ -34,10 +34,20 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Post do
@impl Converter
@spec model_to_as(Post.t()) :: map
def model_to_as(
%Post{author: %Actor{url: actor_url}, attributed_to: %Actor{url: creator_url}} = post
%Post{
author: %Actor{url: actor_url},
attributed_to: %Actor{url: creator_url, followers_url: followers_url}
} = post
) do
to =
if post.visibility == :public,
do: ["https://www.w3.org/ns/activitystreams#Public"],
else: [followers_url]
%{
"type" => "Article",
"to" => to,
"cc" => [],
"actor" => actor_url,
"id" => post.url,
"name" => post.title,