publisher: move remote_users() from Salmon module

This commit is contained in:
Ariadne Conill 2019-10-17 23:05:45 +00:00
parent 4f82e42e4e
commit adb639db56
2 changed files with 27 additions and 1 deletions

View file

@ -129,7 +129,7 @@ defp recipients(actor, activity) do
[]
end
Pleroma.Web.Salmon.remote_users(actor, activity) ++ followers ++ fetchers
Pleroma.Web.Federator.Publisher.remote_users(actor, activity) ++ followers ++ fetchers
end
defp get_cc_ap_ids(ap_id, recipients) do

View file

@ -80,4 +80,30 @@ def gather_nodeinfo_protocol_names do
links ++ module.gather_nodeinfo_protocol_names()
end)
end
@doc """
Gathers a set of remote users given an IR envelope.
"""
def remote_users(%User{id: user_id}, %{data: %{"to" => to} = data}) do
cc = Map.get(data, "cc", [])
bcc =
data
|> Map.get("bcc", [])
|> Enum.reduce([], fn ap_id, bcc ->
case Pleroma.List.get_by_ap_id(ap_id) do
%Pleroma.List{user_id: ^user_id} = list ->
{:ok, following} = Pleroma.List.get_following(list)
bcc ++ Enum.map(following, & &1.ap_id)
_ ->
bcc
end
end)
[to, cc, bcc]
|> Enum.concat()
|> Enum.map(&User.get_cached_by_ap_id/1)
|> Enum.filter(fn user -> user && !user.local end)
end
end