Fix application of incoming view syncs

This commit is contained in:
Ken Powers 2020-04-24 15:32:36 -04:00 committed by Scott Nonnenberg
parent 5cfcedb549
commit 4b685d09b4
2 changed files with 29 additions and 12 deletions

View file

@ -2579,14 +2579,10 @@
const { source, sourceUuid, timestamp } = ev; const { source, sourceUuid, timestamp } = ev;
window.log.info(`view sync ${source} ${timestamp}`); window.log.info(`view sync ${source} ${timestamp}`);
const conversationId = ConversationController.getConversationId(
source || sourceUuid
);
const sync = Whisper.ViewSyncs.add({ const sync = Whisper.ViewSyncs.add({
source, source,
sourceUuid, sourceUuid,
conversationId,
timestamp, timestamp,
}); });

View file

@ -13,14 +13,24 @@
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
Whisper.ViewSyncs = new (Backbone.Collection.extend({ Whisper.ViewSyncs = new (Backbone.Collection.extend({
forMessage(message) { forMessage(message) {
const sync = this.findWhere({ const syncBySourceUuid = this.findWhere({
conversationId: message.get('conversationId'), sourceUuid: message.get('sourceUuid'),
timestamp: message.get('sent_at'), timestamp: message.get('sent_at'),
}); });
if (sync) { if (syncBySourceUuid) {
window.log.info('Found early view sync for message'); window.log.info('Found early view sync for message');
this.remove(sync); this.remove(syncBySourceUuid);
return sync; 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; return null;
@ -34,9 +44,20 @@
} }
); );
const found = messages.find( const found = messages.find(item => {
item => item.get('conversationId') === sync.get('conversationId') 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 syncSource = sync.get('source');
const syncSourceUuid = sync.get('sourceUuid'); const syncSourceUuid = sync.get('sourceUuid');
const syncTimestamp = sync.get('timestamp'); const syncTimestamp = sync.get('timestamp');