Comparison

plugins/muc/mod_muc.lua @ 6241:6b4ff34dc8ea

plugins/muc/mod_muc: Use module:shared instead of save/restore
author daurnimator <quae@daurnimator.com>
date Tue, 29 Apr 2014 17:18:14 -0400
parent 6240:641756a6a5f7
child 6243:b7c95e9c13de
comparison
equal deleted inserted replaced
6240:641756a6a5f7 6241:6b4ff34dc8ea
28 local jid_bare = require "util.jid".bare; 28 local jid_bare = require "util.jid".bare;
29 local st = require "util.stanza"; 29 local st = require "util.stanza";
30 local um_is_admin = require "core.usermanager".is_admin; 30 local um_is_admin = require "core.usermanager".is_admin;
31 local hosts = prosody.hosts; 31 local hosts = prosody.hosts;
32 32
33 rooms = {}; 33 local rooms = module:shared "rooms";
34 local rooms = rooms; 34 _G.rooms = rooms;
35
36 35
37 module:depends("disco"); 36 module:depends("disco");
38 module:add_identity("conference", "text", module:get_option_string("name", "Prosody Chatrooms")); 37 module:add_identity("conference", "text", module:get_option_string("name", "Prosody Chatrooms"));
39 module:add_feature("http://jabber.org/protocol/muc"); 38 module:add_feature("http://jabber.org/protocol/muc");
40 module:depends "muc_unique" 39 module:depends "muc_unique"
201 end 200 end
202 return room[method](room, origin, stanza); 201 return room[method](room, origin, stanza);
203 end, -2) 202 end, -2)
204 end 203 end
205 204
206 local saved = false;
207 module.save = function()
208 saved = true;
209 return {rooms = rooms};
210 end
211 module.restore = function(data)
212 for jid, oldroom in pairs(data.rooms or {}) do
213 local room = create_room(jid);
214 room._jid_nick = oldroom._jid_nick;
215 room._occupants = oldroom._occupants;
216 room._data = oldroom._data;
217 room._affiliations = oldroom._affiliations;
218 end
219 end
220
221 function shutdown_component() 205 function shutdown_component()
222 if not saved then 206 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"})
223 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) 207 :tag("status", { code = "332"}):up();
224 :tag("status", { code = "332"}):up(); 208 for roomjid, room in pairs(rooms) do
225 for roomjid, room in pairs(rooms) do 209 room:clear(x);
226 room:clear(x); 210 end
227 end 211 end
228 end
229 end
230 module.unload = shutdown_component;
231 module:hook_global("server-stopping", shutdown_component); 212 module:hook_global("server-stopping", shutdown_component);
232 213
233 -- Ad-hoc commands 214 -- Ad-hoc commands
234 module:depends("adhoc") 215 module:depends("adhoc")
235 local t_concat = table.concat; 216 local t_concat = table.concat;