@inngageregistry/inngage-react 2.2.7 → 2.3.1

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.
@@ -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, {
@@ -49,7 +50,7 @@ export const openCommonNotification = (notificationData) => {
49
50
  },
50
51
  }
51
52
  if (!url) {
52
- if (enableAlert && state === 'foreground') {
53
+ if (state === 'foreground') {
53
54
  return notificationApi(request, dev).then(() => {
54
55
  if (enableAlert) {
55
56
  showAlert(title, body)
@@ -88,7 +89,7 @@ export const openRichNotification = (notificationData) => {
88
89
 
89
90
 
90
91
 
91
- export default async ({ appToken, dev, enableAlert }) => {
92
+ export default async ({ appToken, dev, enableAlert, onNotificationOpenedApp }) => {
92
93
  var messageArray = [];
93
94
 
94
95
  firebase.messaging().onNotificationOpenedApp(async (remoteMessage) => {
@@ -96,12 +97,52 @@ export default async ({ appToken, dev, enableAlert }) => {
96
97
  openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'Background' })
97
98
  });
98
99
 
99
- messaging().getInitialNotification(async (remoteMessage) => {
100
- console.log("from quit")
101
- })
100
+ if(typeof onNotificationOpenedApp == 'function') {
101
+ const remoteMessage = await messaging().getInitialNotification();
102
+ onNotificationOpenedApp(remoteMessage);
103
+ }
102
104
 
103
105
  firebase.messaging().onMessage(async (remoteMessage) => {
104
106
  console.log('Push received: Foreground')
107
+
108
+ try {
109
+ PushNotification.configure({
110
+ onNotification: function(notification) {
111
+ console.log('LOCAL NOTIFICATION ==>', notification)
112
+
113
+ openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'foreground' })
114
+
115
+ },
116
+ channelId: "high_importance_channel",
117
+ priority: "high",
118
+ popInitialNotification: true,
119
+ requestPermissions: true
120
+ })
121
+
122
+ } catch (e) {
123
+ console.log(e)
124
+
125
+ }
126
+ try{
127
+
128
+ PushNotification.presentLocalNotification({
129
+ autoCancel: true,
130
+ bigText:remoteMessage.data.body,
131
+ title: remoteMessage.data.title,
132
+ message: '',
133
+ vibrate: true,
134
+ vibration: 300,
135
+ playSound: true,
136
+ soundName: 'default',
137
+
138
+ })
139
+ console.log(remoteMessage)
140
+ }catch(e){
141
+ console.log(e)
142
+ }
143
+
144
+
145
+
105
146
  if (remoteMessage != null && remoteMessage.data.additional_data) {
106
147
  let msg = JSON.parse(remoteMessage.data.additional_data)
107
148
  if (msg.inapp_message == true) {
@@ -118,7 +159,6 @@ export default async ({ appToken, dev, enableAlert }) => {
118
159
  showAlert(remoteMessage.data.title, remoteMessage.data.body)
119
160
  }
120
161
  }
121
- openCommonNotification({ appToken, dev, remoteMessage, enableAlert, state: 'foreground' })
122
162
  });
123
163
 
124
164
  firebase.messaging().setBackgroundMessageHandler(async (remoteMessage) => {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inngageregistry/inngage-react",
3
- "version": "2.2.7",
3
+ "version": "2.3.1",
4
4
  "description": "Inngage react integration",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js CHANGED
@@ -7,15 +7,30 @@ const baseUrlHook = {
7
7
  [true]: 'https://apid.inngage.com.br/v1',
8
8
  }
9
9
 
10
- const requestConfigFactory = (method, request) => ({
11
- headers: {
10
+ const requestConfigFactory = (method, request) => {
11
+
12
+ let header = {
12
13
  Accept: 'application/json',
13
14
  'Content-Type': 'application/json',
14
- Authorization: request.registerSubscriberRequest.authKey
15
- },
16
- method,
17
- body: JSON.stringify(request),
18
- })
15
+ }
16
+ try{
17
+ if (request.registerSubscriberRequest.authKey) {
18
+ header = {
19
+ ...header,
20
+ Authorization: request.registerSubscriberRequest.authKey
21
+ }
22
+ }
23
+ }catch(e){
24
+ console.log(e)
25
+ }
26
+ let objToSend = {
27
+ method,
28
+ body: JSON.stringify(request),
29
+ headers: header
30
+ }
31
+
32
+ return objToSend
33
+ }
19
34
 
20
35
  export const fetchClient = (method, requestBody, path, isDev = false) => {
21
36
  return new Promise((resolve) => {