Add additional logging in notification service

This commit is contained in:
Evan Hahn 2021-10-12 10:19:07 -05:00 committed by GitHub
parent ae1af09bf2
commit aec3b76117
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,6 +79,7 @@ class NotificationService extends EventEmitter {
i18n, i18n,
storage, storage,
}: Readonly<{ i18n: LocalizerType; storage: StorageInterface }>): void { }: Readonly<{ i18n: LocalizerType; storage: StorageInterface }>): void {
log.info('NotificationService initialized');
this.i18n = i18n; this.i18n = i18n;
this.storage = storage; this.storage = storage;
} }
@ -110,6 +111,9 @@ class NotificationService extends EventEmitter {
* which doesn't check permissions, do any filtering, etc. * which doesn't check permissions, do any filtering, etc.
*/ */
public add(notificationData: NotificationDataType): void { public add(notificationData: NotificationDataType): void {
log.info(
'NotificationService: adding a notification and requesting an update'
);
this.notificationData = notificationData; this.notificationData = notificationData;
this.update(); this.update();
} }
@ -131,6 +135,8 @@ class NotificationService extends EventEmitter {
silent: boolean; silent: boolean;
title: string; title: string;
}>): void { }>): void {
log.info('NotificationService: showing a notification');
this.lastNotification?.close(); this.lastNotification?.close();
const audioNotificationSupport = getAudioNotificationSupport(); const audioNotificationSupport = getAudioNotificationSupport();
@ -172,6 +178,7 @@ class NotificationService extends EventEmitter {
targetTimestamp?: number; targetTimestamp?: number;
}>): void { }>): void {
if (!this.notificationData) { if (!this.notificationData) {
log.info('NotificationService#removeBy: no notification data');
return; return;
} }
@ -180,9 +187,11 @@ class NotificationService extends EventEmitter {
conversationId && conversationId &&
this.notificationData.conversationId === conversationId this.notificationData.conversationId === conversationId
) { ) {
log.info('NotificationService#removeBy: conversation ID matches');
shouldClear = true; shouldClear = true;
} }
if (messageId && this.notificationData.messageId === messageId) { if (messageId && this.notificationData.messageId === messageId) {
log.info('NotificationService#removeBy: message ID matches');
shouldClear = true; shouldClear = true;
} }
@ -225,7 +234,13 @@ class NotificationService extends EventEmitter {
const shouldShowNotification = const shouldShowNotification =
this.isEnabled && !isAppFocused && notificationData; this.isEnabled && !isAppFocused && notificationData;
if (!shouldShowNotification) { 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) { if (isAppFocused) {
this.notificationData = null; this.notificationData = null;
} }
@ -241,7 +256,7 @@ class NotificationService extends EventEmitter {
true true
); );
if (shouldDrawAttention) { if (shouldDrawAttention) {
log.info('Drawing attention'); log.info('NotificationService: drawing attention');
window.drawAttention(); window.drawAttention();
} }
@ -260,7 +275,9 @@ class NotificationService extends EventEmitter {
switch (userSetting) { switch (userSetting) {
case NotificationSetting.Off: 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; return;
case NotificationSetting.NameOnly: case NotificationSetting.NameOnly:
case NotificationSetting.NameAndMessage: { case NotificationSetting.NameAndMessage: {
@ -302,7 +319,7 @@ class NotificationService extends EventEmitter {
break; break;
} }
log.info('Showing a notification'); log.info('NotificationService: requesting a notification to be shown');
this.notify({ this.notify({
title: notificationTitle, title: notificationTitle,
@ -322,7 +339,9 @@ class NotificationService extends EventEmitter {
} }
public clear(): void { public clear(): void {
window.SignalContext.log.info('Removing notification'); log.info(
'NotificationService: clearing notification and requesting an update'
);
this.notificationData = null; this.notificationData = null;
this.update(); this.update();
} }
@ -331,11 +350,13 @@ class NotificationService extends EventEmitter {
// least try to remove the notification immediately instead of waiting for the // least try to remove the notification immediately instead of waiting for the
// normal debounce. // normal debounce.
public fastClear(): void { public fastClear(): void {
log.info('NotificationService: clearing notification and updating');
this.notificationData = null; this.notificationData = null;
this.fastUpdate(); this.fastUpdate();
} }
public enable(): void { public enable(): void {
log.info('NotificationService enabling');
const needUpdate = !this.isEnabled; const needUpdate = !this.isEnabled;
this.isEnabled = true; this.isEnabled = true;
if (needUpdate) { if (needUpdate) {
@ -344,6 +365,7 @@ class NotificationService extends EventEmitter {
} }
public disable(): void { public disable(): void {
log.info('NotificationService disabling');
this.isEnabled = false; this.isEnabled = false;
} }
} }