From 4b685d09b4656e072bda52c3a398843599f69121 Mon Sep 17 00:00:00 2001 From: Ken Powers Date: Fri, 24 Apr 2020 15:32:36 -0400 Subject: [PATCH] Fix application of incoming view syncs --- js/background.js | 4 ---- js/view_syncs.js | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/js/background.js b/js/background.js index 7118d19310..df1b7fd7e1 100644 --- a/js/background.js +++ b/js/background.js @@ -2579,14 +2579,10 @@ const { source, sourceUuid, timestamp } = ev; window.log.info(`view sync ${source} ${timestamp}`); - const conversationId = ConversationController.getConversationId( - source || sourceUuid - ); const sync = Whisper.ViewSyncs.add({ source, sourceUuid, - conversationId, timestamp, }); diff --git a/js/view_syncs.js b/js/view_syncs.js index 3b6fac1c39..90640665b7 100644 --- a/js/view_syncs.js +++ b/js/view_syncs.js @@ -13,14 +13,24 @@ window.Whisper = window.Whisper || {}; Whisper.ViewSyncs = new (Backbone.Collection.extend({ forMessage(message) { - const sync = this.findWhere({ - conversationId: message.get('conversationId'), + const syncBySourceUuid = this.findWhere({ + sourceUuid: message.get('sourceUuid'), timestamp: message.get('sent_at'), }); - if (sync) { + if (syncBySourceUuid) { window.log.info('Found early view sync for message'); - this.remove(sync); - return sync; + this.remove(syncBySourceUuid); + return syncBySourceUuid; + } + + const syncBySource = this.findWhere({ + source: message.get('source'), + timestamp: message.get('sent_at'), + }); + if (syncBySource) { + window.log.info('Found early view sync for message'); + this.remove(syncBySource); + return syncBySource; } return null; @@ -34,9 +44,20 @@ } ); - const found = messages.find( - item => item.get('conversationId') === sync.get('conversationId') - ); + const found = messages.find(item => { + const itemSourceUuid = item.get('sourceUuid'); + const syncSourceUuid = sync.get('sourceUuid'); + const itemSource = item.get('source'); + const syncSource = sync.get('source'); + + return ( + (itemSourceUuid && + syncSourceUuid && + itemSourceUuid === syncSourceUuid) || + (itemSource && syncSource && itemSource === syncSource) + ); + }); + const syncSource = sync.get('source'); const syncSourceUuid = sync.get('sourceUuid'); const syncTimestamp = sync.get('timestamp');