@inngageregistry/inngage-react 2.2.8 → 2.3.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/ListenToNotifications.js +83 -74
- package/index.js +1 -0
- package/package.json +1 -1
- package/utils.js +9 -7
package/ListenToNotifications.js
CHANGED
|
@@ -5,6 +5,7 @@ import DeviceInfo from 'react-native-device-info'
|
|
|
5
5
|
import { showAlert, showAlertLink } from './utils'
|
|
6
6
|
import { notificationApi } from './inngageApi'
|
|
7
7
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
8
|
+
import PushNotification from 'react-native-push-notification'
|
|
8
9
|
|
|
9
10
|
export const linkInApp = (link) => {
|
|
10
11
|
InAppBrowser.open(link, {
|
|
@@ -38,10 +39,7 @@ export const openCommonNotification = (notificationData) => {
|
|
|
38
39
|
if (!data || (data && !Object.keys(data).length)) {
|
|
39
40
|
return
|
|
40
41
|
}
|
|
41
|
-
const { notId, title, body, type, url
|
|
42
|
-
// if (picture) {
|
|
43
|
-
// return openRichNotification(notificationData)
|
|
44
|
-
// }
|
|
42
|
+
const { notId, title, body, type, url } = data
|
|
45
43
|
const request = {
|
|
46
44
|
notificationRequest: {
|
|
47
45
|
id: notId,
|
|
@@ -49,78 +47,29 @@ export const openCommonNotification = (notificationData) => {
|
|
|
49
47
|
},
|
|
50
48
|
}
|
|
51
49
|
if (!url) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}).catch(console.log)
|
|
58
|
-
} else if (!enableAlert) {
|
|
59
|
-
return
|
|
60
|
-
} else {
|
|
61
|
-
return notificationApi(request, dev).then(() => {
|
|
62
|
-
if (enableAlert) {
|
|
63
|
-
showAlert(title, body)
|
|
64
|
-
}
|
|
65
|
-
}).catch(console.log)
|
|
66
|
-
}
|
|
50
|
+
|
|
51
|
+
return notificationApi(request, dev).then(() => {
|
|
52
|
+
|
|
53
|
+
}).catch(console.log)
|
|
54
|
+
|
|
67
55
|
}
|
|
68
56
|
return Linking.canOpenURL(url).then((supported) => {
|
|
69
57
|
if (supported) {
|
|
70
|
-
|
|
71
|
-
showAlertLink(
|
|
72
|
-
title,
|
|
73
|
-
body,
|
|
74
|
-
`${DeviceInfo.getApplicationName()}`,
|
|
75
|
-
`Acessar ${url} ?`,
|
|
76
|
-
).then((response) => { supported && openLinkByType(type, url) })
|
|
77
|
-
notificationApi(request, dev)
|
|
78
|
-
} else {
|
|
58
|
+
|
|
79
59
|
supported && openLinkByType(type, url)
|
|
80
|
-
|
|
60
|
+
|
|
81
61
|
}
|
|
82
62
|
}).catch(console.log)
|
|
83
63
|
}
|
|
84
64
|
export const openRichNotification = (notificationData) => {
|
|
85
|
-
//console.log("Rich push", notificationData)
|
|
86
|
-
//Rich push code
|
|
87
65
|
}
|
|
88
66
|
|
|
89
67
|
|
|
90
68
|
|
|
91
|
-
export default async ({ appToken, dev, enableAlert }) => {
|
|
69
|
+
export default async ({ appToken, dev, enableAlert, onNotificationOpenedApp }) => {
|
|
92
70
|
var messageArray = [];
|
|
93
71
|
|
|
94
|
-
|
|
95
|
-
console.log("Notification Oppened")
|
|
96
|
-
openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'Background' })
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
messaging().getInitialNotification(async (remoteMessage) => {
|
|
100
|
-
console.log("from quit")
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
firebase.messaging().onMessage(async (remoteMessage) => {
|
|
104
|
-
console.log('Push received: Foreground')
|
|
105
|
-
if (remoteMessage != null && remoteMessage.data.additional_data) {
|
|
106
|
-
let msg = JSON.parse(remoteMessage.data.additional_data)
|
|
107
|
-
if (msg.inapp_message == true) {
|
|
108
|
-
const currentMessages = await AsyncStorage.getItem('inngage');
|
|
109
|
-
if (currentMessages !== null) {
|
|
110
|
-
messageArray = JSON.parse(currentMessages);
|
|
111
|
-
}
|
|
112
|
-
messageArray.push(remoteMessage);
|
|
113
|
-
await AsyncStorage.setItem('inngage', JSON.stringify(messageArray));
|
|
114
|
-
}
|
|
115
|
-
} else if (remoteMessage != null && !remoteMessage.data.additional_data) {
|
|
116
|
-
console.log(remoteMessage.data.title)
|
|
117
|
-
if (enableAlert) {
|
|
118
|
-
showAlert(remoteMessage.data.title, remoteMessage.data.body)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'foreground' })
|
|
122
|
-
});
|
|
123
|
-
|
|
72
|
+
|
|
124
73
|
firebase.messaging().setBackgroundMessageHandler(async (remoteMessage) => {
|
|
125
74
|
console.log('Push received: Background')
|
|
126
75
|
|
|
@@ -151,24 +100,14 @@ export default async ({ appToken, dev, enableAlert }) => {
|
|
|
151
100
|
setTimeout(() => {
|
|
152
101
|
messaging().getInitialNotification().then(notification => {
|
|
153
102
|
if (!remoteMessage.data.url) {
|
|
154
|
-
if (enableAlert) {
|
|
155
|
-
showAlert(remoteMessage.data.title, remoteMessage.data.body)
|
|
156
|
-
}
|
|
157
103
|
notificationApi(request, dev)
|
|
158
104
|
} else {
|
|
159
105
|
notificationApi(request, dev)
|
|
160
106
|
Linking.canOpenURL(remoteMessage.data.url).then((supported) => {
|
|
161
107
|
if (supported) {
|
|
162
|
-
|
|
163
|
-
showAlertLink(
|
|
164
|
-
remoteMessage.data.title,
|
|
165
|
-
remoteMessage.data.body,
|
|
166
|
-
`${DeviceInfo.getApplicationName()}`,
|
|
167
|
-
`Acessar ${remoteMessage.data.url} ?`,
|
|
168
|
-
).then((response) => { supported && openLinkByType(remoteMessage.data.type, remoteMessage.data.url) })
|
|
169
|
-
} else {
|
|
108
|
+
|
|
170
109
|
supported && openLinkByType(remoteMessage.data.type, remoteMessage.data.url)
|
|
171
|
-
|
|
110
|
+
|
|
172
111
|
}
|
|
173
112
|
}).catch(error => console.log(error))
|
|
174
113
|
}
|
|
@@ -176,4 +115,74 @@ export default async ({ appToken, dev, enableAlert }) => {
|
|
|
176
115
|
}, 3000)
|
|
177
116
|
}
|
|
178
117
|
})
|
|
118
|
+
|
|
119
|
+
firebase.messaging().onNotificationOpenedApp(async (remoteMessage) => {
|
|
120
|
+
console.log("Notification Oppened")
|
|
121
|
+
openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'Background' })
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if(typeof onNotificationOpenedApp == 'function') {
|
|
125
|
+
const remoteMessage = await messaging().getInitialNotification();
|
|
126
|
+
onNotificationOpenedApp(remoteMessage);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
firebase.messaging().onMessage(async (remoteMessage) => {
|
|
130
|
+
console.log('Push received: Foreground')
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
PushNotification.configure({
|
|
134
|
+
onNotification: function(notification) {
|
|
135
|
+
console.log('LOCAL NOTIFICATION ==>', notification)
|
|
136
|
+
|
|
137
|
+
openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'foreground' })
|
|
138
|
+
|
|
139
|
+
},
|
|
140
|
+
channelId: "high_importance_channel",
|
|
141
|
+
priority: "high",
|
|
142
|
+
popInitialNotification: true,
|
|
143
|
+
requestPermissions: true
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
} catch (e) {
|
|
147
|
+
console.log(e)
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
try{
|
|
151
|
+
|
|
152
|
+
PushNotification.presentLocalNotification({
|
|
153
|
+
autoCancel: true,
|
|
154
|
+
bigText:remoteMessage.data.body,
|
|
155
|
+
title: remoteMessage.data.title,
|
|
156
|
+
message: '',
|
|
157
|
+
vibrate: true,
|
|
158
|
+
vibration: 300,
|
|
159
|
+
playSound: true,
|
|
160
|
+
soundName: 'default',
|
|
161
|
+
|
|
162
|
+
})
|
|
163
|
+
console.log(remoteMessage)
|
|
164
|
+
}catch(e){
|
|
165
|
+
console.log(e)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
if (remoteMessage != null && remoteMessage.data.additional_data) {
|
|
171
|
+
let msg = JSON.parse(remoteMessage.data.additional_data)
|
|
172
|
+
if (msg.inapp_message == true) {
|
|
173
|
+
const currentMessages = await AsyncStorage.getItem('inngage');
|
|
174
|
+
if (currentMessages !== null) {
|
|
175
|
+
messageArray = JSON.parse(currentMessages);
|
|
176
|
+
}
|
|
177
|
+
messageArray.push(remoteMessage);
|
|
178
|
+
await AsyncStorage.setItem('inngage', JSON.stringify(messageArray));
|
|
179
|
+
}
|
|
180
|
+
} else if (remoteMessage != null && !remoteMessage.data.additional_data) {
|
|
181
|
+
console.log(remoteMessage.data.title)
|
|
182
|
+
if (enableAlert) {
|
|
183
|
+
showAlert(remoteMessage.data.title, remoteMessage.data.body)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
179
188
|
}
|
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { subscription, eventsApi } from "./inngageApi";
|
|
|
7
7
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
8
8
|
import Carousel, { Pagination } from 'react-native-snap-carousel';
|
|
9
9
|
import React, { useState, useEffect, useRef } from 'react';
|
|
10
|
+
|
|
10
11
|
import {
|
|
11
12
|
Platform,
|
|
12
13
|
Modal,
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -13,14 +13,16 @@ const requestConfigFactory = (method, request) => {
|
|
|
13
13
|
Accept: 'application/json',
|
|
14
14
|
'Content-Type': 'application/json',
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
try{
|
|
17
|
+
if (request.registerSubscriberRequest.authKey) {
|
|
18
|
+
header = {
|
|
19
|
+
...header,
|
|
20
|
+
Authorization: request.registerSubscriberRequest.authKey
|
|
21
|
+
}
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
}catch(e){
|
|
24
|
+
console.log(e)
|
|
25
|
+
}
|
|
24
26
|
let objToSend = {
|
|
25
27
|
method,
|
|
26
28
|
body: JSON.stringify(request),
|