@inngageregistry/inngage-react 3.3.1 → 4.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Inngage.ts +126 -131
- package/src/api/api.ts +28 -0
- package/src/{services → api}/handler.ts +21 -9
- package/src/components/in_app.tsx +102 -0
- package/src/components/modal.tsx +221 -0
- package/src/components/styles.ts +91 -91
- package/src/firebase/notifications_listener.ts +117 -0
- package/src/index.ts +2 -2
- package/src/models/requests.ts +42 -0
- package/src/services/api_service.ts +30 -0
- package/src/utils.ts +0 -24
- package/src/components/Inapp.tsx +0 -321
- package/src/notificationsListener.ts +0 -178
- package/src/services/inngage.ts +0 -23
package/src/components/Inapp.tsx
DELETED
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Modal,
|
|
4
|
-
View,
|
|
5
|
-
Text,
|
|
6
|
-
TouchableHighlight,
|
|
7
|
-
TouchableOpacity,
|
|
8
|
-
Image,
|
|
9
|
-
ScrollView,
|
|
10
|
-
ImageBackground,
|
|
11
|
-
Linking,
|
|
12
|
-
Dimensions,
|
|
13
|
-
} from "react-native";
|
|
14
|
-
import DeviceInfo from "react-native-device-info";
|
|
15
|
-
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
16
|
-
import Carousel, { Pagination } from 'react-native-snap-carousel';
|
|
17
|
-
|
|
18
|
-
import { showAlertLink, isEmpty } from "../utils";
|
|
19
|
-
import { linkInApp } from "../notificationsListener";
|
|
20
|
-
import { styleInapp, styleItem } from './styles';
|
|
21
|
-
|
|
22
|
-
const SLIDER_WIDTH = Dimensions.get('window').width;
|
|
23
|
-
const SLIDER_HEIGHT = Dimensions.get('window').height;
|
|
24
|
-
const ITEM_WIDTH = Math.round(SLIDER_WIDTH * 0.8);
|
|
25
|
-
const ITEM_HEIGHT = Math.round(SLIDER_HEIGHT * 0.8);
|
|
26
|
-
|
|
27
|
-
export interface InappProps {
|
|
28
|
-
mediaStyle?: any;
|
|
29
|
-
titleStyle?: any;
|
|
30
|
-
bodyStyle?: any;
|
|
31
|
-
buttonLeftStyle?: any;
|
|
32
|
-
buttonRightStyle?: any;
|
|
33
|
-
buttonTitleLeftStyle?: any;
|
|
34
|
-
buttonTitleRightStyle?: any;
|
|
35
|
-
styleContainer?: any;
|
|
36
|
-
onClose?: 'clear';
|
|
37
|
-
}
|
|
38
|
-
export const Inapp = (props: InappProps) => {
|
|
39
|
-
const [data, setData] = useState<any>([])
|
|
40
|
-
const [indIm, setIndImg] = useState(0)
|
|
41
|
-
const [visible, setVisible] = useState(true)
|
|
42
|
-
const [bgImage, setbgImage] = useState<any>(undefined) // TODO, need a placeholder
|
|
43
|
-
|
|
44
|
-
const CarouselRef = useRef<Carousel<any>>(null);
|
|
45
|
-
const ScrollRef1 = useRef<ScrollView>(null);
|
|
46
|
-
const ScrollRef2 = useRef<ScrollView>(null);
|
|
47
|
-
const ScrollRef3 = useRef<ScrollView>(null);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
interface _renderItemProps {
|
|
51
|
-
item: any;
|
|
52
|
-
index: number;
|
|
53
|
-
}
|
|
54
|
-
const _renderItem = ({ item, index }: _renderItemProps) => {
|
|
55
|
-
let msg = JSON.parse(item.data.additional_data)
|
|
56
|
-
let arrayImgs: any = []
|
|
57
|
-
let indImg = 0
|
|
58
|
-
|
|
59
|
-
const checkBG = () => {
|
|
60
|
-
if (msg.background_img != '') {
|
|
61
|
-
return null
|
|
62
|
-
} else {
|
|
63
|
-
return msg.background_color
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const itemStyles = styleItem({ msg, checkBG })
|
|
68
|
-
|
|
69
|
-
const chooseRef = () => {
|
|
70
|
-
if (index == 0) {
|
|
71
|
-
return ScrollRef1
|
|
72
|
-
}
|
|
73
|
-
if (index == 1) {
|
|
74
|
-
return ScrollRef2
|
|
75
|
-
}
|
|
76
|
-
if (index == 2) {
|
|
77
|
-
return ScrollRef3
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const pagination = ref => {
|
|
83
|
-
return (
|
|
84
|
-
<Pagination
|
|
85
|
-
dotsLength={arrayImgs.length}
|
|
86
|
-
activeDotIndex={indIm}
|
|
87
|
-
containerStyle={{ height: 2, padding: 0, margin: 0 }}
|
|
88
|
-
renderDots={(activeIndex, total, context) => {
|
|
89
|
-
let dots: any = []
|
|
90
|
-
var size = 0
|
|
91
|
-
for (let i = 0; i < total; i++) {
|
|
92
|
-
if (activeIndex == i) {
|
|
93
|
-
size = 13
|
|
94
|
-
} else {
|
|
95
|
-
size = 8
|
|
96
|
-
}
|
|
97
|
-
dots.push(
|
|
98
|
-
<TouchableOpacity
|
|
99
|
-
onPress={() => {
|
|
100
|
-
ref.current.scrollTo({ x: i * 220, y: 0, animated: true })
|
|
101
|
-
if (i * 220 === 0) {
|
|
102
|
-
setIndImg(0)
|
|
103
|
-
} else if (i * 220 === 220) {
|
|
104
|
-
setIndImg(1)
|
|
105
|
-
} else if (i * 220 === 440) {
|
|
106
|
-
setIndImg(2)
|
|
107
|
-
}
|
|
108
|
-
}}
|
|
109
|
-
key={i.toString()}
|
|
110
|
-
style={[itemStyles.dot, { width: size, height: size }]}
|
|
111
|
-
/>
|
|
112
|
-
)
|
|
113
|
-
}
|
|
114
|
-
return (
|
|
115
|
-
dots
|
|
116
|
-
)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
/>
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const handleButton = (title: string, body: string, url: string, type: string) => {
|
|
124
|
-
if (type === '' || url === '') {
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
const openLinkByType = (type, url) => (type === 'deep' ? Linking.openURL(url) : linkInApp(url))
|
|
128
|
-
|
|
129
|
-
return Linking.canOpenURL(url).then((supported) => {
|
|
130
|
-
if (supported) {
|
|
131
|
-
showAlertLink(
|
|
132
|
-
title,
|
|
133
|
-
body,
|
|
134
|
-
`${DeviceInfo.getApplicationName()}`,
|
|
135
|
-
`Acessar ${url} ?`,
|
|
136
|
-
).then(() => { supported && openLinkByType(type, url) })
|
|
137
|
-
}
|
|
138
|
-
}).catch(console.error)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const imgCarosel = () => {
|
|
142
|
-
if (msg.rich_content.carousel == true) {
|
|
143
|
-
if (msg.rich_content.img1 != '') {
|
|
144
|
-
arrayImgs.push({ url: msg.rich_content.img1 })
|
|
145
|
-
}
|
|
146
|
-
if (msg.rich_content.img2 != '') {
|
|
147
|
-
arrayImgs.push({ url: msg.rich_content.img2 })
|
|
148
|
-
}
|
|
149
|
-
if (msg.rich_content.img3 != '') {
|
|
150
|
-
arrayImgs.push({ url: msg.rich_content.img3 })
|
|
151
|
-
}
|
|
152
|
-
let arrayElements = arrayImgs.map((item, index) => (
|
|
153
|
-
<Image key={index.toString()} style={[props.mediaStyle, { width: 200, height: 200, marginRight: 10 }]} source={{ uri: item.url }} />
|
|
154
|
-
));
|
|
155
|
-
return arrayElements
|
|
156
|
-
} else if (arrayImgs.length <= 0) {
|
|
157
|
-
return (
|
|
158
|
-
<Image style={[props.mediaStyle, { width: 200, height: 200 }]} source={{ uri: item.data.picture }} />
|
|
159
|
-
)
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
return (
|
|
163
|
-
<Image style={[props.mediaStyle, { width: 200, height: 200 }]} source={{ uri: item.data.picture }} />
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return (
|
|
168
|
-
<View style={[itemStyles.body]}>
|
|
169
|
-
<Text style={[itemStyles.title, props.titleStyle]}>{msg.title}</Text>
|
|
170
|
-
<ScrollView
|
|
171
|
-
ref={chooseRef()}
|
|
172
|
-
horizontal
|
|
173
|
-
snapToInterval={220}
|
|
174
|
-
decelerationRate="fast"
|
|
175
|
-
showsHorizontalScrollIndicator={false}
|
|
176
|
-
style={{ width: 200, height: 240 }}
|
|
177
|
-
contentContainerStyle={{ alignItems: 'center', justifyContent: 'center' }}
|
|
178
|
-
onMomentumScrollEnd={(e) => {
|
|
179
|
-
if (Math.round(e.nativeEvent.contentOffset.x) === 0
|
|
180
|
-
) {
|
|
181
|
-
indImg = 0
|
|
182
|
-
setIndImg(indImg)
|
|
183
|
-
}
|
|
184
|
-
if (Math.round(e.nativeEvent.contentOffset.x) === 220
|
|
185
|
-
) {
|
|
186
|
-
indImg = 1
|
|
187
|
-
setIndImg(indImg)
|
|
188
|
-
}
|
|
189
|
-
if (Math.round(e.nativeEvent.contentOffset.x) === 430
|
|
190
|
-
) {
|
|
191
|
-
indImg = 2
|
|
192
|
-
setIndImg(indImg)
|
|
193
|
-
}
|
|
194
|
-
}}
|
|
195
|
-
>
|
|
196
|
-
{imgCarosel()}
|
|
197
|
-
</ScrollView>
|
|
198
|
-
{
|
|
199
|
-
msg.rich_content.carousel == true ?
|
|
200
|
-
pagination(chooseRef()) : null
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
<Text style={[itemStyles.bodyText, props.bodyStyle]}>{msg.body}</Text>
|
|
204
|
-
<View style={{ flexDirection: "row", marginBottom: 0, justifyContent: 'center' }}>
|
|
205
|
-
<TouchableOpacity onPress={() => handleButton(msg.title, msg.body, msg.btn_left_action_link, msg.btn_left_action_type)} style={[itemStyles.btn_left, props.buttonLeftStyle]}>
|
|
206
|
-
<View>
|
|
207
|
-
<Text style={[itemStyles.btn_left_title, props.buttonTitleLeftStyle]}>{msg.btn_left_txt}</Text>
|
|
208
|
-
</View>
|
|
209
|
-
</TouchableOpacity>
|
|
210
|
-
<TouchableOpacity onPress={() => handleButton(msg.title, msg.body, msg.btn_right_action_link, msg.btn_right_action_type)} style={[itemStyles.btn_right, props.buttonRightStyle]}>
|
|
211
|
-
<View>
|
|
212
|
-
<Text style={[itemStyles.btn_right_title, props.buttonTitleRightStyle]}>{msg.btn_right_txt}</Text>
|
|
213
|
-
</View>
|
|
214
|
-
</TouchableOpacity>
|
|
215
|
-
</View>
|
|
216
|
-
</View>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
useEffect(() => {
|
|
221
|
-
onLoad();
|
|
222
|
-
}, [])
|
|
223
|
-
|
|
224
|
-
const onLoad = async () => {
|
|
225
|
-
let temp: any = []
|
|
226
|
-
const messages = JSON.parse(await AsyncStorage.getItem('inngage') ?? '[]')
|
|
227
|
-
|
|
228
|
-
if (messages !== null) {
|
|
229
|
-
messages.forEach((el) => {
|
|
230
|
-
if (!isEmpty(el)) {
|
|
231
|
-
temp.push(el)
|
|
232
|
-
}
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
let msg: any = {}
|
|
236
|
-
if (temp.length > 0 && temp[0]?.data?.additional_data) {
|
|
237
|
-
msg = JSON.parse(temp[0].data.additional_data)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (msg.background_img != '') {
|
|
241
|
-
setbgImage({ uri: msg.background_img })
|
|
242
|
-
} else {
|
|
243
|
-
setbgImage(undefined)
|
|
244
|
-
}
|
|
245
|
-
setData(temp)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const handleClose = async () => {
|
|
250
|
-
if (props.onClose) {
|
|
251
|
-
if (props.onClose.toLowerCase() === 'clear') {
|
|
252
|
-
await AsyncStorage.removeItem('inngage');
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
setVisible(false)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const handleBg = index => {
|
|
259
|
-
let msg = JSON.parse(data[index].data.additional_data)
|
|
260
|
-
if (msg.background_img != '') {
|
|
261
|
-
setbgImage({ uri: msg.background_img })
|
|
262
|
-
} else {
|
|
263
|
-
setbgImage(undefined)
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (data.length > 0) {
|
|
268
|
-
return (
|
|
269
|
-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
|
270
|
-
<Modal
|
|
271
|
-
animationType='slide'
|
|
272
|
-
visible={visible}
|
|
273
|
-
transparent={true}
|
|
274
|
-
style={{ justifyContent: 'center', alignItems: 'center', backgroundColor: 'blue' }}
|
|
275
|
-
><View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
|
276
|
-
<View style={[styles.styleContainer, props.styleContainer]}>
|
|
277
|
-
<ImageBackground style={{ width: '100%', alignItems: 'center', justifyContent: 'center' }} resizeMode='cover' imageStyle={{ borderRadius: 10, alignSelf: 'stretch', height: 480 }} source={bgImage}>
|
|
278
|
-
<TouchableHighlight
|
|
279
|
-
onPress={() => handleClose()}
|
|
280
|
-
underlayColor='#cccccc'
|
|
281
|
-
style={styles.closeButton}
|
|
282
|
-
>
|
|
283
|
-
<Text style={{ fontWeight: 'bold', color: '#ffffff' }}>
|
|
284
|
-
X
|
|
285
|
-
</Text>
|
|
286
|
-
</TouchableHighlight>
|
|
287
|
-
<Carousel
|
|
288
|
-
vertical
|
|
289
|
-
ref={CarouselRef}
|
|
290
|
-
layout={'default'}
|
|
291
|
-
layoutCardOffset={10}
|
|
292
|
-
data={data}
|
|
293
|
-
inactiveSlideOpacity={0}
|
|
294
|
-
containerCustomStyle={{
|
|
295
|
-
backgroundColor: 'white',
|
|
296
|
-
elevation: 10,
|
|
297
|
-
borderRadius: 10,
|
|
298
|
-
width: SLIDER_WIDTH * 0.8,
|
|
299
|
-
height: 480,
|
|
300
|
-
}}
|
|
301
|
-
contentContainerCustomStyle={{ justifyContent: 'center' }}
|
|
302
|
-
inactiveSlideShift={0}
|
|
303
|
-
onSnapToItem={(index) => {
|
|
304
|
-
handleBg(index)
|
|
305
|
-
}}
|
|
306
|
-
renderItem={({ item, index }) => _renderItem({ item, index })}
|
|
307
|
-
sliderHeight={500}
|
|
308
|
-
itemHeight={500}
|
|
309
|
-
/>
|
|
310
|
-
</ImageBackground>
|
|
311
|
-
</View>
|
|
312
|
-
</View>
|
|
313
|
-
</Modal>
|
|
314
|
-
</View>
|
|
315
|
-
);
|
|
316
|
-
} else {
|
|
317
|
-
return null
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
const styles = styleInapp({ SLIDER_WIDTH })
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { Linking } from 'react-native'
|
|
2
|
-
import InAppBrowser from 'react-native-inappbrowser-reborn'
|
|
3
|
-
import messaging from '@react-native-firebase/messaging';
|
|
4
|
-
import { showAlert } from './utils'
|
|
5
|
-
import { notificationApi } from './services/inngage'
|
|
6
|
-
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
7
|
-
import PushNotification, { Importance } from 'react-native-push-notification'
|
|
8
|
-
|
|
9
|
-
export const linkInApp = (link: string) => {
|
|
10
|
-
InAppBrowser.open(link, {
|
|
11
|
-
dismissButtonStyle: 'cancel',
|
|
12
|
-
preferredBarTintColor: 'gray',
|
|
13
|
-
preferredControlTintColor: 'white',
|
|
14
|
-
readerMode: false,
|
|
15
|
-
showTitle: true,
|
|
16
|
-
toolbarColor: '#6200EE',
|
|
17
|
-
secondaryToolbarColor: 'black',
|
|
18
|
-
enableUrlBarHiding: true,
|
|
19
|
-
enableDefaultShare: true,
|
|
20
|
-
forceCloseOnRedirection: false,
|
|
21
|
-
animations: {
|
|
22
|
-
startEnter: 'slide_in_right',
|
|
23
|
-
startExit: 'slide_out_left',
|
|
24
|
-
endEnter: 'slide_in_right',
|
|
25
|
-
endExit: 'slide_out_left',
|
|
26
|
-
},
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const openLinkByType = (type: string, url: string) => {
|
|
31
|
-
const linkTypeHandlers: Record<string, () => void> = {
|
|
32
|
-
deep: () => Linking.openURL(url),
|
|
33
|
-
// inapp: () => linkInApp(url),
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const handler = linkTypeHandlers[type];
|
|
37
|
-
if (handler) {
|
|
38
|
-
handler();
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const openCommonNotification = ({ appToken, dev, remoteMessage, enableAlert, state }) => {
|
|
43
|
-
if (!remoteMessage)
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
const { data } = remoteMessage
|
|
47
|
-
if (!data || (data && !Object.keys(data).length))
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
const { notId, title, body, type, url } = data
|
|
51
|
-
const request = {
|
|
52
|
-
notificationRequest: {
|
|
53
|
-
id: notId,
|
|
54
|
-
app_token: appToken,
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (url) {
|
|
59
|
-
Linking.canOpenURL(url).then((supported) => {
|
|
60
|
-
if (supported) {
|
|
61
|
-
supported && openLinkByType(type, url)
|
|
62
|
-
}
|
|
63
|
-
}).catch(console.error)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return notificationApi(request, dev)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const handleUniqueRemoteMessage = async (
|
|
70
|
-
remoteMessage: { messageId?: string },
|
|
71
|
-
handleInitialNotification: (value: { messageId?: string }) => void
|
|
72
|
-
) => {
|
|
73
|
-
try {
|
|
74
|
-
const lastRemoteMessageId = await AsyncStorage.getItem('LAST_REMOTE_MESSAGE_ID');
|
|
75
|
-
const newRemoteMessageId = remoteMessage?.messageId;
|
|
76
|
-
|
|
77
|
-
if (newRemoteMessageId && lastRemoteMessageId !== newRemoteMessageId) {
|
|
78
|
-
await AsyncStorage.setItem('LAST_REMOTE_MESSAGE_ID', newRemoteMessageId);
|
|
79
|
-
handleInitialNotification(remoteMessage);
|
|
80
|
-
}
|
|
81
|
-
} catch (e) {
|
|
82
|
-
console.error(e);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export interface notificationsListenerProps {
|
|
87
|
-
appToken: string,
|
|
88
|
-
dev?: boolean,
|
|
89
|
-
enableAlert: boolean,
|
|
90
|
-
onNotificationOpenedApp?: any,
|
|
91
|
-
}
|
|
92
|
-
export default async ({ appToken, dev, enableAlert, onNotificationOpenedApp }: notificationsListenerProps) => {
|
|
93
|
-
var messageArray: any = [];
|
|
94
|
-
|
|
95
|
-
if (typeof onNotificationOpenedApp == 'function') {
|
|
96
|
-
messaging().getInitialNotification().then(async (value) => {
|
|
97
|
-
onNotificationOpenedApp(value?.data);
|
|
98
|
-
if (value !== null)
|
|
99
|
-
handleUniqueRemoteMessage(value, async (value) => {
|
|
100
|
-
await handleInitialNotification(value);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const handleBackgroundMessage = async (remoteMessage: any) => {
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const handleNotificationOpenedApp = async (remoteMessage: any) => {
|
|
109
|
-
await openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'Background' })
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const handleInitialNotification = async (remoteMessage: any) => {
|
|
113
|
-
await openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'Closed' })
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const handleForegroundMessage = async (remoteMessage: any) => {
|
|
117
|
-
try {
|
|
118
|
-
PushNotification.configure({
|
|
119
|
-
onNotification: function (notification) {
|
|
120
|
-
openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'Foreground' })
|
|
121
|
-
},
|
|
122
|
-
popInitialNotification: true,
|
|
123
|
-
requestPermissions: true
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
PushNotification.createChannel({
|
|
127
|
-
channelId: 'high_importance_channel',
|
|
128
|
-
channelName: 'default',
|
|
129
|
-
importance: Importance.HIGH,
|
|
130
|
-
playSound: true,
|
|
131
|
-
soundName: 'default',
|
|
132
|
-
vibrate: true
|
|
133
|
-
}, (created) => {
|
|
134
|
-
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
} catch (e) {
|
|
138
|
-
console.error(e)
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
PushNotification.localNotification({
|
|
142
|
-
autoCancel: true,
|
|
143
|
-
title: remoteMessage.data!.title,
|
|
144
|
-
message: remoteMessage.data!.body,
|
|
145
|
-
vibration: 300,
|
|
146
|
-
channelId: "high_importance_channel"
|
|
147
|
-
});
|
|
148
|
-
} catch (e) {
|
|
149
|
-
console.error(e)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (remoteMessage != null && remoteMessage.data!.additional_data) {
|
|
153
|
-
let msg = JSON.parse(remoteMessage.data!.additional_data)
|
|
154
|
-
if (msg.inapp_message == true) {
|
|
155
|
-
const currentMessages = await AsyncStorage.getItem('inngage');
|
|
156
|
-
if (currentMessages !== null) {
|
|
157
|
-
messageArray = JSON.parse(currentMessages);
|
|
158
|
-
}
|
|
159
|
-
messageArray.push(remoteMessage);
|
|
160
|
-
await AsyncStorage.setItem('inngage', JSON.stringify(messageArray));
|
|
161
|
-
}
|
|
162
|
-
} else if (remoteMessage != null && !remoteMessage.data!.additional_data) {
|
|
163
|
-
if (enableAlert) {
|
|
164
|
-
showAlert(remoteMessage.data!.title, remoteMessage.data!.body)
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
messaging().setBackgroundMessageHandler(handleBackgroundMessage)
|
|
170
|
-
messaging().onNotificationOpenedApp(handleNotificationOpenedApp)
|
|
171
|
-
messaging().getInitialNotification().then(async (remoteMessage) => {
|
|
172
|
-
if (remoteMessage !== null)
|
|
173
|
-
handleUniqueRemoteMessage(remoteMessage, async (value) => {
|
|
174
|
-
await handleInitialNotification(value);
|
|
175
|
-
});
|
|
176
|
-
})
|
|
177
|
-
messaging().onMessage(handleForegroundMessage)
|
|
178
|
-
}
|
package/src/services/inngage.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { InngageProperties } from '../models/inngage_properties'
|
|
2
|
-
import { fetchClient } from './handler'
|
|
3
|
-
|
|
4
|
-
export const subscriptionApi = (request, dev = false) => {
|
|
5
|
-
if (InngageProperties.getDebugMode())
|
|
6
|
-
console.log('subscriptionApi', request)
|
|
7
|
-
return fetchClient('POST', request, '/subscription/', !!dev)
|
|
8
|
-
}
|
|
9
|
-
export const notificationApi = (request, dev = false) => {
|
|
10
|
-
if (InngageProperties.getDebugMode())
|
|
11
|
-
console.log('notificationApi', request)
|
|
12
|
-
return fetchClient('POST', request, '/notification/', !!dev)
|
|
13
|
-
}
|
|
14
|
-
export const eventsApi = (request, dev = false) => {
|
|
15
|
-
if (InngageProperties.getDebugMode())
|
|
16
|
-
console.log('eventsApi', request)
|
|
17
|
-
return fetchClient('POST', request, '/events/newEvent/', !!dev)
|
|
18
|
-
}
|
|
19
|
-
export const addUserDataApi = (request, dev = false) => {
|
|
20
|
-
if (InngageProperties.getDebugMode())
|
|
21
|
-
console.log('addUserData', request)
|
|
22
|
-
return fetchClient('POST', request, '/subscription/addCustomField', !!dev)
|
|
23
|
-
}
|