Draw attention even if notifications are otherwise disabled

This commit is contained in:
Evan Hahn 2021-09-24 14:01:29 -05:00 committed by GitHub
parent af66a5b265
commit f81f61af4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,7 @@ import {
import * as OS from '../OS'; import * as OS from '../OS';
import * as log from '../logging/log'; import * as log from '../logging/log';
import { makeEnumParser } from '../util/enum'; import { makeEnumParser } from '../util/enum';
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';
@ -222,10 +223,7 @@ class NotificationService extends EventEmitter {
// This isn't a boolean because TypeScript isn't smart enough to know that, if // This isn't a boolean because TypeScript isn't smart enough to know that, if
// `Boolean(notificationData)` is true, `notificationData` is truthy. // `Boolean(notificationData)` is true, `notificationData` is truthy.
const shouldShowNotification = const shouldShowNotification =
this.isEnabled && this.isEnabled && !isAppFocused && notificationData;
!isAppFocused &&
notificationData &&
userSetting !== NotificationSetting.Off;
if (!shouldShowNotification) { if (!shouldShowNotification) {
log.info('Not updating notifications'); log.info('Not updating notifications');
if (isAppFocused) { if (isAppFocused) {
@ -234,13 +232,12 @@ class NotificationService extends EventEmitter {
return; return;
} }
log.info('Showing a notification');
const shouldDrawAttention = storage.get( const shouldDrawAttention = storage.get(
'notification-draw-attention', 'notification-draw-attention',
true true
); );
if (shouldDrawAttention) { if (shouldDrawAttention) {
log.info('Drawing attention');
window.drawAttention(); window.drawAttention();
} }
@ -257,45 +254,52 @@ class NotificationService extends EventEmitter {
reaction, reaction,
} = notificationData; } = notificationData;
if ( switch (userSetting) {
userSetting === NotificationSetting.NameOnly || case NotificationSetting.Off:
userSetting === NotificationSetting.NameAndMessage log.info('Not showing a notification because user has disabled it');
) { return;
notificationTitle = senderTitle; case NotificationSetting.NameOnly:
({ notificationIconUrl } = notificationData); case NotificationSetting.NameAndMessage: {
notificationTitle = senderTitle;
({ notificationIconUrl } = notificationData);
const shouldHideExpiringMessageBody = const shouldHideExpiringMessageBody =
isExpiringMessage && (OS.isMacOS() || OS.isWindows()); isExpiringMessage && (OS.isMacOS() || OS.isWindows());
if (shouldHideExpiringMessageBody) { if (shouldHideExpiringMessageBody) {
notificationMessage = i18n('newMessage'); notificationMessage = i18n('newMessage');
} else if (userSetting === NotificationSetting.NameOnly) { } else if (userSetting === NotificationSetting.NameOnly) {
if (reaction) { if (reaction) {
notificationMessage = i18n('notificationReaction', { notificationMessage = i18n('notificationReaction', {
sender: senderTitle,
emoji: reaction.emoji,
});
} else {
notificationMessage = i18n('newMessage');
}
} else if (reaction) {
notificationMessage = i18n('notificationReactionMessage', {
sender: senderTitle, sender: senderTitle,
emoji: reaction.emoji, emoji: reaction.emoji,
message,
}); });
} else { } else {
notificationMessage = i18n('newMessage'); notificationMessage = message;
} }
} else if (reaction) { break;
notificationMessage = i18n('notificationReactionMessage', {
sender: senderTitle,
emoji: reaction.emoji,
message,
});
} else {
notificationMessage = message;
} }
} else { case NotificationSetting.NoNameOrMessage:
if (userSetting !== NotificationSetting.NoNameOrMessage) { notificationTitle = FALLBACK_NOTIFICATION_TITLE;
window.SignalWindow.log.error( notificationMessage = i18n('newMessage');
`Error: Unknown user notification setting: '${userSetting}'` break;
); default:
} log.error(missingCaseError(userSetting));
notificationTitle = FALLBACK_NOTIFICATION_TITLE; notificationTitle = FALLBACK_NOTIFICATION_TITLE;
notificationMessage = i18n('newMessage'); notificationMessage = i18n('newMessage');
break;
} }
log.info('Showing a notification');
this.notify({ this.notify({
title: notificationTitle, title: notificationTitle,
icon: notificationIconUrl, icon: notificationIconUrl,