Less explicit Promise declarations.
It's usually not necessary to wrap a promise inside another one, instead the original promise can just be returned.
This commit is contained in:
parent
cda426bc82
commit
7d1db66056
|
@ -401,6 +401,8 @@
|
||||||
function generateFingerprint (device) {
|
function generateFingerprint (device) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
device.getBundle().then((bundle) => {
|
device.getBundle().then((bundle) => {
|
||||||
|
if (_.isNil(bundle)) { resolve(); }
|
||||||
|
|
||||||
// TODO: only generate fingerprints when necessary
|
// TODO: only generate fingerprints when necessary
|
||||||
crypto.subtle.digest('SHA-1', u.base64ToArrayBuffer(bundle['identity_key']))
|
crypto.subtle.digest('SHA-1', u.base64ToArrayBuffer(bundle['identity_key']))
|
||||||
.then((fp) => {
|
.then((fp) => {
|
||||||
|
@ -414,10 +416,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
_converse.getFingerprintsForContact = function (jid) {
|
_converse.getFingerprintsForContact = function (jid) {
|
||||||
return new Promise((resolve, reject) => {
|
return _converse.getDevicesForContact(jid)
|
||||||
_converse.getDevicesForContact(jid)
|
.then(devices => Promise.all(devices.map(d => generateFingerprint(d))))
|
||||||
.then((devices) => Promise.all(devices.map(d => generateFingerprint(d))).then(resolve).catch(reject));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_converse.getDevicesForContact = function (jid) {
|
_converse.getDevicesForContact = function (jid) {
|
||||||
|
@ -629,26 +629,23 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchBundleFromServer () {
|
fetchBundleFromServer () {
|
||||||
return new Promise((resolve, reject) => {
|
const stanza = $iq({
|
||||||
const stanza = $iq({
|
'type': 'get',
|
||||||
'type': 'get',
|
'from': _converse.bare_jid,
|
||||||
'from': _converse.bare_jid,
|
'to': this.get('jid')
|
||||||
'to': this.get('jid')
|
}).c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
|
||||||
}).c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
|
.c('items', {'node': `${Strophe.NS.OMEMO_BUNDLES}:${this.get('id')}`});
|
||||||
.c('items', {'node': `${Strophe.NS.OMEMO_BUNDLES}:${this.get('id')}`});
|
|
||||||
_converse.connection.sendIQ(
|
return _converse.api.sendIQ(stanza)
|
||||||
stanza,
|
.then(iq => {
|
||||||
(iq) => {
|
const publish_el = sizzle(`items[node="${Strophe.NS.OMEMO_BUNDLES}:${this.get('id')}"]`, iq).pop(),
|
||||||
const publish_el = sizzle(`items[node="${Strophe.NS.OMEMO_BUNDLES}:${this.get('id')}"]`, iq).pop(),
|
bundle_el = sizzle(`bundle[xmlns="${Strophe.NS.OMEMO}"]`, publish_el).pop(),
|
||||||
bundle_el = sizzle(`bundle[xmlns="${Strophe.NS.OMEMO}"]`, publish_el).pop(),
|
bundle = parseBundle(bundle_el);
|
||||||
bundle = parseBundle(bundle_el);
|
this.save('bundle', bundle);
|
||||||
this.save('bundle', bundle);
|
return bundle;
|
||||||
resolve(bundle);
|
}).catch(iq => {
|
||||||
},
|
_converse.log(iq.outerHTML, Strophe.LogLevel.ERROR);
|
||||||
reject,
|
});
|
||||||
_converse.IQ_TIMEOUT
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getBundle () {
|
getBundle () {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user