From c2d0cb1a295c46ebb425405a2b38c1c2fe3e6ae1 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 17 Feb 2018 16:18:10 +0100 Subject: [PATCH] ActivtyPub Delivery: Use shared inbox if possible. --- lib/pleroma/web/activity_pub/activity_pub.ex | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 0c1b6cb28..3d476d729 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -256,18 +256,20 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def publish(actor, activity) do {:ok, followers} = User.get_followers(actor) - remote_users = Pleroma.Web.Salmon.remote_users(activity) ++ followers + remote_inboxes = Pleroma.Web.Salmon.remote_users(activity) ++ followers + |> Enum.filter(fn (user) -> User.ap_enabled?(user) end) + |> Enum.map(fn (%{info: %{"source_data" => data}}) -> + (data["endpoints"] && data["endpoints"]["sharedInbox"]) ||data["inbox"] + end) |> Enum.uniq {:ok, data} = Transmogrifier.prepare_outgoing(activity.data) - Enum.each remote_users, fn(user) -> - if user.info["ap_enabled"] do - inbox = user.info["source_data"]["inbox"] - Logger.info("Federating #{activity.data["id"]} to #{inbox}") - host = URI.parse(inbox).host - signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host}) - @httpoison.post(inbox, Poison.encode!(data), [{"Content-Type", "application/activity+json"}, {"signature", signature}]) - end + + Enum.each remote_inboxes, fn(inbox) -> + Logger.info("Federating #{activity.data["id"]} to #{inbox}") + host = URI.parse(inbox).host + signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host}) + @httpoison.post(inbox, Poison.encode!(data), [{"Content-Type", "application/activity+json"}, {"signature", signature}]) end end end