From 44b182732efe2d8571aa54e6062637e7e42021ce Mon Sep 17 00:00:00 2001
From: William Pitcock <nenolod@dereferenced.org>
Date: Sun, 12 May 2019 19:15:29 +0000
Subject: [PATCH] nodeinfo: gather supported protocol names from federation
 modules

---
 lib/pleroma/web/activity_pub/publisher.ex       |  2 ++
 lib/pleroma/web/federator/publisher.ex          | 13 +++++++++++++
 lib/pleroma/web/nodeinfo/nodeinfo_controller.ex |  3 ++-
 lib/pleroma/web/salmon/salmon.ex                |  2 ++
 lib/pleroma/web/websub/websub.ex                |  2 ++
 5 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex
index 5c97485c8..8e3af0a81 100644
--- a/lib/pleroma/web/activity_pub/publisher.ex
+++ b/lib/pleroma/web/activity_pub/publisher.ex
@@ -147,4 +147,6 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
       }
     ]
   end
+
+  def gather_nodeinfo_protocol_names, do: ["activitypub"]
 end
diff --git a/lib/pleroma/web/federator/publisher.ex b/lib/pleroma/web/federator/publisher.ex
index 112a0574f..916bcdcba 100644
--- a/lib/pleroma/web/federator/publisher.ex
+++ b/lib/pleroma/web/federator/publisher.ex
@@ -79,4 +79,17 @@ defmodule Pleroma.Web.Federator.Publisher do
       links ++ module.gather_webfinger_links(user)
     end)
   end
+
+  @doc """
+  Gathers nodeinfo protocol names supported by the federation module.
+  """
+  @callback gather_nodeinfo_protocol_names() :: list()
+
+  @spec gather_nodeinfo_protocol_names() :: list()
+  def gather_nodeinfo_protocol_names do
+    Config.get([:instance, :federation_publisher_modules])
+    |> Enum.reduce([], fn module, links ->
+      links ++ module.gather_nodeinfo_protocol_names()
+    end)
+  end
 end
diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
index 216a962bd..3bf2a0fbc 100644
--- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
+++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
@@ -10,6 +10,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
   alias Pleroma.User
   alias Pleroma.Web
   alias Pleroma.Web.ActivityPub.MRF
+  alias Pleroma.Web.Federator.Publisher
 
   plug(Pleroma.Web.FederatingPlug)
 
@@ -137,7 +138,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
         name: Pleroma.Application.name() |> String.downcase(),
         version: Pleroma.Application.version()
       },
-      protocols: ["ostatus", "activitypub"],
+      protocols: Publisher.gather_nodeinfo_protocol_names(),
       services: %{
         inbound: [],
         outbound: []
diff --git a/lib/pleroma/web/salmon/salmon.ex b/lib/pleroma/web/salmon/salmon.ex
index 92e85b5e9..42709ab47 100644
--- a/lib/pleroma/web/salmon/salmon.ex
+++ b/lib/pleroma/web/salmon/salmon.ex
@@ -264,4 +264,6 @@ defmodule Pleroma.Web.Salmon do
       }
     ]
   end
+
+  def gather_nodeinfo_protocol_names, do: []
 end
diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex
index 2ce6dcc19..7ad0414ab 100644
--- a/lib/pleroma/web/websub/websub.ex
+++ b/lib/pleroma/web/websub/websub.ex
@@ -328,4 +328,6 @@ defmodule Pleroma.Web.Websub do
       }
     ]
   end
+
+  def gather_nodeinfo_protocol_names, do: ["ostatus"]
 end