From 8860e4c7fb08721d9bfcaf8439cf22e73d707028 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 26 Jul 2018 19:26:49 -0700 Subject: [PATCH] Update delivered/read message if already in collection --- js/models/conversations.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 9dc3ea3ba..183610141 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -131,8 +131,8 @@ this.on('destroy', this.revokeAvatarUrl); // Listening for out-of-band data updates - this.on('delivered', this.updateLastMessage); - this.on('read', this.updateLastMessage); + this.on('delivered', this.updateAndMerge); + this.on('read', this.updateAndMerge); this.on('sent', this.updateLastMessage); this.on('expired', this.onExpired); @@ -143,7 +143,26 @@ return this.id === this.ourNumber; }, + async updateAndMerge(message) { + this.updateLastMessage(); + + const mergeMessage = () => { + const existing = this.messageCollection.get(message.id); + if (!existing) { + return; + } + + window.log.info('Merging updated message into collection'); + existing.merge(message.attributes); + }; + + await this.inProgressFetch; + mergeMessage(); + }, + async onExpired(message) { + this.updateLastMessage(); + const removeMessage = () => { const existing = this.messageCollection.get(message.id); if (!existing) { @@ -162,8 +181,6 @@ await this.inProgressFetch; removeMessage(); - - this.updateLastMessage(); }, addSingleMessage(message) {