Comparison

plugins/muc/mod_muc.lua @ 7415:cbb05b454c13

MUC: Separate config from live state
author Kim Alvefur <zash@zash.se>
date Fri, 29 Apr 2016 17:04:05 +0200
parent 7414:1b62c89014c4
child 7417:4c8ee8175f5e
comparison
equal deleted inserted replaced
7414:1b62c89014c4 7415:cbb05b454c13
92 end 92 end
93 93
94 local persistent_rooms_storage = module:open_store("persistent"); 94 local persistent_rooms_storage = module:open_store("persistent");
95 local persistent_rooms = module:open_store("persistent", "map"); 95 local persistent_rooms = module:open_store("persistent", "map");
96 local room_configs = module:open_store("config"); 96 local room_configs = module:open_store("config");
97 local room_state = module:open_store("state");
97 98
98 local room_items_cache = {}; 99 local room_items_cache = {};
99 100
100 local function room_save(room, forced, savestate) 101 local function room_save(room, forced, savestate)
101 local node = jid_split(room.jid); 102 local node = jid_split(room.jid);
102 local is_persistent = persistent.get(room); 103 local is_persistent = persistent.get(room);
103 room_items_cache[room.jid] = room:get_public() and room:get_name() or nil; 104 room_items_cache[room.jid] = room:get_public() and room:get_name() or nil;
104 if is_persistent or savestate then 105 if is_persistent or savestate then
105 persistent_rooms:set(nil, room.jid, true); 106 persistent_rooms:set(nil, room.jid, true);
106 local data = room:freeze(savestate); 107 local data, state = room:freeze(savestate);
108 room_state:set(node, state);
107 return room_configs:set(node, data); 109 return room_configs:set(node, data);
108 elseif forced then 110 elseif forced then
109 persistent_rooms:set(nil, room.jid, nil); 111 persistent_rooms:set(nil, room.jid, nil);
112 room_state:set(node, nil);
110 return room_configs:set(node, nil); 113 return room_configs:set(node, nil);
111 end 114 end
112 end 115 end
113 116
114 local rooms = cache.new(module:get_option_number("muc_room_cache_size", 100), function (_, room) 117 local rooms = cache.new(module:get_option_number("muc_room_cache_size", 100), function (_, room)
131 end 134 end
132 135
133 local function restore_room(jid) 136 local function restore_room(jid)
134 local node = jid_split(jid); 137 local node = jid_split(jid);
135 local data = room_configs:get(node); 138 local data = room_configs:get(node);
139 local state = room_state:get(node);
136 if data then 140 if data then
137 local room = muclib.restore_room(data); 141 local room = muclib.restore_room(data, state);
138 track_room(room); 142 track_room(room);
139 return room; 143 return room;
140 end 144 end
141 end 145 end
142 146