Add Notifications.getStatus
This commit is contained in:
parent
5fe5320760
commit
d5b391757d
3 changed files with 64 additions and 0 deletions
|
@ -200,6 +200,7 @@ window.Signal.Migrations.Migrations0DatabaseWithAttachmentData = require('./js/m
|
||||||
window.Signal.Migrations.Migrations1DatabaseWithoutAttachmentData = require('./js/modules/migrations/migrations_1_database_without_attachment_data');
|
window.Signal.Migrations.Migrations1DatabaseWithoutAttachmentData = require('./js/modules/migrations/migrations_1_database_without_attachment_data');
|
||||||
|
|
||||||
window.Signal.Migrations.upgradeMessageSchema = upgradeMessageSchema;
|
window.Signal.Migrations.upgradeMessageSchema = upgradeMessageSchema;
|
||||||
|
window.Signal.Notifications = require('./ts/notifications');
|
||||||
window.Signal.OS = require('./js/modules/os');
|
window.Signal.OS = require('./js/modules/os');
|
||||||
window.Signal.Settings = require('./js/modules/settings');
|
window.Signal.Settings = require('./js/modules/settings');
|
||||||
window.Signal.Startup = require('./js/modules/startup');
|
window.Signal.Startup = require('./js/modules/startup');
|
||||||
|
|
60
ts/notifications/getStatus.ts
Normal file
60
ts/notifications/getStatus.ts
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
interface Environment {
|
||||||
|
isAppFocused: boolean;
|
||||||
|
isAudioNotificationEnabled: boolean;
|
||||||
|
isAudioNotificationSupported: boolean;
|
||||||
|
isEnabled: boolean;
|
||||||
|
numNotifications: number;
|
||||||
|
userSetting: UserSetting;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Status {
|
||||||
|
shouldClearNotifications: boolean;
|
||||||
|
shouldPlayNotificationSound: boolean;
|
||||||
|
shouldShowNotifications: boolean;
|
||||||
|
type: Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserSetting = 'off' | 'count' | 'name' | 'message';
|
||||||
|
|
||||||
|
type Type =
|
||||||
|
| 'ok'
|
||||||
|
| 'disabled'
|
||||||
|
| 'appIsFocused'
|
||||||
|
| 'noNotifications'
|
||||||
|
| 'userSetting';
|
||||||
|
|
||||||
|
export const getStatus = (environment: Environment): Status => {
|
||||||
|
const type = ((): Type => {
|
||||||
|
if (!environment.isEnabled) {
|
||||||
|
return 'disabled';
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasNotifications = environment.numNotifications > 0;
|
||||||
|
if (!hasNotifications) {
|
||||||
|
return 'noNotifications';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (environment.isAppFocused) {
|
||||||
|
return 'appIsFocused';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (environment.userSetting === 'off') {
|
||||||
|
return 'userSetting';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'ok';
|
||||||
|
})();
|
||||||
|
|
||||||
|
const shouldPlayNotificationSound =
|
||||||
|
environment.isAudioNotificationSupported &&
|
||||||
|
environment.isAudioNotificationEnabled;
|
||||||
|
const shouldShowNotifications = type === 'ok';
|
||||||
|
const shouldClearNotifications = type === 'appIsFocused';
|
||||||
|
|
||||||
|
return {
|
||||||
|
shouldClearNotifications,
|
||||||
|
shouldPlayNotificationSound,
|
||||||
|
shouldShowNotifications,
|
||||||
|
type,
|
||||||
|
};
|
||||||
|
};
|
3
ts/notifications/index.ts
Normal file
3
ts/notifications/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import { getStatus } from './getStatus';
|
||||||
|
|
||||||
|
export { getStatus };
|
Loading…
Add table
Reference in a new issue