Update delivered/read message if already in collection
This commit is contained in:
parent
02675312c5
commit
8860e4c7fb
1 changed files with 21 additions and 4 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue