Update delivered/read message if already in collection

This commit is contained in:
Scott Nonnenberg 2018-07-26 19:26:49 -07:00
parent 02675312c5
commit 8860e4c7fb

View file

@ -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) {