Changeset

7368:4e24aff1e4df

MUC: Flatten format of serialized rooms
author Kim Alvefur <zash@zash.se>
date Mon, 18 Apr 2016 19:29:23 +0200
parents 7367:2aef5e8b69e9
children 7369:c5cae59831d7
files plugins/muc/muc.lib.lua
diffstat 1 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Mon Apr 18 19:26:26 2016 +0200
+++ b/plugins/muc/muc.lib.lua	Mon Apr 18 19:29:23 2016 +0200
@@ -1245,17 +1245,33 @@
 end
 
 function room_mt:freeze()
-	return {
-		jid = self.jid;
+	local frozen = {
+		_jid = self.jid;
 		_data = self._data;
-		_affiliations = self._affiliations;
-	}
+	};
+	for user, affiliation in pairs(self._affiliations) do
+		frozen[user] = affiliation;
+	end
+	return frozen;
 end
 
 function _M.restore_room(frozen)
-	local room_jid = frozen.jid;
+	-- 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 = _M.new_room(room_jid, frozen._data);
-	room._affiliations = frozen._affiliations;
+
+	for jid, data in pairs(frozen) do
+		local node, host = jid_split(jid);
+		if node or host:sub(1,1) ~= "_" then
+			room._affiliations[jid] = data;
+		end
+	end
 	return room;
 end