X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Ffederator%2Fpublisher.ex;h=937064638fc72ee9d8d1b21b80ac34656e17fc89;hb=4714b739a7606b07ec11cbc516c870afa8a18bf9;hp=36277fd7e91328f32a360c37c55bf07088e6dd2c;hpb=e7d292f80ee03d6eabf30792640a7a40e041a796;p=akkoma diff --git a/lib/pleroma/web/federator/publisher.ex b/lib/pleroma/web/federator/publisher.ex index 36277fd7e..937064638 100644 --- a/lib/pleroma/web/federator/publisher.ex +++ b/lib/pleroma/web/federator/publisher.ex @@ -3,6 +3,13 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Federator.Publisher do + alias Pleroma.Activity + alias Pleroma.Config + alias Pleroma.User + alias Pleroma.Workers.PublisherWorker + + require Logger + @moduledoc """ Defines the contract used by federation implementations to publish messages to their peers. @@ -19,20 +26,58 @@ defmodule Pleroma.Web.Federator.Publisher do """ @callback publish_one(Map.t()) :: {:ok, Map.t()} | {:error, any()} + @doc """ + Enqueue publishing a single activity. + """ + @spec enqueue_one(module(), Map.t()) :: :ok + def enqueue_one(module, %{} = params) do + PublisherWorker.enqueue( + "publish_one", + %{"module" => to_string(module), "params" => params} + ) + end + @doc """ Relays an activity to all specified peers. """ - @callback publish(Pleroma.User.t(), Pleroma.Activity.t()) :: :ok | {:error, any()} + @callback publish(User.t(), Activity.t()) :: :ok | {:error, any()} + + @spec publish(User.t(), Activity.t()) :: :ok + def publish(%User{} = user, %Activity{} = activity) do + Config.get([:instance, :federation_publisher_modules]) + |> Enum.each(fn module -> + if module.is_representable?(activity) do + Logger.info("Publishing #{activity.data["id"]} using #{inspect(module)}") + module.publish(user, activity) + end + end) + + :ok + end @doc """ - Enqueues work generated by the federation module. + Gathers links used by an outgoing federation module for WebFinger output. """ - @spec enqueue(module(), keyword()) :: :ok - def enqueue(module, args), do: PleromaJobQueue.enqueue(:federation_outgoing, module, args) + @callback gather_webfinger_links(User.t()) :: list() + + @spec gather_webfinger_links(User.t()) :: list() + def gather_webfinger_links(%User{} = user) do + Config.get([:instance, :federation_publisher_modules]) + |> Enum.reduce([], fn module, links -> + links ++ module.gather_webfinger_links(user) + end) + end @doc """ - Enqueue publishing a single activity. + Gathers nodeinfo protocol names supported by the federation module. """ - @spec enqueue_one(module(), Map.t()) :: :ok - def enqueue_one(module, %{} = args), do: enqueue(module, [:publish_one, args]) + @callback gather_nodeinfo_protocol_names() :: list() + + @spec gather_nodeinfo_protocol_names() :: list() + def gather_nodeinfo_protocol_names do + Config.get([:instance, :federation_publisher_modules]) + |> Enum.reduce([], fn module, links -> + links ++ module.gather_nodeinfo_protocol_names() + end) + end end