From 9c899169692661a99ccb8a5e607b17788d3eec55 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 20 Feb 2018 08:51:19 +0100 Subject: [PATCH] ActivityPub: One queue item per server. --- lib/pleroma/web/activity_pub/activity_pub.ex | 13 +++++++++---- lib/pleroma/web/federator/federator.ex | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 18c2c1900..cc2019791 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -2,6 +2,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do alias Pleroma.{Activity, Repo, Object, Upload, User, Notification} alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.WebFinger + alias Pleroma.Web.Federator import Ecto.Query import Pleroma.Web.ActivityPub.Utils require Logger @@ -305,13 +306,17 @@ def publish(actor, activity) do {:ok, data} = Transmogrifier.prepare_outgoing(activity.data) json = Poison.encode!(data) 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, "content-length": byte_size(json)}) - @httpoison.post(inbox, json, [{"Content-Type", "application/activity+json"}, {"signature", signature}]) + Federator.enqueue(:publish_single_ap, %{inbox: inbox, json: json, actor: actor, id: activity.data["id"]}) end end + def publish_one(%{inbox: inbox, json: json, actor: actor, id: id}) do + Logger.info("Federating #{id} to #{inbox}") + host = URI.parse(inbox).host + signature = Pleroma.Web.HTTPSignatures.sign(actor, %{host: host, "content-length": byte_size(json)}) + @httpoison.post(inbox, json, [{"Content-Type", "application/activity+json"}, {"signature", signature}]) + end + # TODO: # This will create a Create activity, which we need internally at the moment. def fetch_object_from_id(id) do diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index a13126048..b64b43c56 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -66,6 +66,10 @@ def handle(:incoming_doc, doc) do @ostatus.handle_incoming(doc) end + def handle(:publish_single_ap, params) do + ActivityPub.publish_one(params) + end + def handle(:publish_single_websub, %{xml: xml, topic: topic, callback: callback, secret: secret}) do signature = @websub.sign(secret || "", xml) Logger.debug(fn -> "Pushing #{topic} to #{callback}" end)