Avoid unnecessary promise-wrapping
This commit is contained in:
parent
de077ba9af
commit
21a04d9de5
@ -458,23 +458,18 @@
|
|||||||
_converse.NUM_PREKEYS = 100; // Set here so that tests can override
|
_converse.NUM_PREKEYS = 100; // Set here so that tests can override
|
||||||
|
|
||||||
function generateFingerprint (device) {
|
function generateFingerprint (device) {
|
||||||
return new Promise((resolve, reject) => {
|
let bundle;
|
||||||
device.getBundle().then((bundle) => {
|
return device.getBundle().then(b => {
|
||||||
if (_.isNil(bundle)) { resolve(); }
|
bundle = b;
|
||||||
|
return crypto.subtle.digest('SHA-1', u.base64ToArrayBuffer(bundle['identity_key']));
|
||||||
// TODO: only generate fingerprints when necessary
|
}).then(fp => {
|
||||||
crypto.subtle.digest('SHA-1', u.base64ToArrayBuffer(bundle['identity_key']))
|
bundle['fingerprint'] = u.arrayBufferToHex(fp);
|
||||||
.then((fp) => {
|
device.save('bundle', bundle);
|
||||||
bundle['fingerprint'] = u.arrayBufferToHex(fp);
|
device.trigger('change:bundle'); // Doesn't get triggered automatically due to pass-by-reference
|
||||||
device.save('bundle', bundle);
|
|
||||||
device.trigger('change:bundle'); // Doesn't get triggered automatically due to pass-by-reference
|
|
||||||
resolve();
|
|
||||||
}).catch(reject);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_converse.generateFingerprints= function (jid) {
|
_converse.generateFingerprints = function (jid) {
|
||||||
return _converse.getDevicesForContact(jid)
|
return _converse.getDevicesForContact(jid)
|
||||||
.then(devices => Promise.all(devices.map(d => generateFingerprint(d))))
|
.then(devices => Promise.all(devices.map(d => generateFingerprint(d))))
|
||||||
}
|
}
|
||||||
@ -822,29 +817,27 @@
|
|||||||
const store = _converse.omemo_store,
|
const store = _converse.omemo_store,
|
||||||
signed_prekey = store.get('signed_prekey');
|
signed_prekey = store.get('signed_prekey');
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
const stanza = $iq({
|
||||||
const stanza = $iq({
|
'from': _converse.bare_jid,
|
||||||
'from': _converse.bare_jid,
|
'type': 'set'
|
||||||
'type': 'set'
|
}).c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
|
||||||
}).c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
|
.c('publish', {'node': `${Strophe.NS.OMEMO_BUNDLES}:${store.get('device_id')}`})
|
||||||
.c('publish', {'node': `${Strophe.NS.OMEMO_BUNDLES}:${store.get('device_id')}`})
|
.c('item')
|
||||||
.c('item')
|
.c('bundle', {'xmlns': Strophe.NS.OMEMO})
|
||||||
.c('bundle', {'xmlns': Strophe.NS.OMEMO})
|
.c('signedPreKeyPublic', {'signedPreKeyId': signed_prekey.keyId})
|
||||||
.c('signedPreKeyPublic', {'signedPreKeyId': signed_prekey.keyId})
|
.t(u.arrayBufferToBase64(signed_prekey.keyPair.pubKey)).up()
|
||||||
.t(u.arrayBufferToBase64(signed_prekey.keyPair.pubKey)).up()
|
.c('signedPreKeySignature')
|
||||||
.c('signedPreKeySignature')
|
.t(u.arrayBufferToBase64(signed_prekey.signature)).up()
|
||||||
.t(u.arrayBufferToBase64(signed_prekey.signature)).up()
|
.c('identityKey')
|
||||||
.c('identityKey')
|
.t(u.arrayBufferToBase64(store.get('identity_keypair').pubKey)).up()
|
||||||
.t(u.arrayBufferToBase64(store.get('identity_keypair').pubKey)).up()
|
.c('prekeys');
|
||||||
.c('prekeys');
|
_.forEach(
|
||||||
_.forEach(
|
store.get('prekeys').slice(0, _converse.NUM_PREKEYS),
|
||||||
store.get('prekeys').slice(0, _converse.NUM_PREKEYS),
|
(prekey) => {
|
||||||
(prekey) => {
|
stanza.c('preKeyPublic', {'preKeyId': prekey.keyId})
|
||||||
stanza.c('preKeyPublic', {'preKeyId': prekey.keyId})
|
.t(u.arrayBufferToBase64(prekey.keyPair.pubKey)).up();
|
||||||
.t(u.arrayBufferToBase64(prekey.keyPair.pubKey)).up();
|
});
|
||||||
});
|
return _converse.api.sendIQ(stanza);
|
||||||
_converse.connection.sendIQ(stanza, resolve, reject, _converse.IQ_TIMEOUT);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user