From aa4339a69f342d24efbadf1ba5917fc93fcedfd8 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 27 Jul 2018 09:34:47 -0700 Subject: [PATCH] Preserve migration state when deleting config due to failed login --- js/background.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/js/background.js b/js/background.js index 24cce0aac91..3d4418fbb40 100644 --- a/js/background.js +++ b/js/background.js @@ -986,14 +986,32 @@ 'Client is no longer authorized; deleting local configuration' ); Whisper.Registration.remove(); - const previousNumberId = textsecure.storage.get('number_id'); + + const NUMBER_ID_KEY = 'number_id'; + const LAST_PROCESSED_INDEX_KEY = 'attachmentMigration_lastProcessedIndex'; + const IS_MIGRATION_COMPLETE_KEY = 'attachmentMigration_isComplete'; + + const previousNumberId = textsecure.storage.get(NUMBER_ID_KEY); + const lastProcessedIndex = textsecure.storage.get( + LAST_PROCESSED_INDEX_KEY + ); + const isMigrationComplete = textsecure.storage.get( + IS_MIGRATION_COMPLETE_KEY + ); try { await textsecure.storage.protocol.removeAllConfiguration(); + // These two bits of data are important to ensure that the app loads up // the conversation list, instead of showing just the QR code screen. Whisper.Registration.markEverDone(); - textsecure.storage.put('number_id', previousNumberId); + textsecure.storage.put(NUMBER_ID_KEY, previousNumberId); + + // These two are important to ensure we don't rip through every message + // in the database attempting to upgrade it after starting up again. + textsecure.storage.put(LAST_PROCESSED_INDEX_KEY, lastProcessedIndex); + textsecure.storage.put(IS_MIGRATION_COMPLETE_KEY, isMigrationComplete); + window.log.info('Successfully cleared local configuration'); } catch (eraseError) { window.log.error(