changeset 4667:1990611691cf

mod_external_services: Factor out public function returning current services This way you get the _prepared_ services and don't have to do that mapping yourself.
author Kim Alvefur <zash@zash.se>
date Mon, 30 Aug 2021 00:11:58 +0200
parents dbc7ba3cc27c
children ede9682c2022
files mod_external_services/mod_external_services.lua
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mod_external_services/mod_external_services.lua	Mon Aug 30 20:19:09 2021 +0200
+++ b/mod_external_services/mod_external_services.lua	Mon Aug 30 00:11:58 2021 +0200
@@ -115,6 +115,15 @@
 	end;
 }
 
+function get_services()
+	local extras = module:get_host_items("external_service");
+	local services = ( configured_services + extras ) / prepare;
+
+	setmetatable(services, services_mt);
+
+	return services;
+end
+
 local function handle_services(event)
 	local origin, stanza = event.origin, event.stanza;
 	local action = stanza.tags[1];
@@ -127,8 +136,7 @@
 	end
 
 	local reply = st.reply(stanza):tag("services", { xmlns = action.attr.xmlns });
-	local extras = module:get_host_items("external_service");
-	local services = ( configured_services + extras ) / prepare;
+	local services = get_services();
 
 	local requested_type = action.attr.type;
 	if requested_type then
@@ -137,8 +145,6 @@
 		end);
 	end
 
-	setmetatable(services, services_mt);
-
 	module:fire_event("external_service/services", {
 			origin = origin;
 			stanza = stanza;
@@ -174,8 +180,7 @@
 	end
 
 	local reply = st.reply(stanza):tag("credentials", { xmlns = action.attr.xmlns });
-	local extras = module:get_host_items("external_service");
-	local services = ( configured_services + extras ) / prepare;
+	local services = get_services();
 	services:filter(function (item)
 		return item.restricted;
 	end)
@@ -191,8 +196,6 @@
 			tonumber(service.attr.port) or 0));
 	end
 
-	setmetatable(services, services_mt);
-
 	module:fire_event("external_service/credentials", {
 			origin = origin;
 			stanza = stanza;