@inngageregistry/inngage-react 2.3.1 → 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.
@@ -39,10 +39,7 @@ export const openCommonNotification = (notificationData) => {
39
39
  if (!data || (data && !Object.keys(data).length)) {
40
40
  return
41
41
  }
42
- const { notId, title, body, type, url, picture } = data
43
- // if (picture) {
44
- // return openRichNotification(notificationData)
45
- // }
42
+ const { notId, title, body, type, url } = data
46
43
  const request = {
47
44
  notificationRequest: {
48
45
  id: notId,
@@ -50,41 +47,21 @@ export const openCommonNotification = (notificationData) => {
50
47
  },
51
48
  }
52
49
  if (!url) {
53
- if (state === 'foreground') {
54
- return notificationApi(request, dev).then(() => {
55
- if (enableAlert) {
56
- showAlert(title, body)
57
- }
58
- }).catch(console.log)
59
- } else if (!enableAlert) {
60
- return
61
- } else {
62
- return notificationApi(request, dev).then(() => {
63
- if (enableAlert) {
64
- showAlert(title, body)
65
- }
66
- }).catch(console.log)
67
- }
50
+
51
+ return notificationApi(request, dev).then(() => {
52
+
53
+ }).catch(console.log)
54
+
68
55
  }
69
56
  return Linking.canOpenURL(url).then((supported) => {
70
57
  if (supported) {
71
- if (enableAlert) {
72
- showAlertLink(
73
- title,
74
- body,
75
- `${DeviceInfo.getApplicationName()}`,
76
- `Acessar ${url} ?`,
77
- ).then((response) => { supported && openLinkByType(type, url) })
78
- notificationApi(request, dev)
79
- } else {
58
+
80
59
  supported && openLinkByType(type, url)
81
- }
60
+
82
61
  }
83
62
  }).catch(console.log)
84
63
  }
85
64
  export const openRichNotification = (notificationData) => {
86
- //console.log("Rich push", notificationData)
87
- //Rich push code
88
65
  }
89
66
 
90
67
 
@@ -92,6 +69,53 @@ export const openRichNotification = (notificationData) => {
92
69
  export default async ({ appToken, dev, enableAlert, onNotificationOpenedApp }) => {
93
70
  var messageArray = [];
94
71
 
72
+
73
+ firebase.messaging().setBackgroundMessageHandler(async (remoteMessage) => {
74
+ console.log('Push received: Background')
75
+
76
+ const request = {
77
+ notificationRequest: {
78
+ id: remoteMessage.data.notId,
79
+ app_token: appToken,
80
+ },
81
+ }
82
+ if (remoteMessage != null && remoteMessage.data.additional_data) {
83
+ let msg = JSON.parse(remoteMessage.data.additional_data)
84
+ console.log('first step')
85
+ if (msg.inapp_message == true) {
86
+ console.log('second step')
87
+ const currentMessages = await AsyncStorage.getItem('inngage');
88
+ if (currentMessages !== null) {
89
+ messageArray = JSON.parse(currentMessages);
90
+ }
91
+ messageArray.push(remoteMessage);
92
+ await AsyncStorage.setItem('inngage', JSON.stringify(messageArray));
93
+ setTimeout(() => {
94
+ messaging().getInitialNotification().then(notification => {
95
+ notificationApi(request, dev)
96
+ })
97
+ }, 3000)
98
+ }
99
+ } else if (remoteMessage != null && !remoteMessage.data.additional_data) {
100
+ setTimeout(() => {
101
+ messaging().getInitialNotification().then(notification => {
102
+ if (!remoteMessage.data.url) {
103
+ notificationApi(request, dev)
104
+ } else {
105
+ notificationApi(request, dev)
106
+ Linking.canOpenURL(remoteMessage.data.url).then((supported) => {
107
+ if (supported) {
108
+
109
+ supported && openLinkByType(remoteMessage.data.type, remoteMessage.data.url)
110
+
111
+ }
112
+ }).catch(error => console.log(error))
113
+ }
114
+ })
115
+ }, 3000)
116
+ }
117
+ })
118
+
95
119
  firebase.messaging().onNotificationOpenedApp(async (remoteMessage) => {
96
120
  console.log("Notification Oppened")
97
121
  openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'Background' })
@@ -161,59 +185,4 @@ export default async ({ appToken, dev, enableAlert, onNotificationOpenedApp }) =
161
185
  }
162
186
  });
163
187
 
164
- firebase.messaging().setBackgroundMessageHandler(async (remoteMessage) => {
165
- console.log('Push received: Background')
166
-
167
- const request = {
168
- notificationRequest: {
169
- id: remoteMessage.data.notId,
170
- app_token: appToken,
171
- },
172
- }
173
- if (remoteMessage != null && remoteMessage.data.additional_data) {
174
- let msg = JSON.parse(remoteMessage.data.additional_data)
175
- console.log('first step')
176
- if (msg.inapp_message == true) {
177
- console.log('second step')
178
- const currentMessages = await AsyncStorage.getItem('inngage');
179
- if (currentMessages !== null) {
180
- messageArray = JSON.parse(currentMessages);
181
- }
182
- messageArray.push(remoteMessage);
183
- await AsyncStorage.setItem('inngage', JSON.stringify(messageArray));
184
- setTimeout(() => {
185
- messaging().getInitialNotification().then(notification => {
186
- notificationApi(request, dev)
187
- })
188
- }, 3000)
189
- }
190
- } else if (remoteMessage != null && !remoteMessage.data.additional_data) {
191
- setTimeout(() => {
192
- messaging().getInitialNotification().then(notification => {
193
- if (!remoteMessage.data.url) {
194
- if (enableAlert) {
195
- showAlert(remoteMessage.data.title, remoteMessage.data.body)
196
- }
197
- notificationApi(request, dev)
198
- } else {
199
- notificationApi(request, dev)
200
- Linking.canOpenURL(remoteMessage.data.url).then((supported) => {
201
- if (supported) {
202
- if (enableAlert) {
203
- showAlertLink(
204
- remoteMessage.data.title,
205
- remoteMessage.data.body,
206
- `${DeviceInfo.getApplicationName()}`,
207
- `Acessar ${remoteMessage.data.url} ?`,
208
- ).then((response) => { supported && openLinkByType(remoteMessage.data.type, remoteMessage.data.url) })
209
- } else {
210
- supported && openLinkByType(remoteMessage.data.type, remoteMessage.data.url)
211
- }
212
- }
213
- }).catch(error => console.log(error))
214
- }
215
- })
216
- }, 3000)
217
- }
218
- })
219
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inngageregistry/inngage-react",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "Inngage react integration",
5
5
  "main": "index.js",
6
6
  "scripts": {