aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2025-02-06 17:02:02 +0000
committerMatthew Wild <mwild1@gmail.com>2025-02-06 17:02:02 +0000
commit810b59d50e84ffa0c7da3cd731c40cff6d114921 (patch)
tree7aa5ef0b6376b791d7706f22ace0280d2db7ca3e /plugins
parent2fef4f5d9cc2c59def9321899145cf3417880b15 (diff)
downloadprosody-810b59d50e84ffa0c7da3cd731c40cff6d114921.tar.gz
prosody-810b59d50e84ffa0c7da3cd731c40cff6d114921.zip
mod_vcard: Add API to get hash of the vcard avatar
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_vcard.lua13
1 files changed, 13 insertions, 0 deletions
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