Comparison

plugins/muc/mod_muc.lua @ 6247:851647eb6657

plugins/muc/mod_muc: Place adhoc section into own scope
author daurnimator <quae@daurnimator.com>
date Wed, 30 Apr 2014 12:43:47 -0400
parent 6246:45b8ad2b14c5
child 6248:4569b8cbd269
comparison
equal deleted inserted replaced
6246:45b8ad2b14c5 6247:851647eb6657
3 -- Copyright (C) 2008-2010 Waqas Hussain 3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- 4 --
5 -- This project is MIT/X11 licensed. Please see the 5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8
9 local array = require "util.array";
10 8
11 if module:get_host_type() ~= "component" then 9 if module:get_host_type() ~= "component" then
12 error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0); 10 error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0);
13 end 11 end
14 12
211 room:clear(x); 209 room:clear(x);
212 end 210 end
213 end 211 end
214 module:hook_global("server-stopping", shutdown_component); 212 module:hook_global("server-stopping", shutdown_component);
215 213
216 -- Ad-hoc commands 214 do -- Ad-hoc commands
217 module:depends("adhoc") 215 module:depends "adhoc";
218 local t_concat = table.concat; 216 local t_concat = table.concat;
219 local adhoc_new = module:require "adhoc".new; 217 local adhoc_new = module:require "adhoc".new;
220 local adhoc_initial = require "util.adhoc".new_initial_data_form; 218 local adhoc_initial = require "util.adhoc".new_initial_data_form;
221 local dataforms_new = require "util.dataforms".new; 219 local array = require "util.array";
222 220 local dataforms_new = require "util.dataforms".new;
223 local destroy_rooms_layout = dataforms_new { 221
224 title = "Destroy rooms"; 222 local destroy_rooms_layout = dataforms_new {
225 instructions = "Select the rooms to destroy"; 223 title = "Destroy rooms";
226 224 instructions = "Select the rooms to destroy";
227 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/muc#destroy" }; 225
228 { name = "rooms", type = "list-multi", required = true, label = "Rooms to destroy:"}; 226 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/muc#destroy" };
229 }; 227 { name = "rooms", type = "list-multi", required = true, label = "Rooms to destroy:"};
230 228 };
231 local destroy_rooms_handler = adhoc_initial(destroy_rooms_layout, function() 229
232 return { rooms = array.collect(each_room):pluck("jid"):sort(); }; 230 local destroy_rooms_handler = adhoc_initial(destroy_rooms_layout, function()
233 end, function(fields, errors) 231 return { rooms = array.collect(each_room):pluck("jid"):sort(); };
234 if errors then 232 end, function(fields, errors)
235 local errmsg = {}; 233 if errors then
236 for name, err in pairs(errors) do 234 local errmsg = {};
237 errmsg[#errmsg + 1] = name .. ": " .. err; 235 for name, err in pairs(errors) do
238 end 236 errmsg[#errmsg + 1] = name .. ": " .. err;
239 return { status = "completed", error = { message = t_concat(errmsg, "\n") } }; 237 end
240 end 238 return { status = "completed", error = { message = t_concat(errmsg, "\n") } };
241 for _, room in ipairs(fields.rooms) do 239 end
242 get_room_from_jid(room):destroy(); 240 for _, room in ipairs(fields.rooms) do
243 end 241 get_room_from_jid(room):destroy();
244 return { status = "completed", info = "The following rooms were destroyed:\n"..t_concat(fields.rooms, "\n") }; 242 end
245 end); 243 return { status = "completed", info = "The following rooms were destroyed:\n"..t_concat(fields.rooms, "\n") };
246 local destroy_rooms_desc = adhoc_new("Destroy Rooms", "http://prosody.im/protocol/muc#destroy", destroy_rooms_handler, "admin"); 244 end);
247 245 local destroy_rooms_desc = adhoc_new("Destroy Rooms", "http://prosody.im/protocol/muc#destroy", destroy_rooms_handler, "admin");
248 module:provides("adhoc", destroy_rooms_desc); 246
247 module:provides("adhoc", destroy_rooms_desc);
248 end