Bugfix. jid of null was set on own VCard

Also made a few other minor improvements and did some cleanup.
This commit is contained in:
JC Brand 2018-06-12 12:13:22 +02:00
parent 2ff9a3c6fd
commit a2dec2371d
3 changed files with 47 additions and 43 deletions

32
dist/converse.js vendored
View File

@ -73137,8 +73137,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
reader.readAsDataURL(file); reader.readAsDataURL(file);
}, },
setVCard(body, data) { setVCard(data) {
_converse.api.vcard.set(data).then(() => _converse.api.vcard.update(this.model.vcard, true)).catch(err => { _converse.api.vcard.set(_converse.bare_jid, data).then(() => _converse.api.vcard.update(this.model.vcard, true)).catch(err => {
_converse.log(err, Strophe.LogLevel.FATAL); _converse.log(err, Strophe.LogLevel.FATAL);
_converse.api.alert.show(Strophe.LogLevel.ERROR, __('Error'), [__("Sorry, an error happened while trying to save your profile data."), __("You can check your browser's developer console for any error output.")]); _converse.api.alert.show(Strophe.LogLevel.ERROR, __('Error'), [__("Sorry, an error happened while trying to save your profile data."), __("You can check your browser's developer console for any error output.")]);
@ -73151,7 +73151,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
ev.preventDefault(); ev.preventDefault();
const reader = new FileReader(), const reader = new FileReader(),
form_data = new FormData(ev.target), form_data = new FormData(ev.target),
body = this.el.querySelector('.modal-body'),
image_file = form_data.get('image'); image_file = form_data.get('image');
const data = { const data = {
'fn': form_data.get('fn'), 'fn': form_data.get('fn'),
@ -73167,7 +73166,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
'image_type': this.model.vcard.get('image_type') 'image_type': this.model.vcard.get('image_type')
}); });
this.setVCard(body, data); this.setVCard(data);
} else { } else {
reader.onloadend = () => { reader.onloadend = () => {
_.extend(data, { _.extend(data, {
@ -73175,7 +73174,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
'image_type': image_file.type 'image_type': image_file.type
}); });
this.setVCard(body, data); this.setVCard(data);
}; };
reader.readAsBinaryString(image_file); reader.readAsBinaryString(image_file);
@ -76817,7 +76816,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}); });
function onVCardData(_converse, jid, iq, callback) { function onVCardData(jid, iq, callback) {
const vcard = iq.querySelector('vCard'); const vcard = iq.querySelector('vCard');
let result = {}; let result = {};
@ -76846,7 +76845,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
} }
} }
function onVCardError(_converse, jid, iq, errback) { function onVCardError(jid, iq, errback) {
if (errback) { if (errback) {
errback({ errback({
'stanza': iq, 'stanza': iq,
@ -76875,12 +76874,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
return iq; return iq;
} }
function setVCard(data) { function setVCard(jid, data) {
return new Promise((resolve, reject) => { if (!jid) {
const vcard_el = Strophe.xmlHtmlNode(tpl_vcard(data)).firstElementChild; throw Error("No jid provided for the VCard data");
}
_converse.connection.sendIQ(createStanza("set", data.jid, vcard_el), resolve, reject); const vcard_el = Strophe.xmlHtmlNode(tpl_vcard(data)).firstElementChild;
}); return _converse.api.sendIQ(createStanza("set", jid, vcard_el));
} }
function getVCard(_converse, jid) { function getVCard(_converse, jid) {
@ -76890,9 +76890,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
* (String) jid - The Jabber ID of the user whose VCard * (String) jid - The Jabber ID of the user whose VCard
* is being requested. * is being requested.
*/ */
jid = Strophe.getBareJidFromJid(jid) === _converse.bare_jid ? null : jid; const to = Strophe.getBareJidFromJid(jid) === _converse.bare_jid ? null : jid;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
_converse.connection.sendIQ(createStanza("get", jid), _.partial(onVCardData, _converse, jid, _, resolve), _.partial(onVCardError, _converse, jid, _, resolve), 5000); _converse.connection.sendIQ(createStanza("get", to), _.partial(onVCardData, jid, _, resolve), _.partial(onVCardError, jid, _, resolve), _converse.IQ_TIMEOUT);
}); });
} }
/* Event handlers */ /* Event handlers */
@ -76913,7 +76913,9 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
_.extend(_converse.api, { _.extend(_converse.api, {
'vcard': { 'vcard': {
'set': setVCard, 'set'(jid, data) {
return setVCard(jid, data);
},
'get'(model, force) { 'get'(model, force) {
if (_.isString(model)) { if (_.isString(model)) {

View File

@ -88,8 +88,8 @@
reader.readAsDataURL(file); reader.readAsDataURL(file);
}, },
setVCard (body, data) { setVCard (data) {
_converse.api.vcard.set(data) _converse.api.vcard.set(_converse.bare_jid, data)
.then(() => _converse.api.vcard.update(this.model.vcard, true)) .then(() => _converse.api.vcard.update(this.model.vcard, true))
.catch((err) => { .catch((err) => {
_converse.log(err, Strophe.LogLevel.FATAL); _converse.log(err, Strophe.LogLevel.FATAL);
@ -107,7 +107,6 @@
ev.preventDefault(); ev.preventDefault();
const reader = new FileReader(), const reader = new FileReader(),
form_data = new FormData(ev.target), form_data = new FormData(ev.target),
body = this.el.querySelector('.modal-body'),
image_file = form_data.get('image'); image_file = form_data.get('image');
const data = { const data = {
@ -122,14 +121,14 @@
'image': this.model.vcard.get('image'), 'image': this.model.vcard.get('image'),
'image_type': this.model.vcard.get('image_type') 'image_type': this.model.vcard.get('image_type')
}); });
this.setVCard(body, data); this.setVCard(data);
} else { } else {
reader.onloadend = () => { reader.onloadend = () => {
_.extend(data, { _.extend(data, {
'image': btoa(reader.result), 'image': btoa(reader.result),
'image_type': image_file.type 'image_type': image_file.type
}); });
this.setVCard(body, data); this.setVCard(data);
}; };
reader.readAsBinaryString(image_file); reader.readAsBinaryString(image_file);
} }

View File

@ -56,7 +56,7 @@
}); });
function onVCardData (_converse, jid, iq, callback) { function onVCardData (jid, iq, callback) {
const vcard = iq.querySelector('vCard'); const vcard = iq.querySelector('vCard');
let result = {}; let result = {};
if (!_.isNull(vcard)) { if (!_.isNull(vcard)) {
@ -82,7 +82,7 @@
} }
} }
function onVCardError (_converse, jid, iq, errback) { function onVCardError (jid, iq, errback) {
if (errback) { if (errback) {
errback({ errback({
'stanza': iq, 'stanza': iq,
@ -102,11 +102,12 @@
return iq; return iq;
} }
function setVCard (data) { function setVCard (jid, data) {
return new Promise((resolve, reject) => { if (!jid) {
throw Error("No jid provided for the VCard data");
}
const vcard_el = Strophe.xmlHtmlNode(tpl_vcard(data)).firstElementChild; const vcard_el = Strophe.xmlHtmlNode(tpl_vcard(data)).firstElementChild;
_converse.connection.sendIQ(createStanza("set", data.jid, vcard_el), resolve, reject); return _converse.api.sendIQ(createStanza("set", jid, vcard_el));
});
} }
function getVCard (_converse, jid) { function getVCard (_converse, jid) {
@ -116,13 +117,13 @@
* (String) jid - The Jabber ID of the user whose VCard * (String) jid - The Jabber ID of the user whose VCard
* is being requested. * is being requested.
*/ */
jid = Strophe.getBareJidFromJid(jid) === _converse.bare_jid ? null : jid; const to = Strophe.getBareJidFromJid(jid) === _converse.bare_jid ? null : jid;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
_converse.connection.sendIQ( _converse.connection.sendIQ(
createStanza("get", jid), createStanza("get", to),
_.partial(onVCardData, _converse, jid, _, resolve), _.partial(onVCardData, jid, _, resolve),
_.partial(onVCardError, _converse, jid, _, resolve), _.partial(onVCardError, jid, _, resolve),
5000 _converse.IQ_TIMEOUT
); );
}); });
} }
@ -142,7 +143,9 @@
_.extend(_converse.api, { _.extend(_converse.api, {
'vcard': { 'vcard': {
'set': setVCard, 'set' (jid, data) {
return setVCard(jid, data);
},
'get' (model, force) { 'get' (model, force) {
if (_.isString(model)) { if (_.isString(model)) {