Comparison

plugins/muc/mod_muc.lua @ 5692:24e7e58155d8

mod_muc: Add Ad-Hoc command to destroy MUC rooms
author Florian Zeitz <florob@babelmonkeys.de>
date Wed, 05 Jun 2013 00:05:03 +0200
parent 5691:18a115beeebe
child 5776:bd0ff8ae98a8
comparison
equal deleted inserted replaced
5691:18a115beeebe 5692:24e7e58155d8
222 shutdown_room(host_room, stanza); 222 shutdown_room(host_room, stanza);
223 end 223 end
224 end 224 end
225 module.unload = shutdown_component; 225 module.unload = shutdown_component;
226 module:hook_global("server-stopping", shutdown_component); 226 module:hook_global("server-stopping", shutdown_component);
227
228 -- Ad-hoc commands
229 module:depends("adhoc")
230 local t_concat = table.concat;
231 local keys = require "util.iterators".keys;
232 local adhoc_new = module:require "adhoc".new;
233 local adhoc_initial = require "util.adhoc".new_initial_data_form;
234 local dataforms_new = require "util.dataforms".new;
235
236 local destroy_rooms_layout = dataforms_new {
237 title = "Destroy rooms";
238 instructions = "Select the rooms to destroy";
239
240 { name = "FORM_TYPE", type = "hidden", value = "http://prosody.im/protocol/muc#destroy" };
241 { name = "rooms", type = "list-multi", required = true, label = "Rooms to destroy:"};
242 };
243
244 local destroy_rooms_handler = adhoc_initial(destroy_rooms_layout, function()
245 return { rooms = array.collect(keys(rooms)):sort() };
246 end, function(fields, errors)
247 if errors then
248 local errmsg = {};
249 for name, err in pairs(errors) do
250 errmsg[#errmsg + 1] = name .. ": " .. err;
251 end
252 return { status = "completed", error = { message = t_concat(errmsg, "\n") } };
253 end
254 for _, room in ipairs(fields.rooms) do
255 rooms[room]:destroy();
256 rooms[room] = nil;
257 end
258 return { status = "completed", info = "The following rooms were destroyed:\n"..t_concat(fields.rooms, "\n") };
259 end);
260 local destroy_rooms_desc = adhoc_new("Destroy Rooms", "http://prosody.im/protocol/muc#destroy", destroy_rooms_handler, "admin");
261
262 module:provides("adhoc", destroy_rooms_desc);