notifly-sdk 1.0.5 → 1.0.7

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.
Files changed (2) hide show
  1. package/index.js +9 -67
  2. package/package.json +1 -2
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import messaging from "@react-native-firebase/messaging";
2
- import notifee, { AndroidImportance } from "@notifee/react-native";
3
2
  import { Linking, Platform } from 'react-native';
4
3
  import AsyncStorage from '@react-native-async-storage/async-storage';
5
4
  import rnDeviceInfo from 'react-native-device-info';
@@ -44,7 +43,13 @@ exports.sessionStart = async function () {
44
43
 
45
44
  exports.initialize = async function (prjId, userName, password) {
46
45
  try {
46
+ messaging().requestPermission();
47
+
47
48
  messaging().onNotificationOpenedApp(async (remoteMessage) => {
49
+ const link = remoteMessage.data?.link
50
+ if (link) {
51
+ Linking.openURL(link);
52
+ }
48
53
  await logEvent("push_click", { "campaign_id": remoteMessage.data.campaign_id, "status": "background" }, null, true);
49
54
  });
50
55
 
@@ -54,87 +59,24 @@ exports.initialize = async function (prjId, userName, password) {
54
59
  .getInitialNotification()
55
60
  .then(async (remoteMessage) => {
56
61
  if (remoteMessage) {
57
- const link = remoteMessage.notification?.android?.link;
62
+ const link = remoteMessage.data?.link
58
63
  if (link) {
59
- Linking.openURL(remoteMessage.notification?.android?.link);
64
+ Linking.openURL(link);
60
65
  }
61
66
  await logEvent("push_click", { "campaign_id": remoteMessage.data.campaign_id, "status": "quit" }, null, true);
62
- await logEvent("push_delivered", { "campaign_id": remoteMessage.data.campaign_id, "status": "quit" }, null, true);
63
-
64
67
  }
65
68
  });
66
69
 
67
- messaging().setBackgroundMessageHandler(async (remoteMessage) => {
68
- await logEvent("push_delivered", { "campaign_id": remoteMessage.data.campaign_id, "status": "background" }, null, true);
69
- return
70
- })
71
-
72
70
  await Promise.all([
73
71
  AsyncStorage.setItem('notiflyProjectId', prjId),
74
72
  AsyncStorage.setItem('notiflyUserName', userName),
75
73
  AsyncStorage.setItem('notiflyUserPassword', password),
76
74
  ])
77
-
78
- notifee.requestPermission()
79
- if (Platform.OS === 'android') {
80
- notifee.createChannel({
81
- id: "foreground",
82
- name: "foreground",
83
- importance: AndroidImportance.HIGH,
84
- })
85
- }
86
- notifee.onBackgroundEvent(async ({ type, detail }) => {
87
- const { notification } = detail;
88
- const campaign_id = notification.data.campaign_id;
89
- if (!campaign_id) {
90
- return
91
- }
92
- switch (type) {
93
- case 3:
94
- try {
95
- await logEvent("push_delivered", { "campaign_id": campaign_id, "status": "background-notifee" }, null, true);
96
- } catch (err) {
97
- console.warn('[Notifly]: ', err);
98
- }
99
- break;
100
- }
101
- });
102
75
  } catch (err) {
103
76
  console.warn("[Notifly]: ", err);
104
77
  }
105
78
  }
106
79
 
107
- exports.foregroundSetting = function () {
108
- messaging().onMessage(async remoteMessage => {
109
- await notifee.displayNotification({
110
- title: remoteMessage.notification.title,
111
- body: remoteMessage.notification.body,
112
- data: remoteMessage.data,
113
- android: {
114
- channelId: "foreground",
115
- },
116
- });
117
- await logEvent("push_delivered", { "campaign_id": remoteMessage.data.campaign_id, "status": "foreground" }, null, true);
118
- });
119
- notifee.onForegroundEvent(async ({ type, detail }) => {
120
- const { notification } = detail;
121
- const campaign_id = notification.data.campaign_id;
122
- if (!campaign_id) {
123
- return
124
- }
125
- if (type == 1) {
126
- try {
127
- if (notification.data.link) {
128
- Linking.openURL(notification.data.link)
129
- }
130
- await logEvent("push_click", { "campaign_id": campaign_id, "status": "foreground" }, null, true);
131
- } catch (err) {
132
- console.warn('[Notifly]: ', err);
133
- }
134
- }
135
- });
136
- }
137
-
138
80
  async function getCognitoIdToken(userName, password) {
139
81
  const myHeaders = new Headers();
140
82
  myHeaders.append("X-Amz-Target", "AWSCognitoIdentityProviderService.InitiateAuth");
@@ -304,4 +246,4 @@ async function _apiCall(apiUrl, requestOptions) {
304
246
  const result = fetch(apiUrl, requestOptions)
305
247
  .then(response => response.text());
306
248
  return result;
307
- }
249
+ }
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "notifly-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
9
9
  "peerDependencies": {
10
- "@notifee/react-native": "^7.3.0",
11
10
  "@react-native-async-storage/async-storage": "^1.17.11",
12
11
  "@react-native-firebase/app": "^16.4.3",
13
12
  "@react-native-firebase/messaging": "^16.4.3",