comparison mod_vcard_muc/mod_vcard_muc.lua @ 3655:d7b589dec591

mod_vcard_muc: Factor out avatar hash retrieval into a function for easier reuse
author Kim Alvefur <zash@zash.se>
date Fri, 23 Aug 2019 23:01:16 +0200
parents f16b021e8a61
children 3e0f4d727825
comparison
equal deleted inserted replaced
3654:7b02b8de6d27 3655:d7b589dec591
22 function (jid) 22 function (jid)
23 local rooms = rawget(mod_muc, "rooms"); 23 local rooms = rawget(mod_muc, "rooms");
24 return rooms[jid]; 24 return rooms[jid];
25 end 25 end
26 26
27 local function broadcast_presence(room_jid, to) 27 local function get_photo_hash(room)
28 local room = get_room_from_jid(room_jid); 28 local room_node = jid_split(room.jid);
29 local room_node = jid_split(room_jid);
30 local vcard = st.deserialize(vcards:get(room_node)); 29 local vcard = st.deserialize(vcards:get(room_node));
31 local photo_hash;
32
33 if vcard then 30 if vcard then
34 local photo = vcard:get_child("PHOTO"); 31 local photo = vcard:get_child("PHOTO");
35 32
36 if photo then 33 if photo then
37 local photo_b64 = photo:get_child_text("BINVAL"); 34 local photo_b64 = photo:get_child_text("BINVAL");
38 local photo_raw = photo_b64 and base64.decode(photo_b64); 35 local photo_raw = photo_b64 and base64.decode(photo_b64);
39 photo_hash = sha1(photo_raw, true); 36 return sha1(photo_raw, true);
40 end 37 end
41 end 38 end
42 39
40 end
41
42 local function broadcast_presence(room_jid, to)
43 local room = get_room_from_jid(room_jid);
44
45 local photo_hash = get_photo_hash(room)
43 local presence_vcard = st.presence({to = to, from = room_jid}) 46 local presence_vcard = st.presence({to = to, from = room_jid})
44 :tag("x", { xmlns = "vcard-temp:x:update" }) 47 :tag("x", { xmlns = "vcard-temp:x:update" })
45 :tag("photo"):text(photo_hash):up(); 48 :tag("photo"):text(photo_hash):up();
46 49
47 if to == nil then 50 if to == nil then