From 782516186f17ecb7a8804f9f1fbec736cb7c689a Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 26 Feb 2019 15:08:43 -0800 Subject: [PATCH] Move expiring message cleanup after ConversationController.load() --- js/background.js | 86 +++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/js/background.js b/js/background.js index 619cf6e14..aea05034b 100644 --- a/js/background.js +++ b/js/background.js @@ -330,47 +330,6 @@ Views.Initialization.setMessage(window.i18n('optimizingApplication')); - window.log.info('Cleanup: starting...'); - const messagesForCleanup = await window.Signal.Data.getOutgoingWithoutExpiresAt( - { - MessageCollection: Whisper.MessageCollection, - } - ); - window.log.info( - `Cleanup: Found ${messagesForCleanup.length} messages for cleanup` - ); - await Promise.all( - messagesForCleanup.map(async message => { - const delivered = message.get('delivered'); - const sentAt = message.get('sent_at'); - const expirationStartTimestamp = message.get( - 'expirationStartTimestamp' - ); - - if (message.hasErrors()) { - return; - } - - if (delivered) { - window.log.info( - `Cleanup: Starting timer for delivered message ${sentAt}` - ); - message.set( - 'expirationStartTimestamp', - expirationStartTimestamp || sentAt - ); - await message.setToExpire(); - return; - } - - window.log.info(`Cleanup: Deleting unsent message ${sentAt}`); - await window.Signal.Data.removeMessage(message.id, { - Message: Whisper.Message, - }); - }) - ); - window.log.info('Cleanup: complete'); - if (newVersion) { await window.Signal.Data.cleanupOrphanedAttachments(); } @@ -465,6 +424,51 @@ async function start() { window.dispatchEvent(new Event('storage_ready')); + window.log.info('Cleanup: starting...'); + const messagesForCleanup = await window.Signal.Data.getOutgoingWithoutExpiresAt( + { + MessageCollection: Whisper.MessageCollection, + } + ); + window.log.info( + `Cleanup: Found ${messagesForCleanup.length} messages for cleanup` + ); + await Promise.all( + messagesForCleanup.map(async message => { + const delivered = message.get('delivered'); + const sentAt = message.get('sent_at'); + const expirationStartTimestamp = message.get( + 'expirationStartTimestamp' + ); + + if (message.hasErrors()) { + return; + } + + if (delivered) { + window.log.info( + `Cleanup: Starting timer for delivered message ${sentAt}` + ); + message.set( + 'expirationStartTimestamp', + expirationStartTimestamp || sentAt + ); + await message.setToExpire(); + return; + } + + window.log.info(`Cleanup: Deleting unsent message ${sentAt}`); + await window.Signal.Data.removeMessage(message.id, { + Message: Whisper.Message, + }); + const conversation = message.getConversation(); + if (conversation) { + await conversation.updateLastMessage(); + } + }) + ); + window.log.info('Cleanup: complete'); + window.log.info('listening for registration events'); Whisper.events.on('registration_done', () => { window.log.info('handling registration event');