MUC: Fix compatibility with new and old storage format
authorKim Alvefur <zash@zash.se>
Wed, 24 Aug 2016 00:34:46 +0200
changeset 7634 f50c039d6bb1
parent 7633 abe2697b5e92
child 7636 9ddc9401911f
MUC: Fix compatibility with new and old storage format
plugins/muc/muc.lib.lua
--- a/plugins/muc/muc.lib.lua	Tue Aug 23 20:31:14 2016 +0200
+++ b/plugins/muc/muc.lib.lua	Wed Aug 24 00:34:46 2016 +0200
@@ -1345,14 +1345,7 @@
 end
 
 function _M.restore_room(frozen, state)
-	-- COMPAT
-	if frozen.jid and frozen._affiliations then
-		local room = _M.new_room(frozen.jid, frozen._data);
-		room._affiliations = frozen._affiliations;
-		return room;
-	end
-
-	local room_jid = frozen._jid;
+	local room_jid = frozen._jid or frozen.jid;
 	local room = _M.new_room(room_jid, frozen._data);
 
 	if state and state._last_message and state._last_message_at then
@@ -1365,11 +1358,16 @@
 	local occupants = {};
 	local occupant_sessions = {};
 	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;
+
+	if frozen.jid and frozen._affiliations then
+		room._affiliations = frozen._affiliations;
+	else
+		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
 	end
 	for jid, data in pairs(state or frozen) do