From aec3b7611721fa3c3be2e8c297a7c19876bf052e Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Tue, 12 Oct 2021 10:19:07 -0500 Subject: [PATCH] Add additional logging in notification service --- ts/services/notifications.ts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/ts/services/notifications.ts b/ts/services/notifications.ts index 4fa2c17ae7..0f8fa580ea 100644 --- a/ts/services/notifications.ts +++ b/ts/services/notifications.ts @@ -79,6 +79,7 @@ class NotificationService extends EventEmitter { i18n, storage, }: Readonly<{ i18n: LocalizerType; storage: StorageInterface }>): void { + log.info('NotificationService initialized'); this.i18n = i18n; this.storage = storage; } @@ -110,6 +111,9 @@ class NotificationService extends EventEmitter { * which doesn't check permissions, do any filtering, etc. */ public add(notificationData: NotificationDataType): void { + log.info( + 'NotificationService: adding a notification and requesting an update' + ); this.notificationData = notificationData; this.update(); } @@ -131,6 +135,8 @@ class NotificationService extends EventEmitter { silent: boolean; title: string; }>): void { + log.info('NotificationService: showing a notification'); + this.lastNotification?.close(); const audioNotificationSupport = getAudioNotificationSupport(); @@ -172,6 +178,7 @@ class NotificationService extends EventEmitter { targetTimestamp?: number; }>): void { if (!this.notificationData) { + log.info('NotificationService#removeBy: no notification data'); return; } @@ -180,9 +187,11 @@ class NotificationService extends EventEmitter { conversationId && this.notificationData.conversationId === conversationId ) { + log.info('NotificationService#removeBy: conversation ID matches'); shouldClear = true; } if (messageId && this.notificationData.messageId === messageId) { + log.info('NotificationService#removeBy: message ID matches'); shouldClear = true; } @@ -225,7 +234,13 @@ class NotificationService extends EventEmitter { const shouldShowNotification = this.isEnabled && !isAppFocused && notificationData; if (!shouldShowNotification) { - log.info('Not updating notifications'); + log.info( + `NotificationService not updating notifications. Notifications are ${ + this.isEnabled ? 'enabled' : 'disabled' + }; app is ${isAppFocused ? '' : 'not '}focused; there is ${ + notificationData ? '' : 'no ' + }notification data` + ); if (isAppFocused) { this.notificationData = null; } @@ -241,7 +256,7 @@ class NotificationService extends EventEmitter { true ); if (shouldDrawAttention) { - log.info('Drawing attention'); + log.info('NotificationService: drawing attention'); window.drawAttention(); } @@ -260,7 +275,9 @@ class NotificationService extends EventEmitter { switch (userSetting) { case NotificationSetting.Off: - log.info('Not showing a notification because user has disabled it'); + log.info( + 'NotificationService not showing a notification because user has disabled it' + ); return; case NotificationSetting.NameOnly: case NotificationSetting.NameAndMessage: { @@ -302,7 +319,7 @@ class NotificationService extends EventEmitter { break; } - log.info('Showing a notification'); + log.info('NotificationService: requesting a notification to be shown'); this.notify({ title: notificationTitle, @@ -322,7 +339,9 @@ class NotificationService extends EventEmitter { } public clear(): void { - window.SignalContext.log.info('Removing notification'); + log.info( + 'NotificationService: clearing notification and requesting an update' + ); this.notificationData = null; this.update(); } @@ -331,11 +350,13 @@ class NotificationService extends EventEmitter { // least try to remove the notification immediately instead of waiting for the // normal debounce. public fastClear(): void { + log.info('NotificationService: clearing notification and updating'); this.notificationData = null; this.fastUpdate(); } public enable(): void { + log.info('NotificationService enabling'); const needUpdate = !this.isEnabled; this.isEnabled = true; if (needUpdate) { @@ -344,6 +365,7 @@ class NotificationService extends EventEmitter { } public disable(): void { + log.info('NotificationService disabling'); this.isEnabled = false; } }