mod_vcard_muc: Pass room object around instead of JID, hopefully fixing traceback
authorMatthew Wild <mwild1@gmail.com>
Tue, 15 Dec 2020 10:49:11 +0000
changeset 4304 3f3b672b7616
parent 4303 8006da2cf44c
child 4305 bcb2b9adfcde
mod_vcard_muc: Pass room object around instead of JID, hopefully fixing traceback More efficient to pass the object around instead of using the JID and looking up the object when needed. It seems in some (undetermined) cases get_room_from_jid(room.jid) is nil.
mod_vcard_muc/mod_vcard_muc.lua
--- a/mod_vcard_muc/mod_vcard_muc.lua	Tue Dec 15 11:26:29 2020 +0100
+++ b/mod_vcard_muc/mod_vcard_muc.lua	Tue Dec 15 10:49:11 2020 +0000
@@ -39,11 +39,9 @@
 
 end
 
-local function broadcast_presence(room_jid, to)
-	local room = get_room_from_jid(room_jid);
-
+local function broadcast_presence(room, to)
 	local photo_hash = get_photo_hash(room);
-	local presence_vcard = st.presence({to = to, from = room_jid})
+	local presence_vcard = st.presence({to = to, from = room.jid})
 		:tag("x", { xmlns = "vcard-temp:x:update" })
 			:tag("photo"):text(photo_hash):up();
 
@@ -81,7 +79,7 @@
 		if from_affiliation == "owner" then
 			if vcards:set(room_node, st.preserialize(stanza.tags[1])) then
 				session.send(st.reply(stanza):tag("vCard", { xmlns = "vcard-temp" }));
-				broadcast_presence(room_jid, nil)
+				broadcast_presence(room, nil)
 
 				room:broadcast_message(st.message({ from = room.jid, type = "groupchat" })
 					:tag("x", { xmlns = "http://jabber.org/protocol/muc#user" })
@@ -112,5 +110,5 @@
 end);
 
 module:hook("muc-occupant-session-new", function(event)
-	broadcast_presence(event.room.jid, event.jid);
+	broadcast_presence(event.room, event.jid);
 end)