Log whether OS supports native notifications
This commit is contained in:
parent
1f2a2e1d52
commit
4e6a03a91c
2 changed files with 32 additions and 18 deletions
|
@ -42,12 +42,14 @@
|
|||
const isAudioNotificationSupported = Settings.isAudioNotificationSupported();
|
||||
const numNotifications = this.length;
|
||||
const userSetting = this.getUserSetting();
|
||||
const hasNotificationSupport = !Boolean(config.polyfillNotifications);
|
||||
|
||||
const status = Signal.Notifications.getStatus({
|
||||
isEnabled,
|
||||
hasNotificationSupport,
|
||||
isAppFocused,
|
||||
isAudioNotificationEnabled,
|
||||
isAudioNotificationSupported,
|
||||
isEnabled,
|
||||
numNotifications,
|
||||
userSetting,
|
||||
});
|
||||
|
@ -102,16 +104,7 @@
|
|||
|
||||
drawAttention();
|
||||
|
||||
if (config.polyfillNotifications) {
|
||||
nodeNotifier.notify({
|
||||
title,
|
||||
message,
|
||||
sound: false,
|
||||
});
|
||||
nodeNotifier.on('click', () => {
|
||||
last.get('conversationId');
|
||||
});
|
||||
} else {
|
||||
if (hasNotificationSupport) {
|
||||
const notification = new Notification(title, {
|
||||
body: message,
|
||||
icon: iconUrl,
|
||||
|
@ -123,6 +116,15 @@
|
|||
this,
|
||||
last.get('conversationId')
|
||||
);
|
||||
} else {
|
||||
nodeNotifier.notify({
|
||||
title,
|
||||
message,
|
||||
sound: false,
|
||||
});
|
||||
nodeNotifier.on('click', () => {
|
||||
last.get('conversationId');
|
||||
});
|
||||
}
|
||||
|
||||
// We don't want to notify the user about these same messages again
|
||||
|
|
|
@ -4,6 +4,7 @@ interface Environment {
|
|||
isAudioNotificationSupported: boolean;
|
||||
isEnabled: boolean;
|
||||
numNotifications: number;
|
||||
hasNotificationSupport: boolean;
|
||||
userSetting: UserSetting;
|
||||
}
|
||||
|
||||
|
@ -11,6 +12,7 @@ interface Status {
|
|||
shouldClearNotifications: boolean;
|
||||
shouldPlayNotificationSound: boolean;
|
||||
shouldShowNotifications: boolean;
|
||||
hasNotificationSupport: boolean;
|
||||
type: Type;
|
||||
}
|
||||
|
||||
|
@ -23,22 +25,30 @@ type Type =
|
|||
| 'noNotifications'
|
||||
| 'userSetting';
|
||||
|
||||
export const getStatus = (environment: Environment): Status => {
|
||||
export const getStatus = ({
|
||||
hasNotificationSupport,
|
||||
isAppFocused,
|
||||
isAudioNotificationEnabled,
|
||||
isAudioNotificationSupported,
|
||||
isEnabled,
|
||||
numNotifications,
|
||||
userSetting,
|
||||
}: Environment): Status => {
|
||||
const type = ((): Type => {
|
||||
if (!environment.isEnabled) {
|
||||
if (!isEnabled) {
|
||||
return 'disabled';
|
||||
}
|
||||
|
||||
const hasNotifications = environment.numNotifications > 0;
|
||||
const hasNotifications = numNotifications > 0;
|
||||
if (!hasNotifications) {
|
||||
return 'noNotifications';
|
||||
}
|
||||
|
||||
if (environment.isAppFocused) {
|
||||
if (isAppFocused) {
|
||||
return 'appIsFocused';
|
||||
}
|
||||
|
||||
if (environment.userSetting === 'off') {
|
||||
if (userSetting === 'off') {
|
||||
return 'userSetting';
|
||||
}
|
||||
|
||||
|
@ -46,12 +56,14 @@ export const getStatus = (environment: Environment): Status => {
|
|||
})();
|
||||
|
||||
const shouldPlayNotificationSound =
|
||||
environment.isAudioNotificationSupported &&
|
||||
environment.isAudioNotificationEnabled;
|
||||
isAudioNotificationSupported &&
|
||||
isAudioNotificationEnabled &&
|
||||
hasNotificationSupport;
|
||||
const shouldShowNotifications = type === 'ok';
|
||||
const shouldClearNotifications = type === 'appIsFocused';
|
||||
|
||||
return {
|
||||
hasNotificationSupport,
|
||||
shouldClearNotifications,
|
||||
shouldPlayNotificationSound,
|
||||
shouldShowNotifications,
|
||||
|
|
Loading…
Reference in a new issue