federator: publisher: add publish() wrapper

This commit is contained in:
William Pitcock 2019-05-12 03:55:17 +00:00
parent 0afc8d7856
commit 10695a28d2
2 changed files with 22 additions and 5 deletions

View File

@ -212,6 +212,9 @@ config :pleroma, :instance,
registrations_open: true, registrations_open: true,
federating: true, federating: true,
federation_reachability_timeout_days: 7, federation_reachability_timeout_days: 7,
federation_publisher_modules: [
Pleroma.Web.ActivityPub.Publisher
],
allow_relay: true, allow_relay: true,
rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy, rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
public: true, public: true,

View File

@ -3,6 +3,9 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Federator.Publisher do defmodule Pleroma.Web.Federator.Publisher do
alias Pleroma.Activity
alias Pleroma.Config
alias Pleroma.User
alias Pleroma.Web.Federator.RetryQueue alias Pleroma.Web.Federator.RetryQueue
require Logger require Logger
@ -24,11 +27,6 @@ defmodule Pleroma.Web.Federator.Publisher do
@callback publish_one(Map.t()) :: {:ok, Map.t()} | {:error, any()} @callback publish_one(Map.t()) :: {:ok, Map.t()} | {:error, any()}
@doc """ @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. Enqueue publishing a single activity.
""" """
@spec enqueue_one(module(), Map.t()) :: :ok @spec enqueue_one(module(), Map.t()) :: :ok
@ -50,4 +48,20 @@ defmodule Pleroma.Web.Federator.Publisher do
Logger.debug("Unknown task: #{type}") Logger.debug("Unknown task: #{type}")
{:error, "Don't know what to do with this"} {:error, "Don't know what to do with this"}
end 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 end