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

@ -107,12 +107,42 @@
this.on('change:profileAvatar', this.updateAvatarUrl);
this.on('change:profileKey', this.onChangeProfileKey);
this.on('destroy', this.revokeAvatarUrl);
this.on('expired', this.onExpired);
this.listenTo(
this.messageCollection,
'expired',
this.onExpiredCollection
);
},
isMe() {
return this.id === this.ourNumber;
},
onExpired(message) {
const mine = this.messageCollection.get(message.id);
if (mine && mine.cid !== message.cid) {
mine.trigger('expired', mine);
}
},
async onExpiredCollection(message) {
console.log('onExpiredCollection', message.attributes);
const removeMessage = () => {
console.log('Remove expired message from collection', {
sentAt: message.get('sent_at'),
});
this.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();
},
addSingleMessage(message) {
const model = this.messageCollection.add(message, { merge: true });
this.processQuotes(this.messageCollection);
@ -1462,12 +1492,15 @@
throw new Error('This conversation has no id!');
}
await this.messageCollection.fetchConversation(
this.inProgressFetch = this.messageCollection.fetchConversation(
this.id,
null,
this.get('unreadCount')
);
await this.inProgressFetch;
this.inProgressFetch = null;
// We kick this process off, but don't wait for it. If async updates happen on a
// given Message, 'change' will be triggered
this.processQuotes(this.messageCollection);