From: lain Date: Sat, 17 Feb 2018 15:18:10 +0000 (+0100) Subject: ActivtyPub Delivery: Use shared inbox if possible. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=c2d0cb1a295c46ebb425405a2b38c1c2fe3e6ae1;p=akkoma ActivtyPub Delivery: Use shared inbox if possible. --- 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