From 10695a28d28d74f4b6b9bba20af66b506b662c07 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 12 May 2019 03:55:17 +0000 Subject: [PATCH] federator: publisher: add publish() wrapper --- config/config.exs | 3 +++ lib/pleroma/web/federator/publisher.ex | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/config/config.exs b/config/config.exs index 1e64b79a7..37803383a 100644 --- a/config/config.exs +++ b/config/config.exs @@ -212,6 +212,9 @@ registrations_open: true, federating: true, federation_reachability_timeout_days: 7, + federation_publisher_modules: [ + Pleroma.Web.ActivityPub.Publisher + ], allow_relay: true, rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy, public: true, diff --git a/lib/pleroma/web/federator/publisher.ex b/lib/pleroma/web/federator/publisher.ex index 2e533ae94..8777a3deb 100644 --- a/lib/pleroma/web/federator/publisher.ex +++ b/lib/pleroma/web/federator/publisher.ex @@ -3,6 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Federator.Publisher do + alias Pleroma.Activity + alias Pleroma.Config + alias Pleroma.User alias Pleroma.Web.Federator.RetryQueue require Logger @@ -23,11 +26,6 @@ defmodule Pleroma.Web.Federator.Publisher do """ @callback publish_one(Map.t()) :: {:ok, Map.t()} | {:error, any()} - @doc """ - Relays an activity to all specified peers. - """ - @callback publish(Pleroma.User.t(), Pleroma.Activity.t()) :: :ok | {:error, any()} - @doc """ Enqueue publishing a single activity. """ @@ -50,4 +48,20 @@ def perform(type, _, _) do Logger.debug("Unknown task: #{type}") {:error, "Don't know what to do with this"} end + + @doc """ + Relays an activity to all specified peers. + """ + @callback publish(Pleroma.User.t(), Pleroma.Activity.t()) :: :ok | {:error, any()} + + @spec publish(Pleroma.User.t(), Pleroma.Activity.t()) :: :ok + def publish(%User{} = user, %Activity{} = activity) do + Config.get([:instance, :federation_publisher_modules]) + |> Enum.each(fn module -> + Logger.info("Publishing #{activity.data["id"]} using #{inspect(module)}") + module.publish(user, activity) + end) + + :ok + end end