-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpush.ts
99 lines (85 loc) · 2.57 KB
/
push.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
/* tslint:disable:no-bitwise */
import { BatchSDK } from "../../types";
import { Push as PushActions } from "../actions";
import { sendToBridge, sendToBridgePromise, writeBatchLog } from "../helpers";
/**
* Android Notification Types enum.
*/
export enum AndroidNotificationTypes {
NONE = 0,
SOUND = 1 << 0,
VIBRATE = 1 << 1,
LIGHTS = 1 << 2,
ALERT = 1 << 3,
}
/**
* iOS Notification Types enum.
*/
export enum iOSNotificationTypes {
NONE = 0,
BADGE = 1 << 0,
SOUND = 1 << 1,
ALERT = 1 << 2,
}
export class PushModule implements BatchSDK.PushModule {
public AndroidNotificationTypes: typeof AndroidNotificationTypes;
public iOSNotificationTypes: typeof iOSNotificationTypes;
constructor() {
this.AndroidNotificationTypes = AndroidNotificationTypes;
this.iOSNotificationTypes = iOSNotificationTypes;
}
public refreshToken(): void {
sendToBridge(null, PushActions.RefreshToken, null);
}
public requestNotificationAuthorization(): void {
sendToBridge(null, PushActions.RequestAuthorization, null);
}
public requestProvisionalNotificationAuthorization(): void {
sendToBridge(null, PushActions.RequestProvisionalAuthorization, null);
}
public setAndroidNotificationTypes(
notifTypes: AndroidNotificationTypes
): void {
if (typeof notifTypes !== "number") {
writeBatchLog(
false,
"notifTypes must be a number (of the AndroidNotificationTypes enum)"
);
} else {
sendToBridge(null, PushActions.SetAndroidNotifTypes, [{ notifTypes }]);
}
}
public setiOSNotificationTypes(notifTypes: iOSNotificationTypes): void {
if (typeof notifTypes !== "number") {
writeBatchLog(
false,
"notifTypes must be a number (of the iOSNotificationTypes enum)"
);
return;
} else {
sendToBridge(null, PushActions.SetIOSNotifTypes, [{ notifTypes }]);
}
}
public setiOSShowForegroundNotifications(showForeground: boolean): void {
if (typeof showForeground !== "boolean") {
writeBatchLog(
false,
"setiOSShowForegroundNotifications expects a boolean argument"
);
return;
} else {
sendToBridge(null, PushActions.SetIOSShowForegroundNotifications, [
{ showForeground },
]);
}
}
public clearBadge(): void {
sendToBridge(null, PushActions.ClearBadge, null);
}
public dismissNotifications(): void {
sendToBridge(null, PushActions.DismissNotifications, null);
}
public getLastKnownPushToken(): Promise<undefined | string> {
return sendToBridgePromise(PushActions.GetLastKnownPushToken, null);
}
}