ostatus: only as:Public activities are representable
[akkoma] / lib / pleroma / web / federator / publisher.ex
index 2e533ae946e58d3bbadc41e7935bb8e0ac42b7b2..8777a3deb9ff7f4bf7d7b48a934db498cafde418 100644 (file)
@@ -3,6 +3,9 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.Federator.Publisher do
+  alias Pleroma.Activity
+  alias Pleroma.Config
+  alias Pleroma.User
   alias Pleroma.Web.Federator.RetryQueue
 
   require Logger
@@ -23,11 +26,6 @@ defmodule Pleroma.Web.Federator.Publisher do
   """
   @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 """
   Enqueue publishing a single activity.
   """
@@ -50,4 +48,20 @@ defmodule Pleroma.Web.Federator.Publisher do
     Logger.debug("Unknown task: #{type}")
     {:error, "Don't know what to do with this"}
   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