Commit ec609a38 authored by JC Brand's avatar JC Brand

Refetch VCards which we couldn't retrieve before

parent ab4d0204
// Converse.js // Converse.js
// http://conversejs.org // http://conversejs.org
// //
// Copyright (c) 2012-2018, the Converse.js developers // Copyright (c) 2013-2018, the Converse.js developers
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
(function (root, factory) { (function (root, factory) {
...@@ -68,7 +68,9 @@ ...@@ -68,7 +68,9 @@
'image_type': _.get(vcard.querySelector('PHOTO TYPE'), 'textContent'), 'image_type': _.get(vcard.querySelector('PHOTO TYPE'), 'textContent'),
'url': _.get(vcard.querySelector('URL'), 'textContent'), 'url': _.get(vcard.querySelector('URL'), 'textContent'),
'role': _.get(vcard.querySelector('ROLE'), 'textContent'), 'role': _.get(vcard.querySelector('ROLE'), 'textContent'),
'email': _.get(vcard.querySelector('EMAIL USERID'), 'textContent') 'email': _.get(vcard.querySelector('EMAIL USERID'), 'textContent'),
'vcard_updated': moment().format(),
'vcard_error': undefined
}; };
} }
if (result.image) { if (result.image) {
...@@ -82,7 +84,11 @@ ...@@ -82,7 +84,11 @@
function onVCardError (_converse, jid, iq, errback) { function onVCardError (_converse, jid, iq, errback) {
if (errback) { if (errback) {
errback({'stanza': iq, 'jid': jid}); errback({
'stanza': iq,
'jid': jid,
'vcard_error': moment().format()
});
} }
} }
...@@ -141,7 +147,10 @@ ...@@ -141,7 +147,10 @@
'get' (model, force) { 'get' (model, force) {
if (_.isString(model)) { if (_.isString(model)) {
return getVCard(_converse, model); return getVCard(_converse, model);
} else if (!model.get('vcard_updated') || force) { } else if (force ||
!model.get('vcard_updated') ||
!moment(model.get('vcard_error')).isSame(new Date(), "day")) {
const jid = model.get('jid'); const jid = model.get('jid');
if (!jid) { if (!jid) {
throw new Error("No JID to get vcard for!"); throw new Error("No JID to get vcard for!");
...@@ -155,10 +164,8 @@ ...@@ -155,10 +164,8 @@
'update' (model, force) { 'update' (model, force) {
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( delete vcard['stanza']
_.pick(vcard, ['fullname', 'nickname', 'email', 'url', 'role', 'image_type', 'image', 'image_hash']), model.save(vcard);
{'vcard_updated': moment().format()}
));
resolve(); resolve();
}); });
}); });
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
var _ = converse.env._; var _ = converse.env._;
var Promise = converse.env.Promise; var Promise = converse.env.Promise;
var Strophe = converse.env.Strophe; var Strophe = converse.env.Strophe;
var moment = converse.env.moment;
var $iq = converse.env.$iq; var $iq = converse.env.$iq;
var mock = {}; var mock = {};
...@@ -99,6 +100,7 @@ ...@@ -99,6 +100,7 @@
}, settings || {})); }, settings || {}));
_converse.ChatBoxViews.prototype.trimChat = function () {}; _converse.ChatBoxViews.prototype.trimChat = function () {};
_converse.api.vcard.get = function (model, force) { _converse.api.vcard.get = function (model, force) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let jid; let jid;
...@@ -120,11 +122,13 @@ ...@@ -120,11 +122,13 @@
} }
var vcard = $iq().c('vCard').c('FN').t(fullname).nodeTree; var vcard = $iq().c('vCard').c('FN').t(fullname).nodeTree;
var result = { var result = {
'stanza': vcard, 'vcard': vcard,
'fullname': _.get(vcard.querySelector('FN'), 'textContent'), 'fullname': _.get(vcard.querySelector('FN'), 'textContent'),
'image': _.get(vcard.querySelector('PHOTO BINVAL'), 'textContent'), 'image': _.get(vcard.querySelector('PHOTO BINVAL'), 'textContent'),
'image_type': _.get(vcard.querySelector('PHOTO TYPE'), 'textContent'), 'image_type': _.get(vcard.querySelector('PHOTO TYPE'), 'textContent'),
'url': _.get(vcard.querySelector('URL'), 'textContent') 'url': _.get(vcard.querySelector('URL'), 'textContent'),
'vcard_updated': moment().format(),
'vcard_error': undefined
}; };
resolve(result); resolve(result);
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
......
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