changeset 13905:0e346f4d88ce

MUC: Add get_occupant_id_from_jid() method, which works on real JIDs This is useful to get the occupant ID of someone who is affiliated, but not currently joined to the room.
author Matthew Wild <mwild1@gmail.com>
date Fri, 20 Jun 2025 18:55:39 +0100
parents f8779be95156
children 0749265327d2
files plugins/muc/mod_muc.lua plugins/muc/occupant_id.lib.lua
diffstat 2 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/mod_muc.lua	Mon Nov 11 12:52:54 2024 +0000
+++ b/plugins/muc/mod_muc.lua	Fri Jun 20 18:55:39 2025 +0100
@@ -100,6 +100,7 @@
 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;
+room_mt.get_occupant_id_from_jid = occupant_id.get_occupant_id_from_jid;
 
 local jid_split = require "prosody.util.jid".split;
 local jid_prep = require "prosody.util.jid".prep;
--- a/plugins/muc/occupant_id.lib.lua	Mon Nov 11 12:52:54 2024 +0000
+++ b/plugins/muc/occupant_id.lib.lua	Fri Jun 20 18:55:39 2025 +0100
@@ -31,6 +31,11 @@
 	return occupant.stable_id;
 end
 
+local function get_occupant_id_from_jid(room, real_bare_jid)
+	local salt = get_room_salt(room)
+	return b64encode(hmac_sha256(real_bare_jid, salt));
+end
+
 local function update_occupant(event)
 	local stanza, room, occupant, dest_occupant = event.stanza, event.room, event.occupant, event.dest_occupant;
 
@@ -73,4 +78,5 @@
 return {
 	get_room_salt = get_room_salt;
 	get_occupant_id = get_occupant_id;
+	get_occupant_id_from_jid = get_occupant_id_from_jid;
 };