Commit 8c3f379d authored by JC Brand's avatar JC Brand

Calculate and save avatar hash upon receipt

parent d49adc93
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
/*global define */ /*global define */
(function (root, factory) { (function (root, factory) {
define(["converse-core", "strophe.vcard"], factory); define(["converse-core", "crypto", "strophe.vcard"], factory);
}(this, function (converse) { }(this, function (converse, CryptoJS) {
"use strict"; "use strict";
const { Promise, Strophe, _, moment, sizzle } = converse.env; const { Promise, Strophe, SHA1, _, moment, sizzle } = converse.env;
const u = converse.env.utils; const u = converse.env.utils;
...@@ -21,11 +21,15 @@ ...@@ -21,11 +21,15 @@
result = { result = {
'stanza': iq, 'stanza': iq,
'fullname': _.get(vcard.querySelector('FN'), 'textContent'), 'fullname': _.get(vcard.querySelector('FN'), 'textContent'),
'image': _.get(vcard.querySelector('BINVAL'), 'textContent'), 'image': _.get(vcard.querySelector('PHOTO BINVAL'), 'textContent'),
'image_type': _.get(vcard.querySelector('TYPE'), 'textContent'), 'image_type': _.get(vcard.querySelector('PHOTO TYPE'), 'textContent'),
'url': _.get(vcard.querySelector('URL'), 'textContent') 'url': _.get(vcard.querySelector('URL'), 'textContent')
}; };
} }
if (result.image) {
const word_array_from_b64 = CryptoJS.enc.Base64.parse(result['image']);
result['image_type'] = CryptoJS.SHA1(word_array_from_b64).toString()
}
if (callback) { if (callback) {
callback(result); callback(result);
} }
...@@ -121,6 +125,7 @@ ...@@ -121,6 +125,7 @@
'fullname': fullname, 'fullname': fullname,
'image': vcard.image, 'image': vcard.image,
'image_type': vcard.image_type, 'image_type': vcard.image_type,
'image_hash': vcard.image_hash,
'url': vcard.url, 'url': vcard.url,
'vcard_updated': moment().format() 'vcard_updated': moment().format()
}; };
...@@ -181,7 +186,7 @@ ...@@ -181,7 +186,7 @@
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.get(model, force).then((vcard) => { this.get(model, force).then((vcard) => {
model.save(_.extend( model.save(_.extend(
_.pick(vcard, ['fullname', 'url', 'image_type', 'image', 'vcard_updated']), _.pick(vcard, ['fullname', 'url', 'image_type', 'image', 'image_hash']),
{'vcard_updated': moment().format()} {'vcard_updated': moment().format()}
)); ));
resolve(); resolve();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment