From 810b59d50e84ffa0c7da3cd731c40cff6d114921 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 6 Feb 2025 17:02:02 +0000 Subject: mod_vcard: Add API to get hash of the vcard avatar --- plugins/mod_vcard.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'plugins/mod_vcard.lua') diff --git a/plugins/mod_vcard.lua b/plugins/mod_vcard.lua index ea6839bb..6b36bdeb 100644 --- a/plugins/mod_vcard.lua +++ b/plugins/mod_vcard.lua @@ -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 @@ end 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 -- cgit v1.2.3