Software /
code /
prosody
Comparison
plugins/mod_vcard.lua @ 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 |
parent | 12977:74b9e05af71e |
child | 13655:6902bb3dd196 |
comparison
equal
deleted
inserted
replaced
13653:e0bbf85edc21 | 13654:39c35f7e6cfa |
---|---|
4 -- | 4 -- |
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 local base64 = require "prosody.util.encodings".base64; | |
10 local sha1 = require "prosody.util.hashes".sha1; | |
9 local st = require "prosody.util.stanza" | 11 local st = require "prosody.util.stanza" |
10 local jid_split = require "prosody.util.jid".split; | 12 local jid_split = require "prosody.util.jid".split; |
11 | 13 |
12 local vcards = module:open_store(); | 14 local vcards = module:open_store(); |
13 | 15 |
44 return true; | 46 return true; |
45 end | 47 end |
46 | 48 |
47 module:hook("iq/bare/vcard-temp:vCard", handle_vcard); | 49 module:hook("iq/bare/vcard-temp:vCard", handle_vcard); |
48 module:hook("iq/host/vcard-temp:vCard", handle_vcard); | 50 module:hook("iq/host/vcard-temp:vCard", handle_vcard); |
51 | |
52 function get_avatar_hash(username) | |
53 local vcard = st.deserialize(vcards:get(username)); | |
54 if not vcard then return end | |
55 local photo = vcard:get_child("PHOTO"); | |
56 if not photo then return end | |
57 | |
58 local photo_b64 = photo:get_child_text("BINVAL"); | |
59 local photo_raw = photo_b64 and base64.decode(photo_b64); | |
60 return (sha1(photo_raw, true)); | |
61 end |