Ensure message expire timer start times are never in the future

This commit is contained in:
Scott Nonnenberg 2018-05-30 18:07:25 -07:00
parent f3bd0cf903
commit 71d873ccfe
2 changed files with 7 additions and 3 deletions

View file

@ -720,6 +720,7 @@
function createSentMessage(data) { function createSentMessage(data) {
const now = Date.now(); const now = Date.now();
return new Whisper.Message({ return new Whisper.Message({
source: textsecure.storage.user.getNumber(), source: textsecure.storage.user.getNumber(),
sourceDevice: data.device, sourceDevice: data.device,
@ -728,7 +729,9 @@
conversationId: data.destination, conversationId: data.destination,
type: 'outgoing', type: 'outgoing',
sent: true, sent: true,
expirationStartTimestamp: data.expirationStartTimestamp, expirationStartTimestamp: data.expirationStartTimestamp
? Math.min(data.expirationStartTimestamp, Date.now())
: null,
}); });
} }

View file

@ -669,7 +669,7 @@
) { ) {
message.set( message.set(
'expirationStartTimestamp', 'expirationStartTimestamp',
readSync.get('read_at') Math.min(readSync.get('read_at'), Date.now())
); );
} }
} }
@ -802,7 +802,8 @@
async markRead(readAt) { async markRead(readAt) {
this.unset('unread'); this.unset('unread');
if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) { if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) {
this.set('expirationStartTimestamp', readAt || Date.now()); const expireTimerStart = Math.min(Date.now(), readAt || Date.now());
this.set('expirationStartTimestamp', expireTimerStart);
} }
Whisper.Notifications.remove( Whisper.Notifications.remove(
Whisper.Notifications.where({ Whisper.Notifications.where({