Move expiring message time earlier if read sync has earlier time
This commit is contained in:
parent
a01db40e27
commit
9ed1ee90f8
3 changed files with 38 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
|||
/* global Backbone, Whisper, ConversationController */
|
||||
/* global Backbone, Whisper */
|
||||
|
||||
/* eslint-disable more/no-then */
|
||||
|
||||
|
@ -32,9 +32,7 @@
|
|||
|
||||
const message = messages.find(
|
||||
item =>
|
||||
item.isIncoming() &&
|
||||
item.isUnread() &&
|
||||
item.get('source') === receipt.get('sender')
|
||||
item.isIncoming() && item.get('source') === receipt.get('sender')
|
||||
);
|
||||
const notificationForMessage = message
|
||||
? Whisper.Notifications.findWhere({ messageId: message.id })
|
||||
|
@ -59,11 +57,39 @@
|
|||
return;
|
||||
}
|
||||
|
||||
await message.markRead(receipt.get('read_at'));
|
||||
// This notification may result in messages older than this one being
|
||||
// marked read. We want those messages to have the same expire timer
|
||||
// start time as this one, so we pass the read_at value through.
|
||||
this.notifyConversation(message, receipt.get('read_at'));
|
||||
const readAt = receipt.get('read_at');
|
||||
|
||||
// If message is unread, we mark it read. Otherwise, we update the expiration
|
||||
// timer to the time specified by the read sync if it's earlier than
|
||||
// the previous read time.
|
||||
if (message.isUnread()) {
|
||||
await message.markRead(readAt);
|
||||
|
||||
// onReadMessage may result in messages older than this one being
|
||||
// marked read. We want those messages to have the same expire timer
|
||||
// start time as this one, so we pass the readAt value through.
|
||||
const conversation = message.getConversation();
|
||||
if (conversation) {
|
||||
conversation.onReadMessage(message, readAt);
|
||||
}
|
||||
} else {
|
||||
const now = Date.now();
|
||||
const existingTimestamp = message.get('expirationStartTimestamp');
|
||||
const expirationStartTimestamp = Math.min(
|
||||
now,
|
||||
Math.min(existingTimestamp || now, readAt || now)
|
||||
);
|
||||
message.set({ expirationStartTimestamp });
|
||||
|
||||
const force = true;
|
||||
await message.setToExpire(force);
|
||||
|
||||
const conversation = message.getConversation();
|
||||
if (conversation) {
|
||||
conversation.trigger('expiration-change', message);
|
||||
}
|
||||
}
|
||||
|
||||
this.remove(receipt);
|
||||
} catch (error) {
|
||||
window.log.error(
|
||||
|
@ -72,14 +98,5 @@
|
|||
);
|
||||
}
|
||||
},
|
||||
notifyConversation(message, readAt) {
|
||||
const conversation = ConversationController.get({
|
||||
id: message.get('conversationId'),
|
||||
});
|
||||
|
||||
if (conversation) {
|
||||
conversation.onReadMessage(message, readAt);
|
||||
}
|
||||
},
|
||||
}))();
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue