Comparison

plugins/muc/muc.lib.lua @ 7119:50b9a7e86de9

MUC: Separate form data from form in disco#info event
author Kim Alvefur <zash@zash.se>
date Wed, 03 Feb 2016 02:05:49 +0100
parent 7089:890f4b2cc444
child 7120:a6afe52159f1
comparison
equal deleted inserted replaced
7116:ecba5fee4867 7119:50b9a7e86de9
308 function room_mt:get_disco_info(stanza) 308 function room_mt:get_disco_info(stanza)
309 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#info"); 309 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#info");
310 local form = dataform.new { 310 local form = dataform.new {
311 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/muc#roominfo" }; 311 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/muc#roominfo" };
312 }; 312 };
313 module:fire_event("muc-disco#info", {room = self; reply = reply; form = form;}); 313 local formdata = {};
314 reply:add_child(form:form(nil, "result")); 314 module:fire_event("muc-disco#info", {room = self; reply = reply; form = form, formdata = formdata ;});
315 reply:add_child(form:form(formdata, "result"));
315 return reply; 316 return reply;
316 end 317 end
317 module:hook("muc-disco#info", function(event) 318 module:hook("muc-disco#info", function(event)
318 event.reply:tag("feature", {var = "http://jabber.org/protocol/muc"}):up(); 319 event.reply:tag("feature", {var = "http://jabber.org/protocol/muc"}):up();
319 end); 320 end);
320 module:hook("muc-disco#info", function(event) 321 module:hook("muc-disco#info", function(event)
321 local count = iterators.count(event.room:each_occupant()); 322 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants" });
322 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); 323 event.formdata["muc#roominfo_occupants"] = tostring(iterators.count(event.room:each_occupant()));
323 end); 324 end);
324 325
325 function room_mt:get_disco_items(stanza) 326 function room_mt:get_disco_items(stanza)
326 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); 327 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items");
327 for room_jid in self:each_occupant() do 328 for room_jid in self:each_occupant() do