diff --git a/js/models/conversations.js b/js/models/conversations.js index a2cd6b04348e..141a75f38080 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -321,6 +321,7 @@ this.debouncedUpdateLastMessage(); }, + // For outgoing messages, we can call this directly. We're already loaded. addSingleMessage(message) { const { id } = message; const existing = this.messageCollection.get(id); @@ -342,6 +343,15 @@ return model; }, + // For incoming messages, they might arrive while we're in the middle of a bulk fetch + // from the database. We'll wait until that is done to process this newly-arrived + // message. + async addIncomingMessage(message) { + await this.inProgressFetch; + + this.addSingleMessage(message); + }, + format() { return this.cachedProps; }, diff --git a/js/models/messages.js b/js/models/messages.js index 5e34f31eb325..249153947bc0 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -1115,8 +1115,8 @@ } return msFromNow; }, - async setToExpire(force = false, options = {}) { - const { skipSave } = options; + async setToExpire(force = false, options) { + const { skipSave } = options || {}; if (this.isExpiring() && (force || !this.get('expires_at'))) { const start = this.get('expirationStartTimestamp'); diff --git a/js/modules/refresh_sender_certificate.js b/js/modules/refresh_sender_certificate.js index 275453fdad6c..a694ab66c557 100644 --- a/js/modules/refresh_sender_certificate.js +++ b/js/modules/refresh_sender_certificate.js @@ -47,8 +47,15 @@ function initialize({ events, storage, navigator, logger }) { ); const expires = decoded.expires.toNumber(); - const time = Math.min(now + ONE_DAY, expires - MINIMUM_TIME_LEFT); + // If we have a time in place and it's already before the safety zone before expire, + // we keep it + if (scheduledTime && scheduledTime <= expires - MINIMUM_TIME_LEFT) { + setTimeoutForNextRun(scheduledTime); + return; + } + // Otherwise, we reset every day, or earlier if the safety zone requires it + const time = Math.min(now + ONE_DAY, expires - MINIMUM_TIME_LEFT); setTimeoutForNextRun(time); } diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 45a0c86fc048..950183575b68 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -1827,7 +1827,7 @@ // We do this here because we don't want convo.messageCollection to have // anything in it unless it has an associated view. This is so, when we // fetch on open, it's clean. - this.model.addSingleMessage(message); + this.model.addIncomingMessage(message); }, async showMembers(e, providedMembers, options = {}) {