ActivtyPub Delivery: Use shared inbox if possible.
authorlain <lain@soykaf.club>
Sat, 17 Feb 2018 15:18:10 +0000 (16:18 +0100)
committerlain <lain@soykaf.club>
Sat, 17 Feb 2018 15:18:10 +0000 (16:18 +0100)
lib/pleroma/web/activity_pub/activity_pub.ex

index 0c1b6cb280e01ce7631990f7ef22efd39be5d6ab..3d476d729bd8bf9e6d6a9731b833755f758920f1 100644 (file)
@@ -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