1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Federator.Publisher do
6 alias Pleroma.Web.Federator.RetryQueue
11 Defines the contract used by federation implementations to publish messages to
16 Determine whether an activity can be relayed using the federation module.
18 @callback is_representable?(Pleroma.Activity.t()) :: boolean()
21 Relays an activity to a specified peer, determined by the parameters. The
22 parameters used are controlled by the federation module.
24 @callback publish_one(Map.t()) :: {:ok, Map.t()} | {:error, any()}
27 Relays an activity to all specified peers.
29 @callback publish(Pleroma.User.t(), Pleroma.Activity.t()) :: :ok | {:error, any()}
32 Enqueue publishing a single activity.
34 @spec enqueue_one(module(), Map.t()) :: :ok
35 def enqueue_one(module, %{} = params),
36 do: PleromaJobQueue.enqueue(:federation_outgoing, __MODULE__, [:publish_one, module, params])
38 @spec perform(atom(), module(), any()) :: {:ok, any()} | {:error, any()}
39 def perform(:publish_one, module, params) do
40 case apply(module, :publish_one, [params]) do
45 RetryQueue.enqueue(params, module)
49 def perform(type, _, _) do
50 Logger.debug("Unknown task: #{type}")
51 {:error, "Don't know what to do with this"}