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.
pull/1/head
Scott Nonnenberg 7 years ago
parent 4415293100
commit 12b5547e72

@ -5,7 +5,7 @@
function destroyExpiredMessages() {
// Load messages that have expired and destroy them
var expired = new Whisper.MessageCollection();
expired.on('add', function(message) {
expired.on('add', async function(message) {
console.log('Message expired', {
sentAt: message.get('sent_at'),
});
@ -16,7 +16,10 @@
// We delete after the trigger to allow the conversation time to process
// the expiration before the message is removed from the database.
message.destroy();
await wrapDeferred(message.destroy());
if (conversation) {
conversation.updateLastMessage();
}
});
expired.on('reset', throttledCheckExpiringMessages);

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

@ -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();

Loading…
Cancel
Save