# HG changeset patch # User Matthew Wild <mwild1@gmail.com> # Date 1738861322 0 # Node ID 39c35f7e6cfae7a6ecb88ec1915d225be464fc1c # Parent e0bbf85edc210032f04c737519a8f85254d491f7 mod_vcard: Add API to get hash of the vcard avatar diff -r e0bbf85edc21 -r 39c35f7e6cfa plugins/mod_vcard.lua --- a/plugins/mod_vcard.lua Thu Feb 06 15:43:23 2025 +0000 +++ b/plugins/mod_vcard.lua Thu Feb 06 17:02:02 2025 +0000 @@ -6,6 +6,8 @@ -- COPYING file in the source package for more information. -- +local base64 = require "prosody.util.encodings".base64; +local sha1 = require "prosody.util.hashes".sha1; local st = require "prosody.util.stanza" local jid_split = require "prosody.util.jid".split; @@ -46,3 +48,14 @@ module:hook("iq/bare/vcard-temp:vCard", handle_vcard); module:hook("iq/host/vcard-temp:vCard", handle_vcard); + +function get_avatar_hash(username) + local vcard = st.deserialize(vcards:get(username)); + if not vcard then return end + local photo = vcard:get_child("PHOTO"); + if not photo then return end + + local photo_b64 = photo:get_child_text("BINVAL"); + local photo_raw = photo_b64 and base64.decode(photo_b64); + return (sha1(photo_raw, true)); +end