Mercurial > prosody-hg
comparison plugins/muc/mod_muc.lua @ 7414:1b62c89014c4
MUC: Separate force-save parameter from save-entire-state flag
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 29 Apr 2016 16:54:45 +0200 |
| parents | f385cd6127b2 |
| children | cbb05b454c13 |
comparison
equal
deleted
inserted
replaced
| 7413:228396da1e27 | 7414:1b62c89014c4 |
|---|---|
| 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 | 97 |
| 98 local room_items_cache = {}; | 98 local room_items_cache = {}; |
| 99 | 99 |
| 100 local function room_save(room, forced) | 100 local function room_save(room, forced, savestate) |
| 101 local node = jid_split(room.jid); | 101 local node = jid_split(room.jid); |
| 102 local is_persistent = persistent.get(room); | 102 local is_persistent = persistent.get(room); |
| 103 room_items_cache[room.jid] = room:get_public() and room:get_name() or nil; | 103 room_items_cache[room.jid] = room:get_public() and room:get_name() or nil; |
| 104 if is_persistent or forced then | 104 if is_persistent or savestate then |
| 105 persistent_rooms:set(nil, room.jid, true); | 105 persistent_rooms:set(nil, room.jid, true); |
| 106 local data = room:freeze(forced); | 106 local data = room:freeze(savestate); |
| 107 return room_configs:set(node, data); | 107 return room_configs:set(node, data); |
| 108 else | 108 elseif forced then |
| 109 persistent_rooms:set(nil, room.jid, nil); | 109 persistent_rooms:set(nil, room.jid, nil); |
| 110 return room_configs:set(node, nil); | 110 return room_configs:set(node, nil); |
| 111 end | 111 end |
| 112 end | 112 end |
| 113 | 113 |
| 114 local rooms = cache.new(module:get_option_number("muc_room_cache_size", 100), function (_, room) | 114 local rooms = cache.new(module:get_option_number("muc_room_cache_size", 100), function (_, room) |
| 115 module:log("debug", "%s evicted", room); | 115 module:log("debug", "%s evicted", room); |
| 116 room_save(room, true); -- Force to disk | 116 room_save(room, nil, true); -- Force to disk |
| 117 end); | 117 end); |
| 118 | 118 |
| 119 -- Automatically destroy empty non-persistent rooms | 119 -- Automatically destroy empty non-persistent rooms |
| 120 module:hook("muc-occupant-left",function(event) | 120 module:hook("muc-occupant-left",function(event) |
| 121 local room = event.room | 121 local room = event.room |
| 153 room_items_cache[room.jid] = nil; | 153 room_items_cache[room.jid] = nil; |
| 154 end | 154 end |
| 155 | 155 |
| 156 function module.unload() | 156 function module.unload() |
| 157 for room in rooms:values() do | 157 for room in rooms:values() do |
| 158 room:save(true); | 158 room:save(nil, true); |
| 159 forget_room(room); | 159 forget_room(room); |
| 160 end | 160 end |
| 161 end | 161 end |
| 162 | 162 |
| 163 function get_room_from_jid(room_jid) | 163 function get_room_from_jid(room_jid) |
| 285 end, -2) | 285 end, -2) |
| 286 end | 286 end |
| 287 | 287 |
| 288 function shutdown_component() | 288 function shutdown_component() |
| 289 for room in each_room(true) do | 289 for room in each_room(true) do |
| 290 room:save(true); | 290 room:save(nil, true); |
| 291 end | 291 end |
| 292 end | 292 end |
| 293 module:hook_global("server-stopping", shutdown_component); | 293 module:hook_global("server-stopping", shutdown_component); |
| 294 | 294 |
| 295 do -- Ad-hoc commands | 295 do -- Ad-hoc commands |
