Fix audience for comments under a remote event from group
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
d3a05b5568
commit
56861d6483
@ -52,16 +52,14 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
}) do
|
||||
with {to, cc} <-
|
||||
extract_actors_from_mentions(mentions, actor, visibility),
|
||||
{to, cc} <- {Enum.uniq(to ++ add_in_reply_to(in_reply_to_comment)), cc},
|
||||
{to, cc} <- {Enum.uniq(to ++ add_event_author(event)), cc},
|
||||
{to, cc} <- {to ++ add_in_reply_to(in_reply_to_comment), cc},
|
||||
{to, cc} <- add_event_organizers(event, to, cc),
|
||||
{to, cc} <-
|
||||
{to,
|
||||
Enum.uniq(
|
||||
cc ++
|
||||
add_comments_authors([origin_comment]) ++
|
||||
add_shares_actors_followers(url)
|
||||
)} do
|
||||
%{"to" => to, "cc" => cc}
|
||||
cc ++
|
||||
add_comments_authors([origin_comment]) ++
|
||||
add_shares_actors_followers(url)} do
|
||||
%{"to" => Enum.uniq(to), "cc" => Enum.uniq(cc)}
|
||||
end
|
||||
end
|
||||
|
||||
@ -173,11 +171,22 @@ defmodule Mobilizon.Federation.ActivityPub.Audience do
|
||||
defp add_in_reply_to(%Event{organizer_actor: %Actor{url: url}} = _event), do: [url]
|
||||
defp add_in_reply_to(_), do: []
|
||||
|
||||
defp add_event_author(%Event{} = event) do
|
||||
[Repo.preload(event, [:organizer_actor]).organizer_actor.url]
|
||||
defp add_event_organizers(%Event{} = event, to, cc) do
|
||||
event = Repo.preload(event, [:organizer_actor, :attributed_to])
|
||||
|
||||
case event do
|
||||
%Event{
|
||||
attributed_to: %Actor{members_url: members_url, followers_url: followers_url},
|
||||
organizer_actor: %Actor{url: organizer_actor_url}
|
||||
} ->
|
||||
{to ++ [organizer_actor_url, members_url], cc ++ [followers_url]}
|
||||
|
||||
%Event{organizer_actor: %Actor{url: organizer_actor_url}} ->
|
||||
{to ++ [organizer_actor_url], cc}
|
||||
end
|
||||
end
|
||||
|
||||
defp add_event_author(_), do: []
|
||||
defp add_event_organizers(_, to, cc), do: {to, cc}
|
||||
|
||||
defp add_comment_author(%Comment{} = comment) do
|
||||
case Repo.preload(comment, [:actor]) do
|
||||
|
@ -247,6 +247,32 @@ defmodule Mobilizon.Federation.ActivityPub.AudienceTest do
|
||||
assert %{"to" => [members_url], "cc" => []} ==
|
||||
Audience.get_audience(comment)
|
||||
end
|
||||
|
||||
test "reply to a remote comment" do
|
||||
%Actor{id: remote_actor_id, url: remote_actor_url} =
|
||||
remote_actor =
|
||||
insert(:actor, domain: "somewhere.else", url: "https://somewhere.else/@someone")
|
||||
|
||||
%Actor{id: remote_group_id, url: remote_group_url} =
|
||||
remote_group =
|
||||
insert(:group, domain: "somewhere.else", url: "https://somewhere.else/@somegroup")
|
||||
|
||||
%Event{} =
|
||||
event =
|
||||
insert(:event, local: false, organizer_actor: remote_actor, attributed_to: remote_group)
|
||||
|
||||
%Comment{} = comment = insert(:comment, event: event)
|
||||
|
||||
assert %{
|
||||
"cc" => [comment.actor.followers_url, comment.event.attributed_to.followers_url],
|
||||
"to" => [
|
||||
@ap_public,
|
||||
comment.event.organizer_actor.url,
|
||||
comment.event.attributed_to.members_url
|
||||
]
|
||||
} ==
|
||||
Audience.get_audience(comment)
|
||||
end
|
||||
end
|
||||
|
||||
describe "participant" do
|
||||
|
Loading…
Reference in New Issue
Block a user