Skip to content

Commit

Permalink
Add additional logging in notification service
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal committed Oct 12, 2021
1 parent 8f76c8e commit 9166039
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions ts/services/notifications.ts
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
Expand Down Expand Up @@ -172,6 +178,7 @@ class NotificationService extends EventEmitter {
targetTimestamp?: number;
}>): void {
if (!this.notificationData) {
log.info('NotificationService#removeBy: no notification data');
return;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -241,7 +256,7 @@ class NotificationService extends EventEmitter {
true
);
if (shouldDrawAttention) {
log.info('Drawing attention');
log.info('NotificationService: drawing attention');
window.drawAttention();
}

Expand All @@ -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: {
Expand Down Expand Up @@ -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,
Expand All @@ -322,7 +339,9 @@ class NotificationService extends EventEmitter {
}

public clear(): void {
window.SignalWindow.log.info('Removing notification');
log.info(
'NotificationService: clearing notification and requesting an update'
);
this.notificationData = null;
this.update();
}
Expand All @@ -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) {
Expand All @@ -344,6 +365,7 @@ class NotificationService extends EventEmitter {
}

public disable(): void {
log.info('NotificationService disabling');
this.isEnabled = false;
}
}
Expand Down

0 comments on commit 9166039

Please sign in to comment.