aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2019-05-12 02:41:34 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2019-05-12 03:08:50 +0000
commite7d292f80ee03d6eabf30792640a7a40e041a796 (patch)
tree84c9114cfaf7def44a3cd95224e2dac7dae6d2ef /lib
parent131f88320740bec9c74e4280a6b1a7d8641ee367 (diff)
downloadpleroma-e7d292f80ee03d6eabf30792640a7a40e041a796.tar.gz
federator: add publisher module defining a contract for publishing behaviours
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/federator/publisher.ex38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/pleroma/web/federator/publisher.ex b/lib/pleroma/web/federator/publisher.ex
new file mode 100644
index 000000000..36277fd7e
--- /dev/null
+++ b/lib/pleroma/web/federator/publisher.ex
@@ -0,0 +1,38 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Federator.Publisher do
+ @moduledoc """
+ Defines the contract used by federation implementations to publish messages to
+ their peers.
+ """
+
+ @doc """
+ Determine whether an activity can be relayed using the federation module.
+ """
+ @callback is_representable?(Pleroma.Activity.t()) :: boolean()
+
+ @doc """
+ Relays an activity to a specified peer, determined by the parameters. The
+ parameters used are controlled by the federation module.
+ """
+ @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 """
+ Enqueues work generated by the federation module.
+ """
+ @spec enqueue(module(), keyword()) :: :ok
+ def enqueue(module, args), do: PleromaJobQueue.enqueue(:federation_outgoing, module, args)
+
+ @doc """
+ Enqueue publishing a single activity.
+ """
+ @spec enqueue_one(module(), Map.t()) :: :ok
+ def enqueue_one(module, %{} = args), do: enqueue(module, [:publish_one, args])
+end