Make sure activity recipient can't be nil

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-05-06 17:47:23 +02:00
parent 888d2ef4b8
commit 3b8b150d48
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -110,13 +110,17 @@ defmodule Mobilizon.Federation.ActivityPub.Publisher do
@spec convert_followers_in_recipients(list(String.t())) :: {list(String.t()), list(String.t())} @spec convert_followers_in_recipients(list(String.t())) :: {list(String.t()), list(String.t())}
defp convert_followers_in_recipients(recipients) do defp convert_followers_in_recipients(recipients) do
Enum.reduce(recipients, {recipients, []}, fn recipient, {recipients, follower_actors} = acc -> Enum.reduce(recipients, {recipients, []}, fn recipient, {recipients, follower_actors} = acc ->
case Actors.get_actor_by_followers_url(recipient) do if is_nil(recipient) do
%Actor{} = group -> acc
{Enum.filter(recipients, fn recipient -> recipient != group.followers_url end), else
follower_actors ++ Actors.list_external_followers_for_actor(group)} case Actors.get_actor_by_followers_url(recipient) do
%Actor{} = group ->
{Enum.filter(recipients, fn recipient -> recipient != group.followers_url end),
follower_actors ++ Actors.list_external_followers_for_actor(group)}
nil -> nil ->
acc acc
end
end end
end) end)
end end
@ -128,19 +132,23 @@ defmodule Mobilizon.Federation.ActivityPub.Publisher do
@spec convert_members_in_recipients(list(String.t())) :: {list(String.t()), list(Actor.t())} @spec convert_members_in_recipients(list(String.t())) :: {list(String.t()), list(Actor.t())}
defp convert_members_in_recipients(recipients) do defp convert_members_in_recipients(recipients) do
Enum.reduce(recipients, {recipients, []}, fn recipient, {recipients, member_actors} = acc -> Enum.reduce(recipients, {recipients, []}, fn recipient, {recipients, member_actors} = acc ->
case Actors.get_group_by_members_url(recipient) do if is_nil(recipient) do
# If the group is local just add external members acc
%Actor{domain: domain} = group when is_nil(domain) -> else
{Enum.filter(recipients, fn recipient -> recipient != group.members_url end), case Actors.get_group_by_members_url(recipient) do
member_actors ++ Actors.list_external_actors_members_for_group(group)} # If the group is local just add external members
%Actor{domain: domain} = group when is_nil(domain) ->
{Enum.filter(recipients, fn recipient -> recipient != group.members_url end),
member_actors ++ Actors.list_external_actors_members_for_group(group)}
# If it's remote add the remote group actor as well # If it's remote add the remote group actor as well
%Actor{} = group -> %Actor{} = group ->
{Enum.filter(recipients, fn recipient -> recipient != group.members_url end), {Enum.filter(recipients, fn recipient -> recipient != group.members_url end),
member_actors ++ Actors.list_external_actors_members_for_group(group) ++ [group]} member_actors ++ Actors.list_external_actors_members_for_group(group) ++ [group]}
_ -> _ ->
acc acc
end
end end
end) end)
end end