From c1423ddca3c82140e537037fdf133ee057c2dac0 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Sun, 17 Dec 2023 11:15:58 +0400 Subject: [PATCH] ActivityPub.Publisher: Filter inboxes --- lib/pleroma/web/activity_pub/publisher.ex | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index 373ceef32..a580994b1 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -118,7 +118,7 @@ defp should_federate?(inbox, public) do 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 followers = 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) non_mentioned = (followers ++ fetchers) -- mentioned - {mentioned, non_mentioned} + [mentioned, non_mentioned] end 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) {:ok, data} = Transmogrifier.prepare_outgoing(activity.data) - {priority_recipients, recipients} = recipients(actor, activity) + [priority_recipients, recipients] = recipients(actor, activity) inboxes = [priority_recipients, recipients] @@ -247,16 +247,19 @@ def publish(%User{} = actor, %Activity{} = activity) do {:ok, data} = Transmogrifier.prepare_outgoing(activity.data) json = Jason.encode!(data) - {priority_recipients, recipients} = recipients(actor, activity) - - [{priority_recipients, 0}, {recipients, 1}] - |> Enum.map(fn {recipients, priority} -> - recipients - |> Enum.map(fn %User{} = user -> - determine_inbox(activity, user) + [priority_inboxes, inboxes] = + recipients(actor, activity) + |> Enum.map(fn recipients -> + recipients + |> Enum.map(fn actor -> actor.inbox end) + |> Enum.filter(fn inbox -> should_federate?(inbox, public) 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() |> Enum.each(fn {inbox, unreachable_since} -> Pleroma.Web.Federator.Publisher.enqueue_one(