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,
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;
}
}