Comparison

plugins/muc/muc.lib.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 7416:c33a1d6da016
comparison
equal deleted inserted replaced
7414:1b62c89014c4 7415:cbb05b454c13
1302 _affiliations = {}; 1302 _affiliations = {};
1303 }, room_mt); 1303 }, room_mt);
1304 end 1304 end
1305 1305
1306 function room_mt:freeze(live) 1306 function room_mt:freeze(live)
1307 local frozen = { 1307 local frozen, state = {
1308 _jid = self.jid; 1308 _jid = self.jid;
1309 _data = self._data; 1309 _data = self._data;
1310 }; 1310 };
1311 for user, affiliation in pairs(self._affiliations) do 1311 for user, affiliation in pairs(self._affiliations) do
1312 frozen[user] = affiliation; 1312 frozen[user] = affiliation;
1313 end 1313 end
1314 if live then 1314 if live then
1315 state = {};
1315 for nick, occupant in self:each_occupant() do 1316 for nick, occupant in self:each_occupant() do
1316 frozen[nick] = { 1317 state[nick] = {
1317 bare_jid = occupant.bare_jid; 1318 bare_jid = occupant.bare_jid;
1318 role = occupant.role; 1319 role = occupant.role;
1319 jid = occupant.jid; 1320 jid = occupant.jid;
1320 } 1321 }
1321 for jid, presence in occupant:each_session() do 1322 for jid, presence in occupant:each_session() do
1322 frozen[jid] = st.preserialize(presence); 1323 state[jid] = st.preserialize(presence);
1323 end 1324 end
1324 end 1325 end
1325 local history = self._history; 1326 local history = self._history;
1326 if history then 1327 if history then
1327 frozen._last_message = st.preserialize(history[#history].stanza); 1328 state._last_message = st.preserialize(history[#history].stanza);
1328 frozen._last_message_at = history[#history].timestamp; 1329 state._last_message_at = history[#history].timestamp;
1329 end 1330 end
1330 end 1331 end
1331 return frozen; 1332 return frozen, state;
1332 end 1333 end
1333 1334
1334 function _M.restore_room(frozen) 1335 function _M.restore_room(frozen, state)
1335 -- COMPAT 1336 -- COMPAT
1336 if frozen.jid and frozen._affiliations then 1337 if frozen.jid and frozen._affiliations then
1337 local room = _M.new_room(frozen.jid, frozen._data); 1338 local room = _M.new_room(frozen.jid, frozen._data);
1338 room._affiliations = frozen._affiliations; 1339 room._affiliations = frozen._affiliations;
1339 return room; 1340 return room;
1352 local occupants = {}; 1353 local occupants = {};
1353 local occupant_sessions = {}; 1354 local occupant_sessions = {};
1354 local room_name, room_host = jid_split(room_jid); 1355 local room_name, room_host = jid_split(room_jid);
1355 for jid, data in pairs(frozen) do 1356 for jid, data in pairs(frozen) do
1356 local node, host, resource = jid_split(jid); 1357 local node, host, resource = jid_split(jid);
1358 if host:sub(1,1) ~= "_" and not resource and type(data) == "string" then
1359 -- bare jid: affiliation
1360 room._affiliations[jid] = data;
1361 end
1362 end
1363 for jid, data in pairs(state or frozen) do
1364 local node, host, resource = jid_split(jid);
1357 if node or host:sub(1,1) ~= "_" then 1365 if node or host:sub(1,1) ~= "_" then
1358 if not resource and type(data) == "string" then 1366 if host == room_host and node == room_name and resource and type(data) == "table" then
1359 -- bare jid: affiliation
1360 room._affiliations[jid] = data;
1361 elseif host == room_host and node == room_name and resource and type(data) == "table" then
1362 -- full room jid: bare real jid and role 1367 -- full room jid: bare real jid and role
1363 local bare_jid = data.bare_jid; 1368 local bare_jid = data.bare_jid;
1364 local occupant = occupant_lib.new(bare_jid, jid); 1369 local occupant = occupant_lib.new(bare_jid, jid);
1365 occupant.jid = data.jid; 1370 occupant.jid = data.jid;
1366 occupant.role = data.role; 1371 occupant.role = data.role;