Commit 21a04d9d authored by JC Brand's avatar JC Brand

Avoid unnecessary promise-wrapping

parent de077ba9
...@@ -458,23 +458,18 @@ ...@@ -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']))
.then((fp) => {
bundle['fingerprint'] = u.arrayBufferToHex(fp); bundle['fingerprint'] = u.arrayBufferToHex(fp);
device.save('bundle', bundle); device.save('bundle', bundle);
device.trigger('change:bundle'); // Doesn't get triggered automatically due to pass-by-reference 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,7 +817,6 @@ ...@@ -822,7 +817,6 @@
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'
...@@ -843,8 +837,7 @@ ...@@ -843,8 +837,7 @@
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();
}); });
_converse.connection.sendIQ(stanza, resolve, reject, _converse.IQ_TIMEOUT); return _converse.api.sendIQ(stanza);
});
} }
} }
......
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