ActivtyPub Delivery: Use shared inbox if possible.

This commit is contained in:
lain 2018-02-17 16:18:10 +01:00
parent 7b26443a76
commit c2d0cb1a29

View file

@ -256,13 +256,16 @@ def make_user_from_ap_id(ap_id) do
def publish(actor, activity) do def publish(actor, activity) do
{:ok, followers} = User.get_followers(actor) {: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 |> Enum.uniq
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data) {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
Enum.each remote_users, fn(user) ->
if user.info["ap_enabled"] do Enum.each remote_inboxes, fn(inbox) ->
inbox = user.info["source_data"]["inbox"]
Logger.info("Federating #{activity.data["id"]} to #{inbox}") Logger.info("Federating #{activity.data["id"]} to #{inbox}")
host = URI.parse(inbox).host host = URI.parse(inbox).host
signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host}) signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host})
@ -270,4 +273,3 @@ def publish(actor, activity) do
end end
end end
end end
end