aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-04-29 17:04:05 +0200
committerKim Alvefur <zash@zash.se>2016-04-29 17:04:05 +0200
commite1c897b8e3251493bfa2e9df38b7da90d94d3da8 (patch)
tree498ecaf6ffc1cf0cb11c8b2d3f410d685d670c28
parente4a91c1d8f3d8f1a673b220e6812c7038964525b (diff)
downloadprosody-e1c897b8e3251493bfa2e9df38b7da90d94d3da8.tar.gz
prosody-e1c897b8e3251493bfa2e9df38b7da90d94d3da8.zip
MUC: Separate config from live state
-rw-r--r--plugins/muc/mod_muc.lua8
-rw-r--r--plugins/muc/muc.lib.lua27
2 files changed, 22 insertions, 13 deletions
diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua
index 5b342c02..c1ecb4f1 100644
--- a/plugins/muc/mod_muc.lua
+++ b/plugins/muc/mod_muc.lua
@@ -94,6 +94,7 @@ end
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 = {};
@@ -103,10 +104,12 @@ local function room_save(room, forced, savestate)
room_items_cache[room.jid] = room:get_public() and room:get_name() or nil;
if is_persistent or savestate then
persistent_rooms:set(nil, room.jid, true);
- local data = room:freeze(savestate);
+ local data, state = room:freeze(savestate);
+ room_state:set(node, state);
return room_configs:set(node, data);
elseif forced then
persistent_rooms:set(nil, room.jid, nil);
+ room_state:set(node, nil);
return room_configs:set(node, nil);
end
end
@@ -133,8 +136,9 @@ end
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
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index eeb531a9..fea0ba93 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -1304,7 +1304,7 @@ function _M.new_room(jid, config)
end
function room_mt:freeze(live)
- local frozen = {
+ local frozen, state = {
_jid = self.jid;
_data = self._data;
};
@@ -1312,26 +1312,27 @@ function room_mt:freeze(live)
frozen[user] = affiliation;
end
if live then
+ state = {};
for nick, occupant in self:each_occupant() do
- frozen[nick] = {
+ state[nick] = {
bare_jid = occupant.bare_jid;
role = occupant.role;
jid = occupant.jid;
}
for jid, presence in occupant:each_session() do
- frozen[jid] = st.preserialize(presence);
+ state[jid] = st.preserialize(presence);
end
end
local history = self._history;
if history then
- frozen._last_message = st.preserialize(history[#history].stanza);
- frozen._last_message_at = history[#history].timestamp;
+ state._last_message = st.preserialize(history[#history].stanza);
+ state._last_message_at = history[#history].timestamp;
end
end
- return frozen;
+ return frozen, state;
end
-function _M.restore_room(frozen)
+function _M.restore_room(frozen, state)
-- COMPAT
if frozen.jid and frozen._affiliations then
local room = _M.new_room(frozen.jid, frozen._data);
@@ -1354,11 +1355,15 @@ function _M.restore_room(frozen)
local room_name, room_host = jid_split(room_jid);
for jid, data in pairs(frozen) do
local node, host, resource = jid_split(jid);
+ if host:sub(1,1) ~= "_" and not resource and type(data) == "string" then
+ -- bare jid: affiliation
+ room._affiliations[jid] = data;
+ end
+ end
+ for jid, data in pairs(state or frozen) do
+ local node, host, resource = jid_split(jid);
if node or host:sub(1,1) ~= "_" then
- if not resource and type(data) == "string" then
- -- bare jid: affiliation
- room._affiliations[jid] = data;
- elseif host == room_host and node == room_name and resource and type(data) == "table" then
+ if host == room_host and node == room_name and resource and type(data) == "table" then
-- full room jid: bare real jid and role
local bare_jid = data.bare_jid;
local occupant = occupant_lib.new(bare_jid, jid);