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);
|
this.on('destroy', this.revokeAvatarUrl);
|
||||||
|
|
||||||
// Listening for out-of-band data updates
|
// Listening for out-of-band data updates
|
||||||
this.on('delivered', this.updateLastMessage);
|
this.on('delivered', this.updateAndMerge);
|
||||||
this.on('read', this.updateLastMessage);
|
this.on('read', this.updateAndMerge);
|
||||||
this.on('sent', this.updateLastMessage);
|
this.on('sent', this.updateLastMessage);
|
||||||
this.on('expired', this.onExpired);
|
this.on('expired', this.onExpired);
|
||||||
|
|
||||||
|
@ -143,7 +143,26 @@
|
||||||
return this.id === this.ourNumber;
|
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) {
|
async onExpired(message) {
|
||||||
|
this.updateLastMessage();
|
||||||
|
|
||||||
const removeMessage = () => {
|
const removeMessage = () => {
|
||||||
const existing = this.messageCollection.get(message.id);
|
const existing = this.messageCollection.get(message.id);
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
|
@ -162,8 +181,6 @@
|
||||||
|
|
||||||
await this.inProgressFetch;
|
await this.inProgressFetch;
|
||||||
removeMessage();
|
removeMessage();
|
||||||
|
|
||||||
this.updateLastMessage();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
addSingleMessage(message) {
|
addSingleMessage(message) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue