Comparison

plugins/muc/muc.lib.lua @ 6990:f476e2497568

MUC: Fire per-field events for the config form, including those with value == nil (no <value/> element in form)
author Matthew Wild <mwild1@gmail.com>
date Fri, 11 Dec 2015 15:27:01 +0000
parent 6988:329d5fb8a9d3
child 7013:f387fae9fb31
comparison
equal deleted inserted replaced
6989:118858bf47cd 6990:f476e2497568
642 function room_mt:process_form(origin, stanza) 642 function room_mt:process_form(origin, stanza)
643 local form = stanza.tags[1]:get_child("x", "jabber:x:data"); 643 local form = stanza.tags[1]:get_child("x", "jabber:x:data");
644 if form.attr.type == "cancel" then 644 if form.attr.type == "cancel" then
645 origin.send(st.reply(stanza)); 645 origin.send(st.reply(stanza));
646 elseif form.attr.type == "submit" then 646 elseif form.attr.type == "submit" then
647 local fields; 647 local fields, errors, present;
648 if form.tags[1] == nil then -- Instant room 648 if form.tags[1] == nil then -- Instant room
649 fields = {}; 649 fields, present = {}, {};
650 else 650 else
651 fields = self:get_form_layout(stanza.attr.from):data(form); 651 fields, errors, present = self:get_form_layout(stanza.attr.from):data(form);
652 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then 652 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then
653 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); 653 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration"));
654 return true; 654 return true;
655 end 655 end
656 end 656 end
664 event.status_codes["104"] = true; 664 event.status_codes["104"] = true;
665 self["set_"..name](self, new); 665 self["set_"..name](self, new);
666 return true; 666 return true;
667 end 667 end
668 module:fire_event("muc-config-submitted", event); 668 module:fire_event("muc-config-submitted", event);
669 for submitted_field in pairs(present) do
670 event.field, event.value = submitted_field, fields[submitted_field];
671 module:fire_event("muc-config-submitted/"..submitted_field, event);
672 end
673 event.field, event.value = nil, nil;
669 674
670 if self.save then self:save(true); end 675 if self.save then self:save(true); end
671 origin.send(st.reply(stanza)); 676 origin.send(st.reply(stanza));
672 677
673 if next(event.status_codes) then 678 if next(event.status_codes) then