Changeset

12215:33a93d0a9a45

mod_pubsub: Allow configuring summary templates Enables generation of summaries for more than Atom without additional modules.
author Kim Alvefur <zash@zash.se>
date Mon, 24 Jan 2022 23:06:45 +0100
parents 12214:82cf9d3ffeee
children 12216:0f5d04c3092f
files plugins/mod_pubsub/mod_pubsub.lua
diffstat 1 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_pubsub/mod_pubsub.lua	Mon Jan 24 23:04:38 2022 +0100
+++ b/plugins/mod_pubsub/mod_pubsub.lua	Mon Jan 24 23:06:45 2022 +0100
@@ -135,12 +135,17 @@
 end
 
 -- Compose a textual representation of Atom payloads
-module:hook("pubsub-summary/http://www.w3.org/2005/Atom", function (event)
-	local payload = event.payload;
-	local template = "{summary|or{{author/name|and{{author/name} posted }}{title}}}";
-	local summary = xtemplate.render(template, payload, tostring);
-	return summary;
-end, -1);
+local summary_templates = module:get_option("pubsub_summary_templates", {
+	["http://www.w3.org/2005/Atom"] = "{summary|or{{author/name|and{{author/name} posted }}{title}}}";
+})
+
+for pubsub_type, template in pairs(summary_templates) do
+	module:hook("pubsub-summary/"..pubsub_type, function (event)
+		local payload = event.payload;
+		return xtemplate.render(template, payload, tostring);
+	end, -1);
+end
+
 
 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
 module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);