ActivityPub.Publisher: Filter inboxes

This commit is contained in:
Lain Soykaf 2023-12-17 11:15:58 +04:00
parent 77bb1bb6c8
commit c1423ddca3
1 changed files with 15 additions and 12 deletions

View File

@ -118,7 +118,7 @@ defp should_federate?(inbox, public) do
end end
end end
@spec recipients(User.t(), Activity.t()) :: {[User.t()], [User.t()]} @spec recipients(User.t(), Activity.t()) :: [[User.t()]]
defp recipients(actor, activity) do defp recipients(actor, activity) do
followers = followers =
if actor.follower_address in activity.recipients do if actor.follower_address in activity.recipients do
@ -141,7 +141,7 @@ defp recipients(actor, activity) do
mentioned = Pleroma.Web.Federator.Publisher.remote_users(actor, activity) mentioned = Pleroma.Web.Federator.Publisher.remote_users(actor, activity)
non_mentioned = (followers ++ fetchers) -- mentioned non_mentioned = (followers ++ fetchers) -- mentioned
{mentioned, non_mentioned} [mentioned, non_mentioned]
end end
defp get_cc_ap_ids(ap_id, recipients) do defp get_cc_ap_ids(ap_id, recipients) do
@ -198,7 +198,7 @@ def publish(%User{} = actor, %{data: %{"bcc" => bcc}} = activity)
public = is_public?(activity) public = is_public?(activity)
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data) {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
{priority_recipients, recipients} = recipients(actor, activity) [priority_recipients, recipients] = recipients(actor, activity)
inboxes = inboxes =
[priority_recipients, recipients] [priority_recipients, recipients]
@ -247,16 +247,19 @@ def publish(%User{} = actor, %Activity{} = activity) do
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data) {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
json = Jason.encode!(data) json = Jason.encode!(data)
{priority_recipients, recipients} = recipients(actor, activity) [priority_inboxes, inboxes] =
recipients(actor, activity)
[{priority_recipients, 0}, {recipients, 1}] |> Enum.map(fn recipients ->
|> Enum.map(fn {recipients, priority} -> recipients
recipients |> Enum.map(fn actor -> actor.inbox end)
|> Enum.map(fn %User{} = user -> |> Enum.filter(fn inbox -> should_federate?(inbox, public) end)
determine_inbox(activity, user)
end) end)
|> Enum.uniq()
|> Enum.filter(fn inbox -> should_federate?(inbox, public) end) inboxes = inboxes -- priority_inboxes
[{priority_inboxes, 0}, {inboxes, 1}]
|> Enum.each(fn {inboxes, priority} ->
inboxes
|> Instances.filter_reachable() |> Instances.filter_reachable()
|> Enum.each(fn {inbox, unreachable_since} -> |> Enum.each(fn {inbox, unreachable_since} ->
Pleroma.Web.Federator.Publisher.enqueue_one( Pleroma.Web.Federator.Publisher.enqueue_one(