local persistent_rooms_storage = module:open_store("persistent");
local persistent_rooms = module:open_store("persistent", "map");
local room_configs = module:open_store("config");
+local room_state = module:open_store("state");
local room_items_cache = {};
-local function room_save(room, forced)
+local function room_save(room, forced, savestate)
local node = jid_split(room.jid);
local is_persistent = persistent.get(room);
room_items_cache[room.jid] = room:get_public() and room:get_name() or nil;
- if is_persistent or forced then
+ if is_persistent or savestate then
persistent_rooms:set(nil, room.jid, true);
- local data = room:freeze(forced);
+ local data, state = room:freeze(savestate);
+ room_state:set(node, state);
return room_configs:set(node, data);
- else
+ elseif forced then
persistent_rooms:set(nil, room.jid, nil);
+ room_state:set(node, nil);
return room_configs:set(node, nil);
end
end
local rooms = cache.new(module:get_option_number("muc_room_cache_size", 100), function (_, room)
module:log("debug", "%s evicted", room);
- room_save(room, true); -- Force to disk
+ room_save(room, nil, true); -- Force to disk
end);
-- Automatically destroy empty non-persistent rooms
local function restore_room(jid)
local node = jid_split(jid);
local data = room_configs:get(node);
+ local state = room_state:get(node);
if data then
- local room = muclib.restore_room(data);
+ local room = muclib.restore_room(data, state);
track_room(room);
return room;
end
function module.unload()
for room in rooms:values() do
- room:save(true);
+ room:save(nil, true);
forget_room(room);
end
end
end
end);
-module:hook("muc-room-pre-create", function(event)
+module:hook("muc-room-created", function(event)
track_room(event.room);
end, -1000);
function shutdown_component()
for room in each_room(true) do
- room:save(true);
+ room:save(nil, true);
end
end
module:hook_global("server-stopping", shutdown_component);