Comparison

mod_vcard_muc/mod_vcard_muc.lua @ 4300:3f3b672b7616

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.
author Matthew Wild <mwild1@gmail.com>
date Tue, 15 Dec 2020 10:49:11 +0000
parent 4043:a533abe6ffd0
child 5290:dddac5a3f447
comparison
equal deleted inserted replaced
4299:8006da2cf44c 4300:3f3b672b7616
37 end 37 end
38 end 38 end
39 39
40 end 40 end
41 41
42 local function broadcast_presence(room_jid, to) 42 local function broadcast_presence(room, to)
43 local room = get_room_from_jid(room_jid);
44
45 local photo_hash = get_photo_hash(room); 43 local photo_hash = get_photo_hash(room);
46 local presence_vcard = st.presence({to = to, from = room_jid}) 44 local presence_vcard = st.presence({to = to, from = room.jid})
47 :tag("x", { xmlns = "vcard-temp:x:update" }) 45 :tag("x", { xmlns = "vcard-temp:x:update" })
48 :tag("photo"):text(photo_hash):up(); 46 :tag("photo"):text(photo_hash):up();
49 47
50 if to == nil then 48 if to == nil then
51 room:broadcast_message(presence_vcard); 49 room:broadcast_message(presence_vcard);
79 end 77 end
80 else 78 else
81 if from_affiliation == "owner" then 79 if from_affiliation == "owner" then
82 if vcards:set(room_node, st.preserialize(stanza.tags[1])) then 80 if vcards:set(room_node, st.preserialize(stanza.tags[1])) then
83 session.send(st.reply(stanza):tag("vCard", { xmlns = "vcard-temp" })); 81 session.send(st.reply(stanza):tag("vCard", { xmlns = "vcard-temp" }));
84 broadcast_presence(room_jid, nil) 82 broadcast_presence(room, nil)
85 83
86 room:broadcast_message(st.message({ from = room.jid, type = "groupchat" }) 84 room:broadcast_message(st.message({ from = room.jid, type = "groupchat" })
87 :tag("x", { xmlns = "http://jabber.org/protocol/muc#user" }) 85 :tag("x", { xmlns = "http://jabber.org/protocol/muc#user" })
88 :tag("status", { code = "104" })); 86 :tag("status", { code = "104" }));
89 else 87 else
110 }); 108 });
111 event.formdata["{http://modules.prosody.im/mod_vcard_muc}avatar#sha1"] = get_photo_hash(event.room); 109 event.formdata["{http://modules.prosody.im/mod_vcard_muc}avatar#sha1"] = get_photo_hash(event.room);
112 end); 110 end);
113 111
114 module:hook("muc-occupant-session-new", function(event) 112 module:hook("muc-occupant-session-new", function(event)
115 broadcast_presence(event.room.jid, event.jid); 113 broadcast_presence(event.room, event.jid);
116 end) 114 end)