Mercurial > prosody-hg
comparison plugins/muc/muc.lib.lua @ 5601:f55ab5fa939f
mod_muc: Pass actor (requesting JID) when generating the config form, and to the muc-config-form event handler
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 18 May 2013 15:29:10 +0100 |
| parents | 1b326a1e4da6 |
| children | e043d4d65423 |
comparison
equal
deleted
inserted
replaced
| 5600:1b326a1e4da6 | 5601:f55ab5fa939f |
|---|---|
| 592 end | 592 end |
| 593 end | 593 end |
| 594 | 594 |
| 595 function room_mt:send_form(origin, stanza) | 595 function room_mt:send_form(origin, stanza) |
| 596 origin.send(st.reply(stanza):query("http://jabber.org/protocol/muc#owner") | 596 origin.send(st.reply(stanza):query("http://jabber.org/protocol/muc#owner") |
| 597 :add_child(self:get_form_layout():form()) | 597 :add_child(self:get_form_layout(stanza.attr.from):form()) |
| 598 ); | 598 ); |
| 599 end | 599 end |
| 600 | 600 |
| 601 function room_mt:get_form_layout() | 601 function room_mt:get_form_layout(actor) |
| 602 local form = dataform.new({ | 602 local form = dataform.new({ |
| 603 title = "Configuration for "..self.jid, | 603 title = "Configuration for "..self.jid, |
| 604 instructions = "Complete and submit this form to configure the room.", | 604 instructions = "Complete and submit this form to configure the room.", |
| 605 { | 605 { |
| 606 name = 'FORM_TYPE', | 606 name = 'FORM_TYPE', |
| 669 type = 'text-single', | 669 type = 'text-single', |
| 670 label = 'Maximum Number of History Messages Returned by Room', | 670 label = 'Maximum Number of History Messages Returned by Room', |
| 671 value = tostring(self:get_historylength()) | 671 value = tostring(self:get_historylength()) |
| 672 } | 672 } |
| 673 }); | 673 }); |
| 674 return module:fire_event("muc-config-form", { room = self, form = form }) or form; | 674 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; |
| 675 end | 675 end |
| 676 | 676 |
| 677 function room_mt:process_form(origin, stanza) | 677 function room_mt:process_form(origin, stanza) |
| 678 local query = stanza.tags[1]; | 678 local query = stanza.tags[1]; |
| 679 local form; | 679 local form; |
| 680 for _, tag in ipairs(query.tags) do if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then form = tag; break; end end | 680 for _, tag in ipairs(query.tags) do if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then form = tag; break; end end |
| 681 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end | 681 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end |
| 682 if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end | 682 if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end |
| 683 if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); return; end | 683 if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); return; end |
| 684 | 684 |
| 685 local fields = self:get_form_layout():data(form); | 685 local fields = self:get_form_layout(stanza.attr.from):data(form); |
| 686 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 | 686 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 |
| 687 | 687 |
| 688 | 688 |
| 689 local changed = {}; | 689 local changed = {}; |
| 690 | 690 |
