diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 8a3b5b31e..27dce4eb1 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -3160,7 +3160,7 @@ export class ConversationModel extends window.Backbone } if (hasUserInitiatedMessages) { - await this.maybeApplyUniversalTimer(true); + await this.maybeRemoveUniversalTimer(); return; } @@ -3173,36 +3173,52 @@ export class ConversationModel extends window.Backbone return; } + log.info( + `maybeSetPendingUniversalTimer(${this.idForLogging()}): added notification` + ); const notificationId = await this.addNotification( 'universal-timer-notification' ); this.set('pendingUniversalTimer', notificationId); } - async maybeApplyUniversalTimer(forceRemove: boolean): Promise { - const notificationId = this.get('pendingUniversalTimer'); - if (!notificationId) { + async maybeApplyUniversalTimer(): Promise { + // Check if we had a notification + if (!(await this.maybeRemoveUniversalTimer())) { return; } - const message = window.MessageController.getById(notificationId); - if (message) { - window.Signal.Data.removeMessage(message.id); - } - - if (this.get('expireTimer') || forceRemove) { - this.set('pendingUniversalTimer', undefined); + // We already have an expiration timer + if (this.get('expireTimer')) { return; } const expireTimer = universalExpireTimer.get(); if (expireTimer) { - // `updateExpirationTimer` calls `modifyGroupV2` and shouldn't be awaited - // since we run both on conversation's queue. - this.updateExpirationTimer(expireTimer); + log.info( + `maybeApplyUniversalTimer(${this.idForLogging()}): applying timer` + ); + + await this.updateExpirationTimer(expireTimer); + } + } + + async maybeRemoveUniversalTimer(): Promise { + const notificationId = this.get('pendingUniversalTimer'); + if (!notificationId) { + return false; } this.set('pendingUniversalTimer', undefined); + log.info( + `maybeRemoveUniversalTimer(${this.idForLogging()}): removed notification` + ); + + const message = window.MessageController.getById(notificationId); + if (message) { + await window.Signal.Data.removeMessage(message.id); + } + return true; } async addChangeNumberNotification( @@ -3829,7 +3845,7 @@ export class ConversationModel extends window.Backbone const destination = this.getSendTarget()!; const recipients = this.getRecipients(); - await this.maybeApplyUniversalTimer(false); + await this.maybeApplyUniversalTimer(); const expireTimer = this.get('expireTimer'); @@ -4362,7 +4378,7 @@ export class ConversationModel extends window.Backbone // This call actually removes universal timer notification and clears // the pending flags. - await this.maybeApplyUniversalTimer(true); + await this.maybeRemoveUniversalTimer(); window.Signal.Data.updateConversation(this.attributes); diff --git a/ts/reactions/enqueueReactionForSend.ts b/ts/reactions/enqueueReactionForSend.ts index 14c3b0c69..ab02cc754 100644 --- a/ts/reactions/enqueueReactionForSend.ts +++ b/ts/reactions/enqueueReactionForSend.ts @@ -41,7 +41,5 @@ export async function enqueueReactionForSend({ source: ReactionSource.FromThisDevice, }); - await message.getConversation()?.maybeApplyUniversalTimer(false); - await message.handleReaction(reaction); }