Use explicit method names for universal timers

This commit is contained in:
Fedor Indutny 2022-03-09 14:20:08 -08:00 committed by GitHub
parent cc44dca32b
commit 81e991af80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 18 deletions

View File

@ -3160,7 +3160,7 @@ export class ConversationModel extends window.Backbone
} }
if (hasUserInitiatedMessages) { if (hasUserInitiatedMessages) {
await this.maybeApplyUniversalTimer(true); await this.maybeRemoveUniversalTimer();
return; return;
} }
@ -3173,36 +3173,52 @@ export class ConversationModel extends window.Backbone
return; return;
} }
log.info(
`maybeSetPendingUniversalTimer(${this.idForLogging()}): added notification`
);
const notificationId = await this.addNotification( const notificationId = await this.addNotification(
'universal-timer-notification' 'universal-timer-notification'
); );
this.set('pendingUniversalTimer', notificationId); this.set('pendingUniversalTimer', notificationId);
} }
async maybeApplyUniversalTimer(forceRemove: boolean): Promise<void> { async maybeApplyUniversalTimer(): Promise<void> {
const notificationId = this.get('pendingUniversalTimer'); // Check if we had a notification
if (!notificationId) { if (!(await this.maybeRemoveUniversalTimer())) {
return; return;
} }
const message = window.MessageController.getById(notificationId); // We already have an expiration timer
if (message) { if (this.get('expireTimer')) {
window.Signal.Data.removeMessage(message.id);
}
if (this.get('expireTimer') || forceRemove) {
this.set('pendingUniversalTimer', undefined);
return; return;
} }
const expireTimer = universalExpireTimer.get(); const expireTimer = universalExpireTimer.get();
if (expireTimer) { if (expireTimer) {
// `updateExpirationTimer` calls `modifyGroupV2` and shouldn't be awaited log.info(
// since we run both on conversation's queue. `maybeApplyUniversalTimer(${this.idForLogging()}): applying timer`
this.updateExpirationTimer(expireTimer); );
await this.updateExpirationTimer(expireTimer);
}
}
async maybeRemoveUniversalTimer(): Promise<boolean> {
const notificationId = this.get('pendingUniversalTimer');
if (!notificationId) {
return false;
} }
this.set('pendingUniversalTimer', undefined); 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( async addChangeNumberNotification(
@ -3829,7 +3845,7 @@ export class ConversationModel extends window.Backbone
const destination = this.getSendTarget()!; const destination = this.getSendTarget()!;
const recipients = this.getRecipients(); const recipients = this.getRecipients();
await this.maybeApplyUniversalTimer(false); await this.maybeApplyUniversalTimer();
const expireTimer = this.get('expireTimer'); const expireTimer = this.get('expireTimer');
@ -4362,7 +4378,7 @@ export class ConversationModel extends window.Backbone
// This call actually removes universal timer notification and clears // This call actually removes universal timer notification and clears
// the pending flags. // the pending flags.
await this.maybeApplyUniversalTimer(true); await this.maybeRemoveUniversalTimer();
window.Signal.Data.updateConversation(this.attributes); window.Signal.Data.updateConversation(this.attributes);

View File

@ -41,7 +41,5 @@ export async function enqueueReactionForSend({
source: ReactionSource.FromThisDevice, source: ReactionSource.FromThisDevice,
}); });
await message.getConversation()?.maybeApplyUniversalTimer(false);
await message.handleReaction(reaction); await message.handleReaction(reaction);
} }