1012 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then |
1012 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then |
1013 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); |
1013 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); |
1014 return true; |
1014 return true; |
1015 end |
1015 end |
1016 |
1016 |
1017 local changed = {}; |
1017 local event = {room = self; origin = origin; stanza = stanza; fields = fields; status_codes = {};}; |
1018 |
1018 function event.update_option(name, field, allowed) |
1019 local function handle_option(name, field, allowed) |
|
1020 local new = fields[field]; |
1019 local new = fields[field]; |
1021 if new == nil then return; end |
1020 if new == nil then return; end |
1022 if allowed and not allowed[new] then return; end |
1021 if allowed and not allowed[new] then return; end |
1023 if new == self["get_"..name](self) then return; end |
1022 if new == self["get_"..name](self) then return; end |
1024 changed[name] = true; |
1023 event.status_codes["104"] = true; |
1025 self["set_"..name](self, new); |
1024 self["set_"..name](self, new); |
1026 end |
1025 return true; |
1027 |
1026 end |
1028 local event = { room = self, fields = fields, changed = changed, stanza = stanza, origin = origin, update_option = handle_option }; |
|
1029 module:fire_event("muc-config-submitted", event); |
1027 module:fire_event("muc-config-submitted", event); |
1030 |
1028 |
1031 if self.save then self:save(true); end |
1029 if self.save then self:save(true); end |
1032 if self:is_locked() then |
1030 if self:is_locked() then |
1033 self:unlock(); |
1031 self:unlock(); |
1034 end |
1032 end |
1035 origin.send(st.reply(stanza)); |
1033 origin.send(st.reply(stanza)); |
1036 |
1034 |
1037 if next(changed) then |
1035 if next(event.status_codes) then |
1038 local msg = st.message({type='groupchat', from=self.jid}) |
1036 local msg = st.message({type='groupchat', from=self.jid}) |
1039 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
1037 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
1040 :tag('status', {code = '104'}):up() |
1038 for code in pairs(event.status_codes) do |
1041 :up(); |
1039 msg:tag("status", {code = code;}):up(); |
1042 if changed.whois then |
1040 end |
1043 local code = (self:get_whois() == 'moderators') and "173" or "172"; |
1041 msg:up(); |
1044 msg.tags[1]:tag('status', {code = code}):up(); |
|
1045 end |
|
1046 self:broadcast_message(msg, false) |
1042 self:broadcast_message(msg, false) |
1047 end |
1043 end |
1048 else |
1044 else |
1049 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); |
1045 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); |
1050 end |
1046 end |
1073 end); |
1069 end); |
1074 module:hook("muc-config-submitted", function(event) |
1070 module:hook("muc-config-submitted", function(event) |
1075 event.update_option("historylength", "muc#roomconfig_historylength"); |
1071 event.update_option("historylength", "muc#roomconfig_historylength"); |
1076 end); |
1072 end); |
1077 module:hook("muc-config-submitted", function(event) |
1073 module:hook("muc-config-submitted", function(event) |
1078 event.update_option("whois", "muc#roomconfig_whois", valid_whois); |
1074 if event.update_option("whois", "muc#roomconfig_whois", valid_whois) then |
|
1075 local code = (event.room:get_whois() == 'moderators') and "173" or "172"; |
|
1076 event.status_codes[code] = true; |
|
1077 end |
1079 end); |
1078 end); |
1080 module:hook("muc-config-submitted", function(event) |
1079 module:hook("muc-config-submitted", function(event) |
1081 event.update_option("password", "muc#roomconfig_roomsecret"); |
1080 event.update_option("password", "muc#roomconfig_roomsecret"); |
1082 end); |
1081 end); |
1083 |
1082 |