Do not reopen the last notification on reconnect

This commit is contained in:
Fedor Indutny 2022-03-16 17:51:19 -07:00 committed by GitHub
parent 64219f52ac
commit 0923cc6cb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,7 +16,7 @@ import { missingCaseError } from '../util/missingCaseError';
import type { StorageInterface } from '../types/Storage.d'; import type { StorageInterface } from '../types/Storage.d';
import type { LocalizerType } from '../types/Util'; import type { LocalizerType } from '../types/Util';
type NotificationDataType = { type NotificationDataType = Readonly<{
conversationId: string; conversationId: string;
messageId: string; messageId: string;
senderTitle: string; senderTitle: string;
@ -28,7 +28,8 @@ type NotificationDataType = {
targetAuthorUuid: string; targetAuthorUuid: string;
targetTimestamp: number; targetTimestamp: number;
}; };
}; wasShown?: boolean;
}>;
// The keys and values don't match here. This is because the values correspond to old // The keys and values don't match here. This is because the values correspond to old
// setting names. In the future, we may wish to migrate these to match. // setting names. In the future, we may wish to migrate these to match.
@ -111,7 +112,7 @@ class NotificationService extends EventEmitter {
* A higher-level wrapper around `window.Notification`. You may prefer to use `notify`, * A higher-level wrapper around `window.Notification`. You may prefer to use `notify`,
* 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: Omit<NotificationDataType, 'wasShown'>): void {
log.info( log.info(
'NotificationService: adding a notification and requesting an update' 'NotificationService: adding a notification and requesting an update'
); );
@ -272,12 +273,20 @@ class NotificationService extends EventEmitter {
message, message,
isExpiringMessage, isExpiringMessage,
reaction, reaction,
wasShown,
} = notificationData; } = notificationData;
if (wasShown) {
log.info(
'NotificationService: not showing a notification because it was already shown'
);
return;
}
switch (userSetting) { switch (userSetting) {
case NotificationSetting.Off: case NotificationSetting.Off:
log.info( log.info(
'NotificationService not showing a notification because user has disabled it' 'NotificationService: not showing a notification because user has disabled it'
); );
return; return;
case NotificationSetting.NameOnly: case NotificationSetting.NameOnly:
@ -320,6 +329,11 @@ class NotificationService extends EventEmitter {
log.info('NotificationService: requesting a notification to be shown'); log.info('NotificationService: requesting a notification to be shown');
this.notificationData = {
...notificationData,
wasShown: true,
};
this.notify({ this.notify({
title: notificationTitle, title: notificationTitle,
icon: notificationIconUrl, icon: notificationIconUrl,
@ -355,7 +369,7 @@ class NotificationService extends EventEmitter {
} }
public enable(): void { public enable(): void {
log.info('NotificationService enabling'); log.info('NotificationService: enabling');
const needUpdate = !this.isEnabled; const needUpdate = !this.isEnabled;
this.isEnabled = true; this.isEnabled = true;
if (needUpdate) { if (needUpdate) {
@ -364,7 +378,7 @@ class NotificationService extends EventEmitter {
} }
public disable(): void { public disable(): void {
log.info('NotificationService disabling'); log.info('NotificationService: disabling');
this.isEnabled = false; this.isEnabled = false;
} }
} }