comparison plugins/mod_pubsub/mod_pubsub.lua @ 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 82cf9d3ffeee
children 018ac691ee22
comparison
equal deleted inserted replaced
12214:82cf9d3ffeee 12215:33a93d0a9a45
133 function is_item_stanza(item) 133 function is_item_stanza(item)
134 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item" and #item.tags == 1; 134 return st.is_stanza(item) and item.attr.xmlns == xmlns_pubsub and item.name == "item" and #item.tags == 1;
135 end 135 end
136 136
137 -- Compose a textual representation of Atom payloads 137 -- Compose a textual representation of Atom payloads
138 module:hook("pubsub-summary/http://www.w3.org/2005/Atom", function (event) 138 local summary_templates = module:get_option("pubsub_summary_templates", {
139 local payload = event.payload; 139 ["http://www.w3.org/2005/Atom"] = "{summary|or{{author/name|and{{author/name} posted }}{title}}}";
140 local template = "{summary|or{{author/name|and{{author/name} posted }}{title}}}"; 140 })
141 local summary = xtemplate.render(template, payload, tostring); 141
142 return summary; 142 for pubsub_type, template in pairs(summary_templates) do
143 end, -1); 143 module:hook("pubsub-summary/"..pubsub_type, function (event)
144 local payload = event.payload;
145 return xtemplate.render(template, payload, tostring);
146 end, -1);
147 end
148
144 149
145 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); 150 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
146 module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); 151 module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);
147 152
148 local function add_disco_features_from_service(service) --luacheck: ignore 431/service 153 local function add_disco_features_from_service(service) --luacheck: ignore 431/service