# HG changeset patch # User Kim Alvefur # Date 1566594076 -7200 # Node ID d7b589dec591089e064143e0d3be4831ed13d549 # Parent 7b02b8de6d27ff9635dd96283380b739ab3446ec mod_vcard_muc: Factor out avatar hash retrieval into a function for easier reuse diff -r 7b02b8de6d27 -r d7b589dec591 mod_vcard_muc/mod_vcard_muc.lua --- a/mod_vcard_muc/mod_vcard_muc.lua Sat Aug 24 21:49:51 2019 +0200 +++ b/mod_vcard_muc/mod_vcard_muc.lua Fri Aug 23 23:01:16 2019 +0200 @@ -24,22 +24,25 @@ return rooms[jid]; end -local function broadcast_presence(room_jid, to) - local room = get_room_from_jid(room_jid); - local room_node = jid_split(room_jid); +local function get_photo_hash(room) + local room_node = jid_split(room.jid); local vcard = st.deserialize(vcards:get(room_node)); - local photo_hash; - if vcard then local photo = vcard:get_child("PHOTO"); if photo then local photo_b64 = photo:get_child_text("BINVAL"); local photo_raw = photo_b64 and base64.decode(photo_b64); - photo_hash = sha1(photo_raw, true); + return sha1(photo_raw, true); end end +end + +local function broadcast_presence(room_jid, to) + local room = get_room_from_jid(room_jid); + + local photo_hash = get_photo_hash(room) local presence_vcard = st.presence({to = to, from = room_jid}) :tag("x", { xmlns = "vcard-temp:x:update" }) :tag("photo"):text(photo_hash):up();