-
Notifications
You must be signed in to change notification settings - Fork 379
Expand file tree
/
Copy pathOSNotification.ts
More file actions
139 lines (129 loc) · 4.3 KB
/
OSNotification.ts
File metadata and controls
139 lines (129 loc) · 4.3 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { NativeModules, Platform } from 'react-native';
const RNOneSignal = NativeModules.OneSignal;
export interface BaseNotificationData {
body: string;
sound?: string;
title?: string;
launchURL?: string;
rawPayload: object | string; // platform bridges return different types
actionButtons?: object[];
additionalData?: object;
notificationId: string;
}
interface AndroidNotificationData extends BaseNotificationData {
groupKey?: string;
groupMessage?: string;
ledColor?: string;
priority?: number;
smallIcon?: string;
largeIcon?: string;
bigPicture?: string;
collapseId?: string;
fromProjectNumber?: string;
smallIconAccentColor?: string;
lockScreenVisibility?: string;
androidNotificationId?: number;
}
interface iOSNotificationData extends BaseNotificationData {
badge?: string;
badgeIncrement?: string;
category?: string;
threadId?: string;
subtitle?: string;
templateId?: string;
templateName?: string;
attachments?: object;
mutableContent?: boolean;
contentAvailable?: string;
relevanceScore?: number;
interruptionLevel?: string;
}
export type OSNotificationData = AndroidNotificationData | iOSNotificationData;
export default class OSNotification {
body: string;
sound?: string;
title?: string;
launchURL?: string;
rawPayload: object | string; // platform bridges return different types
actionButtons?: object[];
additionalData?: object;
notificationId: string;
// android only
groupKey?: string;
groupMessage?: string;
ledColor?: string;
priority?: number;
smallIcon?: string;
largeIcon?: string;
bigPicture?: string;
collapseId?: string;
fromProjectNumber?: string;
smallIconAccentColor?: string;
lockScreenVisibility?: string;
androidNotificationId?: number;
// ios only
badge?: string;
badgeIncrement?: string;
category?: string;
threadId?: string;
subtitle?: string;
templateId?: string;
templateName?: string;
attachments?: object;
mutableContent?: boolean;
contentAvailable?: string;
relevanceScore?: number;
interruptionLevel?: string;
constructor(receivedEvent: OSNotificationData) {
this.body = receivedEvent.body;
this.sound = receivedEvent.sound;
this.title = receivedEvent.title;
this.launchURL = receivedEvent.launchURL;
this.rawPayload = receivedEvent.rawPayload;
this.actionButtons = receivedEvent.actionButtons;
this.additionalData = receivedEvent.additionalData;
this.notificationId = receivedEvent.notificationId;
/* v8 ignore else -- @preserve */
if (isAndroidNotificationData(receivedEvent)) {
this.groupKey = receivedEvent.groupKey;
this.ledColor = receivedEvent.ledColor;
this.priority = receivedEvent.priority;
this.smallIcon = receivedEvent.smallIcon;
this.largeIcon = receivedEvent.largeIcon;
this.bigPicture = receivedEvent.bigPicture;
this.collapseId = receivedEvent.collapseId;
this.groupMessage = receivedEvent.groupMessage;
this.fromProjectNumber = receivedEvent.fromProjectNumber;
this.smallIconAccentColor = receivedEvent.smallIconAccentColor;
this.lockScreenVisibility = receivedEvent.lockScreenVisibility;
this.androidNotificationId = receivedEvent.androidNotificationId;
} else if (isiOSNotificationData(receivedEvent)) {
this.badge = receivedEvent.badge;
this.category = receivedEvent.category;
this.threadId = receivedEvent.threadId;
this.subtitle = receivedEvent.subtitle;
this.templateId = receivedEvent.templateId;
this.attachments = receivedEvent.attachments;
this.templateName = receivedEvent.templateName;
this.mutableContent = receivedEvent.mutableContent;
this.badgeIncrement = receivedEvent.badgeIncrement;
this.contentAvailable = receivedEvent.contentAvailable;
this.relevanceScore = receivedEvent.relevanceScore;
this.interruptionLevel = receivedEvent.interruptionLevel;
}
}
display(): void {
RNOneSignal.displayNotification(this.notificationId);
return;
}
}
const isAndroidNotificationData = (
_data: AndroidNotificationData | iOSNotificationData,
): _data is AndroidNotificationData => {
return Platform.OS === 'android';
};
const isiOSNotificationData = (
_data: AndroidNotificationData | iOSNotificationData,
): _data is iOSNotificationData => {
return Platform.OS === 'ios';
};