36277fd7e91328f32a360c37c55bf07088e6dd2c
[akkoma] / lib / pleroma / web / federator / publisher.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Federator.Publisher do
6 @moduledoc """
7 Defines the contract used by federation implementations to publish messages to
8 their peers.
9 """
10
11 @doc """
12 Determine whether an activity can be relayed using the federation module.
13 """
14 @callback is_representable?(Pleroma.Activity.t()) :: boolean()
15
16 @doc """
17 Relays an activity to a specified peer, determined by the parameters. The
18 parameters used are controlled by the federation module.
19 """
20 @callback publish_one(Map.t()) :: {:ok, Map.t()} | {:error, any()}
21
22 @doc """
23 Relays an activity to all specified peers.
24 """
25 @callback publish(Pleroma.User.t(), Pleroma.Activity.t()) :: :ok | {:error, any()}
26
27 @doc """
28 Enqueues work generated by the federation module.
29 """
30 @spec enqueue(module(), keyword()) :: :ok
31 def enqueue(module, args), do: PleromaJobQueue.enqueue(:federation_outgoing, module, args)
32
33 @doc """
34 Enqueue publishing a single activity.
35 """
36 @spec enqueue_one(module(), Map.t()) :: :ok
37 def enqueue_one(module, %{} = args), do: enqueue(module, [:publish_one, args])
38 end