MUC: Add method for getting the occupant id salt to allow reuse
authorKim Alvefur <zash@zash.se>
Tue, 05 Oct 2021 18:13:51 +0200
changeset 12112 e9882c4c397f
parent 12111 8a5a9c1adb90
child 12113 83bec90a352c
MUC: Add method for getting the occupant id salt to allow reuse
plugins/muc/mod_muc.lua
plugins/muc/occupant_id.lib.lua
--- a/plugins/muc/mod_muc.lua	Wed Dec 22 18:34:11 2021 +0100
+++ b/plugins/muc/mod_muc.lua	Tue Oct 05 18:13:51 2021 +0200
@@ -92,6 +92,7 @@
 room_mt.get_valid_broadcast_roles = presence_broadcast.get_valid_broadcast_roles;
 
 local occupant_id = module:require "muc/occupant_id";
+room_mt.get_salt = occupant_id.get_room_salt;
 room_mt.get_occupant_id = occupant_id.get_occupant_id;
 
 local jid_split = require "util.jid".split;
--- a/plugins/muc/occupant_id.lib.lua	Wed Dec 22 18:34:11 2021 +0100
+++ b/plugins/muc/occupant_id.lib.lua	Tue Oct 05 18:13:51 2021 +0200
@@ -10,16 +10,21 @@
 
 local xmlns_occupant_id = "urn:xmpp:occupant-id:0";
 
+local function get_room_salt(room)
+	local salt = room._data.occupant_id_salt;
+	if not salt then
+		salt = uuid.generate();
+		room._data.occupant_id_salt = salt;
+	end
+	return salt;
+end
+
 local function get_occupant_id(room, occupant)
 	if occupant.stable_id then
 		return occupant.stable_id;
 	end
 
-	local salt = room._data.occupant_id_salt;
-	if not salt then
-		salt = uuid.generate();
-		room._data.occupant_id_salt = salt;
-	end
+	local salt = get_room_salt(room)
 
 	occupant.stable_id = b64encode(hmac_sha256(occupant.bare_jid, salt));
 
@@ -66,5 +71,6 @@
 end
 
 return {
+	get_room_salt = get_room_salt;
 	get_occupant_id = get_occupant_id;
 };