Mercurial > prosody-hg
comparison plugins/muc/muc.lib.lua @ 5541:1997671d5e46
MUC: Allow plugins to add and handle options in the MUC config form
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 29 Apr 2013 11:21:37 +0100 |
| parents | 06e188268df1 |
| children | 329ebdfb39a2 |
comparison
equal
deleted
inserted
replaced
| 5539:0ae7ed378405 | 5541:1997671d5e46 |
|---|---|
| 578 :add_child(self:get_form_layout():form()) | 578 :add_child(self:get_form_layout():form()) |
| 579 ); | 579 ); |
| 580 end | 580 end |
| 581 | 581 |
| 582 function room_mt:get_form_layout() | 582 function room_mt:get_form_layout() |
| 583 local title = "Configuration for "..self.jid; | 583 local form = dataform.new({ |
| 584 return dataform.new({ | 584 title = "Configuration for "..self.jid, |
| 585 title = title, | 585 instructions = "Complete and submit this form to configure the room.", |
| 586 instructions = title, | |
| 587 { | 586 { |
| 588 name = 'FORM_TYPE', | 587 name = 'FORM_TYPE', |
| 589 type = 'hidden', | 588 type = 'hidden', |
| 590 value = 'http://jabber.org/protocol/muc#roomconfig' | 589 value = 'http://jabber.org/protocol/muc#roomconfig' |
| 591 }, | 590 }, |
| 651 type = 'text-single', | 650 type = 'text-single', |
| 652 label = 'Maximum Number of History Messages Returned by Room', | 651 label = 'Maximum Number of History Messages Returned by Room', |
| 653 value = tostring(self:get_historylength()) | 652 value = tostring(self:get_historylength()) |
| 654 } | 653 } |
| 655 }); | 654 }); |
| 655 return module:fire_event("muc-config-form", { room = self, form = form }) or form; | |
| 656 end | 656 end |
| 657 | 657 |
| 658 local valid_whois = { | 658 local valid_whois = { |
| 659 moderators = true, | 659 moderators = true, |
| 660 anyone = true, | 660 anyone = true, |
| 670 | 670 |
| 671 local fields = self:get_form_layout():data(form); | 671 local fields = self:get_form_layout():data(form); |
| 672 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); return; end | 672 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); return; end |
| 673 | 673 |
| 674 local dirty = false | 674 local dirty = false |
| 675 | |
| 676 local event = { room = self, fields = fields, changed = dirty }; | |
| 677 module:fire_event("muc-config-submitted", event); | |
| 678 dirty = event.changed or dirty; | |
| 675 | 679 |
| 676 local name = fields['muc#roomconfig_roomname']; | 680 local name = fields['muc#roomconfig_roomname']; |
| 677 if name ~= self:get_name() then | 681 if name ~= self:get_name() then |
| 678 self:set_name(name); | 682 self:set_name(name); |
| 679 end | 683 end |
