Update contents of conversation even when view not hydrated

Also ensure that we update the last message in a conversation after
expire, after the mesage is really deleted from the database.
This commit is contained in:
Scott Nonnenberg 2018-06-25 14:51:06 -07:00
parent 4415293100
commit 12b5547e72
3 changed files with 39 additions and 31 deletions

View file

@ -110,13 +110,7 @@
this.listenTo(this.model, 'delivered', this.updateMessage);
this.listenTo(this.model, 'read', this.updateMessage);
this.listenTo(this.model, 'opened', this.onOpened);
this.listenTo(this.model, 'expired', this.onExpired);
this.listenTo(this.model, 'prune', this.onPrune);
this.listenTo(
this.model.messageCollection,
'expired',
this.onExpiredCollection
);
this.listenTo(
this.model.messageCollection,
'scroll-to-message',
@ -807,28 +801,6 @@
return this.inProgressFetch;
},
onExpired(message) {
const mine = this.model.messageCollection.get(message.id);
if (mine && mine.cid !== message.cid) {
mine.trigger('expired', mine);
}
},
async onExpiredCollection(message) {
const removeMessage = () => {
console.log('Remove expired message from message collection', {
sentAt: message.get('sent_at'),
});
this.model.messageCollection.remove(message.id);
};
// If a fetch is in progress, then we need to wait until that's complete to
// do this removal. Otherwise we could remove from messageCollection, then
// the async database fetch could include the removed message.
await this.inProgressFetch;
removeMessage();
},
addMessage(message) {
// This is debounced, so it won't hit the database too often.
this.lazyUpdateVerified();