Software /
code /
prosody
Changeset
13654:39c35f7e6cfa
mod_vcard: Add API to get hash of the vcard avatar
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 06 Feb 2025 17:02:02 +0000 |
parents | 13653:e0bbf85edc21 |
children | 13655:6902bb3dd196 |
files | plugins/mod_vcard.lua |
diffstat | 1 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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