Ensure proper order of state changes during account create

This commit is contained in:
Scott Nonnenberg 2018-11-09 09:57:12 -08:00
parent c5f9fae444
commit 2822f4ce40

View file

@ -387,21 +387,23 @@
return response; return response;
}) })
.then(response => { .then(async response => {
textsecure.storage.remove('identityKey'); await Promise.all([
textsecure.storage.remove('signaling_key'); textsecure.storage.remove('identityKey'),
textsecure.storage.remove('password'); textsecure.storage.remove('signaling_key'),
textsecure.storage.remove('registrationId'); textsecure.storage.remove('password'),
textsecure.storage.remove('number_id'); textsecure.storage.remove('registrationId'),
textsecure.storage.remove('device_name'); textsecure.storage.remove('number_id'),
textsecure.storage.remove('regionCode'); textsecure.storage.remove('device_name'),
textsecure.storage.remove('userAgent'); textsecure.storage.remove('regionCode'),
textsecure.storage.remove('profileKey'); textsecure.storage.remove('userAgent'),
textsecure.storage.remove('read-receipts-setting'); textsecure.storage.remove('profileKey'),
textsecure.storage.remove('read-receipts-setting'),
]);
// update our own identity key, which may have changed // update our own identity key, which may have changed
// if we're relinking after a reinstall on the master device // if we're relinking after a reinstall on the master device
textsecure.storage.protocol.saveIdentityWithAttributes(number, { await textsecure.storage.protocol.saveIdentityWithAttributes(number, {
id: number, id: number,
publicKey: identityKeyPair.pubKey, publicKey: identityKeyPair.pubKey,
firstUse: true, firstUse: true,
@ -410,28 +412,28 @@
nonblockingApproval: true, nonblockingApproval: true,
}); });
textsecure.storage.put('identityKey', identityKeyPair); await textsecure.storage.put('identityKey', identityKeyPair);
textsecure.storage.put('signaling_key', signalingKey); await textsecure.storage.put('signaling_key', signalingKey);
textsecure.storage.put('password', password); await textsecure.storage.put('password', password);
textsecure.storage.put('registrationId', registrationId); await textsecure.storage.put('registrationId', registrationId);
if (profileKey) { if (profileKey) {
textsecure.storage.put('profileKey', profileKey); await textsecure.storage.put('profileKey', profileKey);
} }
if (userAgent) { if (userAgent) {
textsecure.storage.put('userAgent', userAgent); await textsecure.storage.put('userAgent', userAgent);
}
if (readReceipts) {
textsecure.storage.put('read-receipt-setting', true);
} else {
textsecure.storage.put('read-receipt-setting', false);
} }
textsecure.storage.user.setNumberAndDeviceId( await textsecure.storage.put(
'read-receipt-setting',
Boolean(readReceipts)
);
await textsecure.storage.user.setNumberAndDeviceId(
number, number,
response.deviceId || 1, response.deviceId || 1,
deviceName deviceName
); );
textsecure.storage.put( await textsecure.storage.put(
'regionCode', 'regionCode',
libphonenumber.util.getRegionCodeForNumber(number) libphonenumber.util.getRegionCodeForNumber(number)
); );