-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathNotifications.ts
122 lines (106 loc) · 4 KB
/
Notifications.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { NativeCommandsSender } from './adapters/NativeCommandsSender';
import { NativeEventsReceiver } from './adapters/NativeEventsReceiver';
import { Commands } from './commands/Commands';
import { EventsRegistry } from './events/EventsRegistry';
import { EventsRegistryIOS } from './events/EventsRegistryIOS';
import { Notification } from './DTO/Notification';
import { UniqueIdProvider } from './adapters/UniqueIdProvider';
import { CompletionCallbackWrapper } from './adapters/CompletionCallbackWrapper';
import { NotificationCategory } from './interfaces/NotificationCategory';
import { NotificationChannel } from './interfaces/NotificationChannel';
import { NotificationsIOS } from './NotificationsIOS';
import { NotificationsAndroid } from './NotificationsAndroid';
import { NotificationFactory } from './DTO/NotificationFactory';
import { NotificationPermissionOptions } from './interfaces/NotificationPermissions';
export class NotificationsRoot {
public readonly _ios: NotificationsIOS;
public readonly _android: NotificationsAndroid;
private readonly notificationFactory: NotificationFactory;
private readonly nativeEventsReceiver: NativeEventsReceiver;
private readonly nativeCommandsSender: NativeCommandsSender;
private readonly commands: Commands;
private readonly eventsRegistry: EventsRegistry;
private readonly eventsRegistryIOS: EventsRegistryIOS;
private readonly uniqueIdProvider: UniqueIdProvider;
private readonly completionCallbackWrapper: CompletionCallbackWrapper;
constructor() {
this.notificationFactory = new NotificationFactory();
this.nativeEventsReceiver = new NativeEventsReceiver(this.notificationFactory);
this.nativeCommandsSender = new NativeCommandsSender();
this.completionCallbackWrapper = new CompletionCallbackWrapper(this.nativeCommandsSender);
this.uniqueIdProvider = new UniqueIdProvider();
this.commands = new Commands(
this.nativeCommandsSender,
this.uniqueIdProvider,
this.notificationFactory
);
this.eventsRegistry = new EventsRegistry(this.nativeEventsReceiver, this.completionCallbackWrapper);
this.eventsRegistryIOS = new EventsRegistryIOS(this.nativeEventsReceiver, this.completionCallbackWrapper);
this._ios = new NotificationsIOS(this.commands, this.eventsRegistryIOS);
this._android = new NotificationsAndroid(this.commands);
}
/**
* registerRemoteNotifications
*/
public registerRemoteNotifications(options?: NotificationPermissionOptions) {
this.ios.registerRemoteNotifications(options);
this.android.registerRemoteNotifications();
}
/**
* postLocalNotification
*/
public postLocalNotification(notification: Notification, id?: number) {
return this.commands.postLocalNotification(notification, id);
}
/**
* getInitialNotification
*/
public getInitialNotification(): Promise<Notification | undefined> {
return this.commands.getInitialNotification();
}
/**
* setCategories
*/
public setCategories(categories: [NotificationCategory?]) {
this.commands.setCategories(categories);
}
/**
* cancelLocalNotification
*/
public cancelLocalNotification(notificationId: string) {
return this.commands.cancelLocalNotification(notificationId);
}
/**
* removeAllDeliveredNotifications
*/
public removeAllDeliveredNotifications() {
return this.commands.removeAllDeliveredNotifications();
}
/**
* isRegisteredForRemoteNotifications
*/
public isRegisteredForRemoteNotifications(): Promise<boolean> {
return this.commands.isRegisteredForRemoteNotifications();
}
/**
* setNotificationChannel
*/
public setNotificationChannel(notificationChannel: NotificationChannel) {
return this.android.setNotificationChannel(notificationChannel);
}
/**
* Obtain the events registry instance
*/
public events(): EventsRegistry {
return this.eventsRegistry;
}
/**
* ios/android getters
*/
get ios(): NotificationsIOS {
return this._ios;
}
get android(): NotificationsAndroid {
return this._android;
}
}