Comparison

plugins/mod_pubsub/mod_pubsub.lua @ 12214:82cf9d3ffeee

mod_pubsub: Use the util.xtemplate to render Atom summary
author Kim Alvefur <zash@zash.se>
date Mon, 24 Jan 2022 23:04:38 +0100
parent 12212:bc6fc1cb04ae
child 12215:33a93d0a9a45
comparison
equal deleted inserted replaced
12213:dc9d63166488 12214:82cf9d3ffeee
2 local st = require "util.stanza"; 2 local st = require "util.stanza";
3 local jid_bare = require "util.jid".bare; 3 local jid_bare = require "util.jid".bare;
4 local usermanager = require "core.usermanager"; 4 local usermanager = require "core.usermanager";
5 local new_id = require "util.id".medium; 5 local new_id = require "util.id".medium;
6 local storagemanager = require "core.storagemanager"; 6 local storagemanager = require "core.storagemanager";
7 local xtemplate = require "util.xtemplate";
7 8
8 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; 9 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
9 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; 10 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
10 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; 11 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
11 12
134 end 135 end
135 136
136 -- Compose a textual representation of Atom payloads 137 -- Compose a textual representation of Atom payloads
137 module:hook("pubsub-summary/http://www.w3.org/2005/Atom", function (event) 138 module:hook("pubsub-summary/http://www.w3.org/2005/Atom", function (event)
138 local payload = event.payload; 139 local payload = event.payload;
139 local title = payload:get_child_text("title"); 140 local template = "{summary|or{{author/name|and{{author/name} posted }}{title}}}";
140 local summary = payload:get_child_text("summary"); 141 local summary = xtemplate.render(template, payload, tostring);
141 if not summary and title then
142 local author = payload:find("author/name#");
143 summary = title;
144 if author then
145 summary = author .. " posted " .. summary;
146 end
147 end
148 return summary; 142 return summary;
149 end, -1); 143 end, -1);
150 144
151 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); 145 module:hook("iq/host/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
152 module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); 146 module:hook("iq/host/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);