1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-21 23:44:30 +00:00

Refactor audience to introduce maybe_add_followers/2

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-07-30 17:24:57 +02:00
parent e6c05c481a
commit 099b85e9a9
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 17 additions and 6 deletions

View file

@ -66,16 +66,20 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
end
def get_audience(%Participant{} = participant) do
event = Events.get_event_with_preload!(participant.event_id)
%Event{} = event = Events.get_event_with_preload!(participant.event_id)
%Actor{} = organizer = group_or_organizer_event(event)
actor_participants_urls =
cc =
event.id
|> Mobilizon.Events.list_actors_participants_for_event()
|> Enum.map(& &1.url)
|> Enum.filter(&(&1 != participant.actor.url))
|> maybe_add_group_members(organizer)
|> maybe_add_followers(organizer)
%{
"to" => [participant.actor.url, group_or_organizer_event(event).url],
"cc" => actor_participants_urls
"to" => [participant.actor.url, organizer.url],
"cc" => cc
}
end
@ -156,6 +160,13 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
defp maybe_add_group_members(collection, %Actor{type: _}), do: collection
@spec maybe_add_followers(List.t(), Actor.t()) :: List.t()
defp maybe_add_followers(collection, %Actor{type: :Group, followers_url: followers_url}) do
[followers_url | collection]
end
defp maybe_add_followers(collection, %Actor{type: _}), do: collection
def get_addressed_actors(mentioned_users, _), do: mentioned_users
defp add_in_reply_to(%Comment{actor: %Actor{url: url}} = _comment), do: [url]

View file

@ -257,7 +257,7 @@ defmodule Mobilizon.Federation.ActivityPub.AudienceTest do
assert %{
"to" => [participant.actor.url, participant.event.organizer_actor.url],
"cc" => [participant2.actor.url, participant.actor.url]
"cc" => [participant2.actor.url]
} == Audience.get_audience(participant)
end
@ -271,7 +271,7 @@ defmodule Mobilizon.Federation.ActivityPub.AudienceTest do
assert %{
"to" => [participant.actor.url, participant.event.attributed_to.url],
"cc" => [participant2.actor.url, participant.actor.url]
"cc" => [group.followers_url, group.members_url, participant2.actor.url]
} == Audience.get_audience(participant)
end
end