reactnative-plugin-appice 1.7.23 → 1.7.25
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/README.md +37 -37
- package/android/README.md +14 -14
- package/android/build.gradle +158 -153
- package/android/gitignore +47 -47
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -5
- package/android/gradlew +234 -234
- package/android/local.properties +8 -8
- package/android/src/main/AndroidManifest.xml +164 -164
- package/android/src/main/java/com/reactlibrary/AppICEUtils.java +274 -274
- package/android/src/main/java/com/reactlibrary/AppIceReactPluginModule.java +778 -778
- package/android/src/main/java/com/reactlibrary/AppIceReactPluginPackage.java +28 -28
- package/android/src/main/java/com/reactlibrary/CampaignCampsReceiver.java +56 -56
- package/android/src/main/java/com/reactlibrary/EnumConstants.java +282 -282
- package/android/src/main/java/com/reactlibrary/NotificationEventService.java +59 -59
- package/android/src/main/java/com/reactlibrary/StringConstants.java +24 -24
- package/campaign.js +25 -25
- package/example/App.js +332 -332
- package/example/Gemfile +6 -6
- package/example/PageA.tsx +15 -15
- package/example/__tests__/App-test.js +14 -14
- package/example/ancilliary.js +486 -486
- package/example/android/.gradle/7.3.3/checksums/checksums.lock +0 -0
- package/example/android/.gradle/7.3.3/fileChanges/last-build.bin +0 -0
- package/example/android/.gradle/7.3.3/fileHashes/fileHashes.lock +0 -0
- package/example/android/.gradle/7.3.3/gc.properties +0 -0
- package/example/android/.gradle/vcs-1/gc.properties +0 -0
- package/example/android/app/_BUCK +55 -55
- package/example/android/app/build.gradle +320 -320
- package/example/android/app/build_defs.bzl +19 -19
- package/example/android/app/proguard-rules.pro +10 -10
- package/example/android/app/src/debug/AndroidManifest.xml +13 -13
- package/example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +73 -73
- package/example/android/app/src/main/AndroidManifest.xml +72 -72
- package/example/android/app/src/main/java/com/example/MainActivity.java +48 -48
- package/example/android/app/src/main/java/com/example/MainApplication.java +91 -91
- package/example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java +116 -116
- package/example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java +36 -36
- package/example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java +48 -48
- package/example/android/app/src/main/jni/Android.mk +48 -48
- package/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp +24 -24
- package/example/android/app/src/main/jni/MainApplicationModuleProvider.h +16 -16
- package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +45 -45
- package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +38 -38
- package/example/android/app/src/main/jni/MainComponentsRegistry.cpp +61 -61
- package/example/android/app/src/main/jni/MainComponentsRegistry.h +32 -32
- package/example/android/app/src/main/jni/OnLoad.cpp +11 -11
- package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -36
- package/example/android/app/src/main/res/values/strings.xml +3 -3
- package/example/android/app/src/main/res/values/styles.xml +9 -9
- package/example/android/build.gradle +73 -73
- package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -5
- package/example/android/gradle.properties +40 -40
- package/example/android/gradlew +234 -234
- package/example/android/settings.gradle +11 -11
- package/example/app.json +3 -3
- package/example/babel.config.js +3 -3
- package/example/index.js +9 -9
- package/example/ios/Podfile +44 -44
- package/example/ios/Podfile.lock +561 -561
- package/example/ios/_xcode.env +11 -11
- package/example/ios/example/AppDelegate.h +8 -8
- package/example/ios/example/AppDelegate.mm +174 -174
- package/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +53 -53
- package/example/ios/example/Images.xcassets/Contents.json +6 -6
- package/example/ios/example/Info.plist +62 -62
- package/example/ios/example/LaunchScreen.storyboard +47 -47
- package/example/ios/example/example.entitlements +8 -8
- package/example/ios/example/main.m +10 -10
- package/example/ios/example.xcodeproj/project.pbxproj +712 -712
- package/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +88 -88
- package/example/ios/example.xcworkspace/contents.xcworkspacedata +10 -10
- package/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
- package/example/ios/exampleTests/Info.plist +24 -24
- package/example/ios/exampleTests/exampleTests.m +66 -66
- package/example/metro.config.js +17 -17
- package/example/package.json +36 -36
- package/example/yarn.lock +7176 -7176
- package/index.js +590 -590
- package/ios/AppICEReactEvent.h +23 -23
- package/ios/AppICEReactEvent.m +86 -86
- package/ios/AppIceReactPlugin.h +65 -65
- package/ios/AppIceReactPlugin.m +683 -683
- package/ios/AppIceReactPlugin.xcodeproj/project.pbxproj +364 -364
- package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -4
- package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
- package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
- package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
- package/ios/AppIceReactPlugin.xcworkspace/contents.xcworkspacedata +10 -10
- package/ios/AppIceReactPlugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
- package/ios/AppIceReactPlugin.xcworkspace/xcuserdata/artherajesh.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Podfile +10 -10
- package/ios/Podfile.lock +3 -3
- package/ios/Pods/Manifest.lock +3 -3
- package/ios/Pods/Pods.xcodeproj/project.pbxproj +395 -395
- package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/Pods-AppIceReactPlugin.xcscheme +58 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +18 -18
- package/ios/Pods/Pods.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-Info.plist +26 -26
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.markdown +3 -3
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.plist +29 -29
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-dummy.m +5 -5
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-umbrella.h +16 -16
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.debug.xcconfig +6 -6
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.modulemap +6 -6
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.release.xcconfig +6 -6
- package/package.json +42 -42
- package/reactnative-plugin-appice.podspec +30 -30
- package/android/obfuscationdictionary.txt +0 -501
package/example/ancilliary.js
CHANGED
|
@@ -1,486 +1,486 @@
|
|
|
1
|
-
/* eslint-disable prettier/prettier */
|
|
2
|
-
const AppICE = require('reactnative-plugin-appice');
|
|
3
|
-
import { URL } from 'react-native-url-polyfill';
|
|
4
|
-
|
|
5
|
-
/* eslint-disable prettier/prettier */
|
|
6
|
-
/**
|
|
7
|
-
* Helper method to set user profile
|
|
8
|
-
* @param {object} profile - key-value profile properties.
|
|
9
|
-
*/
|
|
10
|
-
const setUser = (profile) => {
|
|
11
|
-
var age = 0;
|
|
12
|
-
var email;
|
|
13
|
-
var phone;
|
|
14
|
-
if (profile.age && profile.age != null && profile.age > 0) {
|
|
15
|
-
age = calculateAge(profile.age);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
email = hasMF(profile.email) ? '' : validateEmail(profile.email);
|
|
19
|
-
phone = hasMF(profile.phone) ? '' : profile.phone;
|
|
20
|
-
|
|
21
|
-
if (email && phone) {
|
|
22
|
-
AppICE.setUser({
|
|
23
|
-
[AppICE.name]: profile.name,
|
|
24
|
-
[AppICE.phone]: phone,
|
|
25
|
-
[AppICE.email]: email,
|
|
26
|
-
[AppICE.dob]: parseInt(profile.dob),
|
|
27
|
-
[AppICE.age]: age,
|
|
28
|
-
[AppICE.gender]: profile.gender,
|
|
29
|
-
[AppICE.educationType]: profile.educationType,
|
|
30
|
-
[AppICE.employmentType]: profile.employmentType,
|
|
31
|
-
[AppICE.married]: profile.married,
|
|
32
|
-
[AppICE.isEmployed]: profile.isEmployed,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Helper method to calculate age from birth year
|
|
39
|
-
* @param {string} birthYear - Year of birth as a string (e.g., '1990')
|
|
40
|
-
* @returns {number} - Age in years
|
|
41
|
-
*/
|
|
42
|
-
const calculateAge = (birthYear) => {
|
|
43
|
-
let age;
|
|
44
|
-
// Convert the birth year from string to integer
|
|
45
|
-
if(birthYear != null){
|
|
46
|
-
const birthYearInt = parseInt(birthYear, 10);
|
|
47
|
-
const currentYear = new Date().getFullYear();
|
|
48
|
-
age = currentYear - birthYearInt;
|
|
49
|
-
}
|
|
50
|
-
else{
|
|
51
|
-
return 0;
|
|
52
|
-
}
|
|
53
|
-
return age;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
function getMessageCounts(
|
|
58
|
-
type: number,
|
|
59
|
-
userids: string[],
|
|
60
|
-
timeout: number,
|
|
61
|
-
callback: {(result: number): void; (arg0: any): void},
|
|
62
|
-
) {
|
|
63
|
-
AppICE.synchronizeInbox(timeout, (res: any) => {
|
|
64
|
-
if (res) {
|
|
65
|
-
console.log(
|
|
66
|
-
'getMessageCounts inside the sync type = ' +
|
|
67
|
-
type +
|
|
68
|
-
', userid = ' +
|
|
69
|
-
userids,
|
|
70
|
-
);
|
|
71
|
-
AppICE.getMessageCount(1, userids, (res: string) => {
|
|
72
|
-
if (res) {
|
|
73
|
-
console.log('getMessageCounts inside the sync res = ' + res);
|
|
74
|
-
callback(res);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
} else {
|
|
78
|
-
console.log(
|
|
79
|
-
'getMessageCounts outside the sync type = ' +
|
|
80
|
-
type +
|
|
81
|
-
', userid = ' +
|
|
82
|
-
userids,
|
|
83
|
-
);
|
|
84
|
-
console.log('inbox is not synced with server, showing old stored data');
|
|
85
|
-
AppICE.getMessageCount(1, userids, (res: any) => {
|
|
86
|
-
if (res) {
|
|
87
|
-
callback(res);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function updatedInboxMessage(
|
|
95
|
-
messageId: string,
|
|
96
|
-
type: number,
|
|
97
|
-
userid: string,
|
|
98
|
-
callback: {(result: boolean): void; (arg0: any): void},
|
|
99
|
-
) {
|
|
100
|
-
AppICE.updateInboxMessage(messageId, type, userid, (res: boolean) => {
|
|
101
|
-
callback(res);
|
|
102
|
-
console.log('updateInboxMessage res : ' + res);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function getInboxMessages(
|
|
107
|
-
type: number,
|
|
108
|
-
userids: string[],
|
|
109
|
-
category: string,
|
|
110
|
-
limit: number,
|
|
111
|
-
offset: number,
|
|
112
|
-
timeout: number,
|
|
113
|
-
withServerHit: boolean,
|
|
114
|
-
callback: {(result: any): void; (arg0: string): void},
|
|
115
|
-
) {
|
|
116
|
-
if (withServerHit) {
|
|
117
|
-
AppICE.synchronizeInbox(timeout, (res: any) => {
|
|
118
|
-
if (res) {
|
|
119
|
-
AppICE.getInboxMessages(type, userids, async (res: any) => {
|
|
120
|
-
console.log('getInboxMessages ' + res);
|
|
121
|
-
if (res) {
|
|
122
|
-
const newData = JSON.stringify(res);
|
|
123
|
-
const result = await getFilteredData(
|
|
124
|
-
newData,
|
|
125
|
-
category,
|
|
126
|
-
limit,
|
|
127
|
-
offset,
|
|
128
|
-
);
|
|
129
|
-
console.log('getFilteredData 2: ', result);
|
|
130
|
-
const val = JSON.stringify(result);
|
|
131
|
-
console.log('getFilteredData 2: ', val);
|
|
132
|
-
if (val) {
|
|
133
|
-
console.log('internalGetInboxMessage 2' + val);
|
|
134
|
-
callback(val);
|
|
135
|
-
// getMediaDataKeys(res);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
} else {
|
|
140
|
-
AppICE.getInboxMessages(type, userids, async (res: any) => {
|
|
141
|
-
console.log('getInboxMessages ' + res);
|
|
142
|
-
if (res) {
|
|
143
|
-
const newData = JSON.stringify(res);
|
|
144
|
-
const result = await getFilteredData(
|
|
145
|
-
newData,
|
|
146
|
-
category,
|
|
147
|
-
limit,
|
|
148
|
-
offset,
|
|
149
|
-
);
|
|
150
|
-
console.log('getFilteredData 3: ', result);
|
|
151
|
-
const val = JSON.stringify(result);
|
|
152
|
-
console.log('getFilteredData 3: ', val);
|
|
153
|
-
if (val) {
|
|
154
|
-
console.log('internalGetInboxMessage 3' + val);
|
|
155
|
-
callback(val);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
} else {
|
|
162
|
-
AppICE.getInboxMessages(type, userids, async (res: any) => {
|
|
163
|
-
if (res) {
|
|
164
|
-
try {
|
|
165
|
-
const newData = JSON.stringify(res);
|
|
166
|
-
console.log('getInboxMessages newData' + newData);
|
|
167
|
-
const result = await getFilteredData(
|
|
168
|
-
newData,
|
|
169
|
-
category,
|
|
170
|
-
limit,
|
|
171
|
-
offset,
|
|
172
|
-
);
|
|
173
|
-
console.log('getFilteredData result' + result);
|
|
174
|
-
|
|
175
|
-
const val = JSON.stringify(result);
|
|
176
|
-
console.log('getFilteredData stringify result val' + val);
|
|
177
|
-
|
|
178
|
-
if (val) {
|
|
179
|
-
console.log('internalGetInboxMessage 4' + val);
|
|
180
|
-
callback(val);
|
|
181
|
-
}
|
|
182
|
-
} catch (error) {
|
|
183
|
-
console.log('internalGetInboxMessage error' + error);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async function getFilteredData(
|
|
191
|
-
newData: string,
|
|
192
|
-
category: string,
|
|
193
|
-
limit: number,
|
|
194
|
-
offset: number | undefined,
|
|
195
|
-
) {
|
|
196
|
-
const jsonArray = JSON.parse(newData);
|
|
197
|
-
if (!jsonArray || !Array.isArray(jsonArray)) {
|
|
198
|
-
console.error('Invalid jsonArray:', jsonArray);
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Convert the provided category to lowercase for case-insensitive comparison
|
|
203
|
-
const lowerCaseCategory = category.toLowerCase();
|
|
204
|
-
|
|
205
|
-
// Count occurrences of each category with original case for the entire array
|
|
206
|
-
const categoryCount = jsonArray.reduce((acc, item) => {
|
|
207
|
-
const categoryName = item?.cdata?.category; // Added null checks
|
|
208
|
-
if (categoryName) {
|
|
209
|
-
acc[categoryName] = (acc[categoryName] || 0) + 1;
|
|
210
|
-
}
|
|
211
|
-
return acc;
|
|
212
|
-
}, {});
|
|
213
|
-
|
|
214
|
-
// Ensure that "chip A" and "chip B" are in the count array, even if they are not present in the filtered array
|
|
215
|
-
['Offers & Promotions', 'Alerts'].forEach(chip => {
|
|
216
|
-
if (!categoryCount[chip]) {
|
|
217
|
-
categoryCount[chip] = 0;
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
// Filter the array based on the provided category (case-insensitive)
|
|
222
|
-
const filteredArray = jsonArray.filter(
|
|
223
|
-
item => item?.cdata?.category?.toLowerCase() === lowerCaseCategory,
|
|
224
|
-
);
|
|
225
|
-
console.log('slicedArray filteredArray ' + filteredArray);
|
|
226
|
-
|
|
227
|
-
// Apply limit and offset to the filtered array
|
|
228
|
-
const slicedArray = filteredArray.slice(offset, offset + limit);
|
|
229
|
-
console.log('slicedArray ' + JSON.stringify(slicedArray));
|
|
230
|
-
|
|
231
|
-
// Prepare the result object without assigning new values
|
|
232
|
-
const result = {
|
|
233
|
-
count: Object.entries(categoryCount).map(([key, value]) => ({
|
|
234
|
-
[key]: value,
|
|
235
|
-
})),
|
|
236
|
-
inboxData: await getMediaDataKeys(slicedArray),
|
|
237
|
-
};
|
|
238
|
-
console.log('filtered data ' + JSON.stringify(result));
|
|
239
|
-
return result;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
async function getMediaDataKeys(inboxMessages: any) {
|
|
243
|
-
const newInboxMessageData: any[] = [];
|
|
244
|
-
|
|
245
|
-
// Iterate over all messages in inboxMessages array
|
|
246
|
-
inboxMessages.forEach(async (message: any) => {
|
|
247
|
-
const mediaKey = 'imageUrl'; // Adjust media key as needed
|
|
248
|
-
const singleInboxMessage = Object.assign({}, message);
|
|
249
|
-
|
|
250
|
-
console.log('from server ', message);
|
|
251
|
-
try {
|
|
252
|
-
const mediaData = await new Promise((resolve, _reject) => {
|
|
253
|
-
AppICE.getMediaData(message, mediaKey, (mediaData: any) => {
|
|
254
|
-
resolve(mediaData);
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
// We have to check mediaData if it is valid only then we should call rest of the functions
|
|
258
|
-
const mediaUrl = await new Promise((resolve, _reject) => {
|
|
259
|
-
AppICE.getMediaUrl(message, mediaData, (mediaUrl: any) => {
|
|
260
|
-
resolve(mediaUrl);
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
const mediaType = await new Promise((resolve, _reject) => {
|
|
264
|
-
AppICE.getMediaType(message, mediaData, (mediaType: any) => {
|
|
265
|
-
resolve(mediaType);
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
const mediaThumbnail = await new Promise((resolve, _reject) => {
|
|
269
|
-
AppICE.getMediaThumbnail(message, mediaData, (mediaThumbnail: any) => {
|
|
270
|
-
resolve(mediaThumbnail);
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
console.log('==================================================');
|
|
274
|
-
console.log('singleInboxMessage:', singleInboxMessage);
|
|
275
|
-
console.log('mediaUrl:', mediaUrl);
|
|
276
|
-
console.log('mediaType:', mediaType);
|
|
277
|
-
console.log('mediaThumbnail:', mediaThumbnail);
|
|
278
|
-
// Add media data to singleInboxMessage
|
|
279
|
-
singleInboxMessage.mediaUrl = mediaUrl;
|
|
280
|
-
singleInboxMessage.mediaType = mediaType;
|
|
281
|
-
singleInboxMessage.mediaThumbnail = mediaThumbnail;
|
|
282
|
-
|
|
283
|
-
// Push singleInboxMessage to newInboxMessageData
|
|
284
|
-
newInboxMessageData.push(singleInboxMessage);
|
|
285
|
-
|
|
286
|
-
console.log('final Media newInboxMessageData push:', newInboxMessageData);
|
|
287
|
-
console.log('==================================================');
|
|
288
|
-
} catch (error) {
|
|
289
|
-
console.error('Error fetching media data:', error);
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
// Wait for all asynchronous operations to complete before returning
|
|
294
|
-
return new Promise(resolve => {
|
|
295
|
-
setTimeout(() => {
|
|
296
|
-
resolve(newInboxMessageData);
|
|
297
|
-
console.log('Media newInboxMessageData promise:', newInboxMessageData);
|
|
298
|
-
}, 500); //millisecond
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Helper method to validate the email and checks if email contains gender values(m/f)
|
|
303
|
-
* @param {string} email - Email address as a string
|
|
304
|
-
* @returns {string} - Valid email address or an empty string if invalid
|
|
305
|
-
*/
|
|
306
|
-
const validateEmail = (email) => {
|
|
307
|
-
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
308
|
-
if (email === 'm' || email === 'M' || email === 'F' || email === 'f') {
|
|
309
|
-
email = '';
|
|
310
|
-
}
|
|
311
|
-
if (!emailPattern.test(email)) {
|
|
312
|
-
return '';
|
|
313
|
-
}
|
|
314
|
-
return email;
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
//common method that checks if email or phone contains gender values(m/f/M/F)
|
|
318
|
-
const hasMF = (value) => {
|
|
319
|
-
if (value === 'm' || value === 'M' || value === 'F' || value === 'f') {
|
|
320
|
-
return true;
|
|
321
|
-
}
|
|
322
|
-
return false;
|
|
323
|
-
};
|
|
324
|
-
/**
|
|
325
|
-
* This function is made for arrange data according to required output
|
|
326
|
-
* they need json array which we do not support from pannel
|
|
327
|
-
* so we are sending it as string for Ex
|
|
328
|
-
* key = offerTexts
|
|
329
|
-
* value = {\"offerTexts\":[\"Customers transacting on BMS "]}",
|
|
330
|
-
* here we are parsing and arranging it according to their need
|
|
331
|
-
* apart from json array we are also sending String and json object
|
|
332
|
-
* @param {JSON} cdata this is data what we are getting from getMessagebyId
|
|
333
|
-
* @param {*} offerid this may be a string valur or null
|
|
334
|
-
* @returns jsonObject
|
|
335
|
-
*/
|
|
336
|
-
const formatOfferData = (cdata,offerid) => {
|
|
337
|
-
const formattedData = {};
|
|
338
|
-
|
|
339
|
-
// Ensure offerId is the first item in data
|
|
340
|
-
if (offerid != null) {
|
|
341
|
-
formattedData.offerId = offerid;
|
|
342
|
-
}
|
|
343
|
-
if (!cdata || Object.keys(cdata).length === 0) {
|
|
344
|
-
return formattedData;
|
|
345
|
-
}
|
|
346
|
-
const isValidJsonString = (str) => {
|
|
347
|
-
if (typeof str !== 'string') {
|
|
348
|
-
return false;
|
|
349
|
-
}
|
|
350
|
-
try {
|
|
351
|
-
JSON.parse(str);
|
|
352
|
-
return true;
|
|
353
|
-
} catch (e) {
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
const parseValue = (value) => {
|
|
359
|
-
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
360
|
-
try {
|
|
361
|
-
const parsed = JSON.parse(value);
|
|
362
|
-
if (Array.isArray(parsed)) {
|
|
363
|
-
return parsed;
|
|
364
|
-
} else if (typeof parsed === 'object') {
|
|
365
|
-
const keys = Object.keys(parsed);
|
|
366
|
-
if (keys.length === 1 && Array.isArray(parsed[keys[0]])) {
|
|
367
|
-
return parsed[keys[0]];
|
|
368
|
-
} else {
|
|
369
|
-
return parsed;
|
|
370
|
-
}
|
|
371
|
-
} else {
|
|
372
|
-
return value;
|
|
373
|
-
}
|
|
374
|
-
} catch (error) {
|
|
375
|
-
return value;
|
|
376
|
-
}
|
|
377
|
-
} else {
|
|
378
|
-
return value;
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
// Loop through cdata keys
|
|
384
|
-
Object.keys(cdata).forEach((key) => {
|
|
385
|
-
formattedData[key] = parseValue(cdata[key]);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
return formattedData;
|
|
389
|
-
};
|
|
390
|
-
/**
|
|
391
|
-
* This function will recive mid userId and offerID
|
|
392
|
-
* with mid and userId it will call native function and retrive data
|
|
393
|
-
* This will retrive InboxMessage for given messageId
|
|
394
|
-
* from recived response we are getting only cData and pass it be formatted
|
|
395
|
-
*
|
|
396
|
-
* @param {String} messageId unique id of message you can get from inboxMessage
|
|
397
|
-
* @param {String} useIds this is id of user you can get it from getUserId
|
|
398
|
-
* @param {*} offerid in case of inbox this will be null from dl we are retriving it
|
|
399
|
-
* @param {Object} callback callback the response
|
|
400
|
-
*/
|
|
401
|
-
export const getOfferDataForInboxMessage = (messageId, useIds, offerid, callback) => {
|
|
402
|
-
AppICE.getInboxMessageForId(messageId, useIds, (inboxMessage) => {
|
|
403
|
-
const offerData = formatOfferData(inboxMessage.cdata,offerid);
|
|
404
|
-
const result = { data: offerData };
|
|
405
|
-
callback(result);
|
|
406
|
-
});
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* This function will recive dl URL and user ID
|
|
411
|
-
* Ex boiua://offers?offerid=1234&mid=37ce1de6-3b63-4182-a5df-2334d5b13750
|
|
412
|
-
* retrive offerid and mid from dl URL
|
|
413
|
-
* useIds you have to getit from appSide
|
|
414
|
-
*
|
|
415
|
-
* @param {string} dl The deep link URL from which to extract the 'mid' parameter.
|
|
416
|
-
* @param {string} useId user id
|
|
417
|
-
* @param {object} callback return the response
|
|
418
|
-
*/
|
|
419
|
-
const getOfferDataForDeeplink = (dl,timeout, callback) =>{
|
|
420
|
-
const mid = extractMidFromDeepLink(dl);
|
|
421
|
-
const offerid = extractOfferIdFromDeepLink(dl);
|
|
422
|
-
if(mid != null){
|
|
423
|
-
const userId = null;
|
|
424
|
-
AppICE.getUserId((userIds) => {
|
|
425
|
-
userId = JSON.parse(userIds)[0];
|
|
426
|
-
console.log('getUserId parse:', userId);
|
|
427
|
-
if (!userId) {
|
|
428
|
-
userId = userIds[0];
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
AppICE.synchronizeInbox(timeout, (success) => {
|
|
432
|
-
if(success){
|
|
433
|
-
AppICE.getInboxMessageForId(mid, userId, (inboxMessage) => {
|
|
434
|
-
callback(inboxMessage)
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* We will recive dl when it is being clicked
|
|
442
|
-
* from that method this method will be called
|
|
443
|
-
* it check if there is mid it will return mid value
|
|
444
|
-
* @param {string} dl Deep Link URL Ex boiua://offers?offerid=1234&mid=37ce1de6-3b63-4182-a5df-2334d5b13750
|
|
445
|
-
* @returns {string} mid Ex 37ce1de6-3b63-4182-a5df-2334d5b13750
|
|
446
|
-
*/
|
|
447
|
-
const extractMidFromDeepLink = (dl) => {
|
|
448
|
-
try {
|
|
449
|
-
const url = new URL(dl);
|
|
450
|
-
const mid = url.searchParams.get('mid');
|
|
451
|
-
if (mid) {
|
|
452
|
-
return mid;
|
|
453
|
-
} else {
|
|
454
|
-
console.log("'mid' parameter not found in the deep link");
|
|
455
|
-
return null;
|
|
456
|
-
}
|
|
457
|
-
} catch (error) {
|
|
458
|
-
console.error('Invalid URL:', error);
|
|
459
|
-
return null;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
const extractOfferIdFromDeepLink = (dl) => {
|
|
463
|
-
try {
|
|
464
|
-
const url = new URL(dl);
|
|
465
|
-
const offerid = url.searchParams.get('offerid');
|
|
466
|
-
if (offerid) {
|
|
467
|
-
return offerid;
|
|
468
|
-
} else {
|
|
469
|
-
console.log("'offerid' parameter not found in the deep link");
|
|
470
|
-
return null;
|
|
471
|
-
}
|
|
472
|
-
} catch (error) {
|
|
473
|
-
console.error('Invalid URL:', error);
|
|
474
|
-
return null;
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
module.exports = {
|
|
480
|
-
getInboxMessages,
|
|
481
|
-
updatedInboxMessage,
|
|
482
|
-
setUser,
|
|
483
|
-
getMessageCounts,
|
|
484
|
-
getOfferDataForDeeplink,
|
|
485
|
-
getOfferDataForInboxMessage,
|
|
486
|
-
};
|
|
1
|
+
/* eslint-disable prettier/prettier */
|
|
2
|
+
const AppICE = require('reactnative-plugin-appice');
|
|
3
|
+
import { URL } from 'react-native-url-polyfill';
|
|
4
|
+
|
|
5
|
+
/* eslint-disable prettier/prettier */
|
|
6
|
+
/**
|
|
7
|
+
* Helper method to set user profile
|
|
8
|
+
* @param {object} profile - key-value profile properties.
|
|
9
|
+
*/
|
|
10
|
+
const setUser = (profile) => {
|
|
11
|
+
var age = 0;
|
|
12
|
+
var email;
|
|
13
|
+
var phone;
|
|
14
|
+
if (profile.age && profile.age != null && profile.age > 0) {
|
|
15
|
+
age = calculateAge(profile.age);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
email = hasMF(profile.email) ? '' : validateEmail(profile.email);
|
|
19
|
+
phone = hasMF(profile.phone) ? '' : profile.phone;
|
|
20
|
+
|
|
21
|
+
if (email && phone) {
|
|
22
|
+
AppICE.setUser({
|
|
23
|
+
[AppICE.name]: profile.name,
|
|
24
|
+
[AppICE.phone]: phone,
|
|
25
|
+
[AppICE.email]: email,
|
|
26
|
+
[AppICE.dob]: parseInt(profile.dob),
|
|
27
|
+
[AppICE.age]: age,
|
|
28
|
+
[AppICE.gender]: profile.gender,
|
|
29
|
+
[AppICE.educationType]: profile.educationType,
|
|
30
|
+
[AppICE.employmentType]: profile.employmentType,
|
|
31
|
+
[AppICE.married]: profile.married,
|
|
32
|
+
[AppICE.isEmployed]: profile.isEmployed,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Helper method to calculate age from birth year
|
|
39
|
+
* @param {string} birthYear - Year of birth as a string (e.g., '1990')
|
|
40
|
+
* @returns {number} - Age in years
|
|
41
|
+
*/
|
|
42
|
+
const calculateAge = (birthYear) => {
|
|
43
|
+
let age;
|
|
44
|
+
// Convert the birth year from string to integer
|
|
45
|
+
if(birthYear != null){
|
|
46
|
+
const birthYearInt = parseInt(birthYear, 10);
|
|
47
|
+
const currentYear = new Date().getFullYear();
|
|
48
|
+
age = currentYear - birthYearInt;
|
|
49
|
+
}
|
|
50
|
+
else{
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
return age;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
function getMessageCounts(
|
|
58
|
+
type: number,
|
|
59
|
+
userids: string[],
|
|
60
|
+
timeout: number,
|
|
61
|
+
callback: {(result: number): void; (arg0: any): void},
|
|
62
|
+
) {
|
|
63
|
+
AppICE.synchronizeInbox(timeout, (res: any) => {
|
|
64
|
+
if (res) {
|
|
65
|
+
console.log(
|
|
66
|
+
'getMessageCounts inside the sync type = ' +
|
|
67
|
+
type +
|
|
68
|
+
', userid = ' +
|
|
69
|
+
userids,
|
|
70
|
+
);
|
|
71
|
+
AppICE.getMessageCount(1, userids, (res: string) => {
|
|
72
|
+
if (res) {
|
|
73
|
+
console.log('getMessageCounts inside the sync res = ' + res);
|
|
74
|
+
callback(res);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
console.log(
|
|
79
|
+
'getMessageCounts outside the sync type = ' +
|
|
80
|
+
type +
|
|
81
|
+
', userid = ' +
|
|
82
|
+
userids,
|
|
83
|
+
);
|
|
84
|
+
console.log('inbox is not synced with server, showing old stored data');
|
|
85
|
+
AppICE.getMessageCount(1, userids, (res: any) => {
|
|
86
|
+
if (res) {
|
|
87
|
+
callback(res);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function updatedInboxMessage(
|
|
95
|
+
messageId: string,
|
|
96
|
+
type: number,
|
|
97
|
+
userid: string,
|
|
98
|
+
callback: {(result: boolean): void; (arg0: any): void},
|
|
99
|
+
) {
|
|
100
|
+
AppICE.updateInboxMessage(messageId, type, userid, (res: boolean) => {
|
|
101
|
+
callback(res);
|
|
102
|
+
console.log('updateInboxMessage res : ' + res);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getInboxMessages(
|
|
107
|
+
type: number,
|
|
108
|
+
userids: string[],
|
|
109
|
+
category: string,
|
|
110
|
+
limit: number,
|
|
111
|
+
offset: number,
|
|
112
|
+
timeout: number,
|
|
113
|
+
withServerHit: boolean,
|
|
114
|
+
callback: {(result: any): void; (arg0: string): void},
|
|
115
|
+
) {
|
|
116
|
+
if (withServerHit) {
|
|
117
|
+
AppICE.synchronizeInbox(timeout, (res: any) => {
|
|
118
|
+
if (res) {
|
|
119
|
+
AppICE.getInboxMessages(type, userids, async (res: any) => {
|
|
120
|
+
console.log('getInboxMessages ' + res);
|
|
121
|
+
if (res) {
|
|
122
|
+
const newData = JSON.stringify(res);
|
|
123
|
+
const result = await getFilteredData(
|
|
124
|
+
newData,
|
|
125
|
+
category,
|
|
126
|
+
limit,
|
|
127
|
+
offset,
|
|
128
|
+
);
|
|
129
|
+
console.log('getFilteredData 2: ', result);
|
|
130
|
+
const val = JSON.stringify(result);
|
|
131
|
+
console.log('getFilteredData 2: ', val);
|
|
132
|
+
if (val) {
|
|
133
|
+
console.log('internalGetInboxMessage 2' + val);
|
|
134
|
+
callback(val);
|
|
135
|
+
// getMediaDataKeys(res);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
AppICE.getInboxMessages(type, userids, async (res: any) => {
|
|
141
|
+
console.log('getInboxMessages ' + res);
|
|
142
|
+
if (res) {
|
|
143
|
+
const newData = JSON.stringify(res);
|
|
144
|
+
const result = await getFilteredData(
|
|
145
|
+
newData,
|
|
146
|
+
category,
|
|
147
|
+
limit,
|
|
148
|
+
offset,
|
|
149
|
+
);
|
|
150
|
+
console.log('getFilteredData 3: ', result);
|
|
151
|
+
const val = JSON.stringify(result);
|
|
152
|
+
console.log('getFilteredData 3: ', val);
|
|
153
|
+
if (val) {
|
|
154
|
+
console.log('internalGetInboxMessage 3' + val);
|
|
155
|
+
callback(val);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
AppICE.getInboxMessages(type, userids, async (res: any) => {
|
|
163
|
+
if (res) {
|
|
164
|
+
try {
|
|
165
|
+
const newData = JSON.stringify(res);
|
|
166
|
+
console.log('getInboxMessages newData' + newData);
|
|
167
|
+
const result = await getFilteredData(
|
|
168
|
+
newData,
|
|
169
|
+
category,
|
|
170
|
+
limit,
|
|
171
|
+
offset,
|
|
172
|
+
);
|
|
173
|
+
console.log('getFilteredData result' + result);
|
|
174
|
+
|
|
175
|
+
const val = JSON.stringify(result);
|
|
176
|
+
console.log('getFilteredData stringify result val' + val);
|
|
177
|
+
|
|
178
|
+
if (val) {
|
|
179
|
+
console.log('internalGetInboxMessage 4' + val);
|
|
180
|
+
callback(val);
|
|
181
|
+
}
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.log('internalGetInboxMessage error' + error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function getFilteredData(
|
|
191
|
+
newData: string,
|
|
192
|
+
category: string,
|
|
193
|
+
limit: number,
|
|
194
|
+
offset: number | undefined,
|
|
195
|
+
) {
|
|
196
|
+
const jsonArray = JSON.parse(newData);
|
|
197
|
+
if (!jsonArray || !Array.isArray(jsonArray)) {
|
|
198
|
+
console.error('Invalid jsonArray:', jsonArray);
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Convert the provided category to lowercase for case-insensitive comparison
|
|
203
|
+
const lowerCaseCategory = category.toLowerCase();
|
|
204
|
+
|
|
205
|
+
// Count occurrences of each category with original case for the entire array
|
|
206
|
+
const categoryCount = jsonArray.reduce((acc, item) => {
|
|
207
|
+
const categoryName = item?.cdata?.category; // Added null checks
|
|
208
|
+
if (categoryName) {
|
|
209
|
+
acc[categoryName] = (acc[categoryName] || 0) + 1;
|
|
210
|
+
}
|
|
211
|
+
return acc;
|
|
212
|
+
}, {});
|
|
213
|
+
|
|
214
|
+
// Ensure that "chip A" and "chip B" are in the count array, even if they are not present in the filtered array
|
|
215
|
+
['Offers & Promotions', 'Alerts'].forEach(chip => {
|
|
216
|
+
if (!categoryCount[chip]) {
|
|
217
|
+
categoryCount[chip] = 0;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Filter the array based on the provided category (case-insensitive)
|
|
222
|
+
const filteredArray = jsonArray.filter(
|
|
223
|
+
item => item?.cdata?.category?.toLowerCase() === lowerCaseCategory,
|
|
224
|
+
);
|
|
225
|
+
console.log('slicedArray filteredArray ' + filteredArray);
|
|
226
|
+
|
|
227
|
+
// Apply limit and offset to the filtered array
|
|
228
|
+
const slicedArray = filteredArray.slice(offset, offset + limit);
|
|
229
|
+
console.log('slicedArray ' + JSON.stringify(slicedArray));
|
|
230
|
+
|
|
231
|
+
// Prepare the result object without assigning new values
|
|
232
|
+
const result = {
|
|
233
|
+
count: Object.entries(categoryCount).map(([key, value]) => ({
|
|
234
|
+
[key]: value,
|
|
235
|
+
})),
|
|
236
|
+
inboxData: await getMediaDataKeys(slicedArray),
|
|
237
|
+
};
|
|
238
|
+
console.log('filtered data ' + JSON.stringify(result));
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function getMediaDataKeys(inboxMessages: any) {
|
|
243
|
+
const newInboxMessageData: any[] = [];
|
|
244
|
+
|
|
245
|
+
// Iterate over all messages in inboxMessages array
|
|
246
|
+
inboxMessages.forEach(async (message: any) => {
|
|
247
|
+
const mediaKey = 'imageUrl'; // Adjust media key as needed
|
|
248
|
+
const singleInboxMessage = Object.assign({}, message);
|
|
249
|
+
|
|
250
|
+
console.log('from server ', message);
|
|
251
|
+
try {
|
|
252
|
+
const mediaData = await new Promise((resolve, _reject) => {
|
|
253
|
+
AppICE.getMediaData(message, mediaKey, (mediaData: any) => {
|
|
254
|
+
resolve(mediaData);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
// We have to check mediaData if it is valid only then we should call rest of the functions
|
|
258
|
+
const mediaUrl = await new Promise((resolve, _reject) => {
|
|
259
|
+
AppICE.getMediaUrl(message, mediaData, (mediaUrl: any) => {
|
|
260
|
+
resolve(mediaUrl);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
const mediaType = await new Promise((resolve, _reject) => {
|
|
264
|
+
AppICE.getMediaType(message, mediaData, (mediaType: any) => {
|
|
265
|
+
resolve(mediaType);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
const mediaThumbnail = await new Promise((resolve, _reject) => {
|
|
269
|
+
AppICE.getMediaThumbnail(message, mediaData, (mediaThumbnail: any) => {
|
|
270
|
+
resolve(mediaThumbnail);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
console.log('==================================================');
|
|
274
|
+
console.log('singleInboxMessage:', singleInboxMessage);
|
|
275
|
+
console.log('mediaUrl:', mediaUrl);
|
|
276
|
+
console.log('mediaType:', mediaType);
|
|
277
|
+
console.log('mediaThumbnail:', mediaThumbnail);
|
|
278
|
+
// Add media data to singleInboxMessage
|
|
279
|
+
singleInboxMessage.mediaUrl = mediaUrl;
|
|
280
|
+
singleInboxMessage.mediaType = mediaType;
|
|
281
|
+
singleInboxMessage.mediaThumbnail = mediaThumbnail;
|
|
282
|
+
|
|
283
|
+
// Push singleInboxMessage to newInboxMessageData
|
|
284
|
+
newInboxMessageData.push(singleInboxMessage);
|
|
285
|
+
|
|
286
|
+
console.log('final Media newInboxMessageData push:', newInboxMessageData);
|
|
287
|
+
console.log('==================================================');
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.error('Error fetching media data:', error);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// Wait for all asynchronous operations to complete before returning
|
|
294
|
+
return new Promise(resolve => {
|
|
295
|
+
setTimeout(() => {
|
|
296
|
+
resolve(newInboxMessageData);
|
|
297
|
+
console.log('Media newInboxMessageData promise:', newInboxMessageData);
|
|
298
|
+
}, 500); //millisecond
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Helper method to validate the email and checks if email contains gender values(m/f)
|
|
303
|
+
* @param {string} email - Email address as a string
|
|
304
|
+
* @returns {string} - Valid email address or an empty string if invalid
|
|
305
|
+
*/
|
|
306
|
+
const validateEmail = (email) => {
|
|
307
|
+
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
308
|
+
if (email === 'm' || email === 'M' || email === 'F' || email === 'f') {
|
|
309
|
+
email = '';
|
|
310
|
+
}
|
|
311
|
+
if (!emailPattern.test(email)) {
|
|
312
|
+
return '';
|
|
313
|
+
}
|
|
314
|
+
return email;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
//common method that checks if email or phone contains gender values(m/f/M/F)
|
|
318
|
+
const hasMF = (value) => {
|
|
319
|
+
if (value === 'm' || value === 'M' || value === 'F' || value === 'f') {
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
return false;
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* This function is made for arrange data according to required output
|
|
326
|
+
* they need json array which we do not support from pannel
|
|
327
|
+
* so we are sending it as string for Ex
|
|
328
|
+
* key = offerTexts
|
|
329
|
+
* value = {\"offerTexts\":[\"Customers transacting on BMS "]}",
|
|
330
|
+
* here we are parsing and arranging it according to their need
|
|
331
|
+
* apart from json array we are also sending String and json object
|
|
332
|
+
* @param {JSON} cdata this is data what we are getting from getMessagebyId
|
|
333
|
+
* @param {*} offerid this may be a string valur or null
|
|
334
|
+
* @returns jsonObject
|
|
335
|
+
*/
|
|
336
|
+
const formatOfferData = (cdata,offerid) => {
|
|
337
|
+
const formattedData = {};
|
|
338
|
+
|
|
339
|
+
// Ensure offerId is the first item in data
|
|
340
|
+
if (offerid != null) {
|
|
341
|
+
formattedData.offerId = offerid;
|
|
342
|
+
}
|
|
343
|
+
if (!cdata || Object.keys(cdata).length === 0) {
|
|
344
|
+
return formattedData;
|
|
345
|
+
}
|
|
346
|
+
const isValidJsonString = (str) => {
|
|
347
|
+
if (typeof str !== 'string') {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
try {
|
|
351
|
+
JSON.parse(str);
|
|
352
|
+
return true;
|
|
353
|
+
} catch (e) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
const parseValue = (value) => {
|
|
359
|
+
if (typeof value === 'string' && isValidJsonString(value)) {
|
|
360
|
+
try {
|
|
361
|
+
const parsed = JSON.parse(value);
|
|
362
|
+
if (Array.isArray(parsed)) {
|
|
363
|
+
return parsed;
|
|
364
|
+
} else if (typeof parsed === 'object') {
|
|
365
|
+
const keys = Object.keys(parsed);
|
|
366
|
+
if (keys.length === 1 && Array.isArray(parsed[keys[0]])) {
|
|
367
|
+
return parsed[keys[0]];
|
|
368
|
+
} else {
|
|
369
|
+
return parsed;
|
|
370
|
+
}
|
|
371
|
+
} else {
|
|
372
|
+
return value;
|
|
373
|
+
}
|
|
374
|
+
} catch (error) {
|
|
375
|
+
return value;
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
return value;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
// Loop through cdata keys
|
|
384
|
+
Object.keys(cdata).forEach((key) => {
|
|
385
|
+
formattedData[key] = parseValue(cdata[key]);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
return formattedData;
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* This function will recive mid userId and offerID
|
|
392
|
+
* with mid and userId it will call native function and retrive data
|
|
393
|
+
* This will retrive InboxMessage for given messageId
|
|
394
|
+
* from recived response we are getting only cData and pass it be formatted
|
|
395
|
+
*
|
|
396
|
+
* @param {String} messageId unique id of message you can get from inboxMessage
|
|
397
|
+
* @param {String} useIds this is id of user you can get it from getUserId
|
|
398
|
+
* @param {*} offerid in case of inbox this will be null from dl we are retriving it
|
|
399
|
+
* @param {Object} callback callback the response
|
|
400
|
+
*/
|
|
401
|
+
export const getOfferDataForInboxMessage = (messageId, useIds, offerid, callback) => {
|
|
402
|
+
AppICE.getInboxMessageForId(messageId, useIds, (inboxMessage) => {
|
|
403
|
+
const offerData = formatOfferData(inboxMessage.cdata,offerid);
|
|
404
|
+
const result = { data: offerData };
|
|
405
|
+
callback(result);
|
|
406
|
+
});
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* This function will recive dl URL and user ID
|
|
411
|
+
* Ex boiua://offers?offerid=1234&mid=37ce1de6-3b63-4182-a5df-2334d5b13750
|
|
412
|
+
* retrive offerid and mid from dl URL
|
|
413
|
+
* useIds you have to getit from appSide
|
|
414
|
+
*
|
|
415
|
+
* @param {string} dl The deep link URL from which to extract the 'mid' parameter.
|
|
416
|
+
* @param {string} useId user id
|
|
417
|
+
* @param {object} callback return the response
|
|
418
|
+
*/
|
|
419
|
+
const getOfferDataForDeeplink = (dl,timeout, callback) =>{
|
|
420
|
+
const mid = extractMidFromDeepLink(dl);
|
|
421
|
+
const offerid = extractOfferIdFromDeepLink(dl);
|
|
422
|
+
if(mid != null){
|
|
423
|
+
const userId = null;
|
|
424
|
+
AppICE.getUserId((userIds) => {
|
|
425
|
+
userId = JSON.parse(userIds)[0];
|
|
426
|
+
console.log('getUserId parse:', userId);
|
|
427
|
+
if (!userId) {
|
|
428
|
+
userId = userIds[0];
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
AppICE.synchronizeInbox(timeout, (success) => {
|
|
432
|
+
if(success){
|
|
433
|
+
AppICE.getInboxMessageForId(mid, userId, (inboxMessage) => {
|
|
434
|
+
callback(inboxMessage)
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* We will recive dl when it is being clicked
|
|
442
|
+
* from that method this method will be called
|
|
443
|
+
* it check if there is mid it will return mid value
|
|
444
|
+
* @param {string} dl Deep Link URL Ex boiua://offers?offerid=1234&mid=37ce1de6-3b63-4182-a5df-2334d5b13750
|
|
445
|
+
* @returns {string} mid Ex 37ce1de6-3b63-4182-a5df-2334d5b13750
|
|
446
|
+
*/
|
|
447
|
+
const extractMidFromDeepLink = (dl) => {
|
|
448
|
+
try {
|
|
449
|
+
const url = new URL(dl);
|
|
450
|
+
const mid = url.searchParams.get('mid');
|
|
451
|
+
if (mid) {
|
|
452
|
+
return mid;
|
|
453
|
+
} else {
|
|
454
|
+
console.log("'mid' parameter not found in the deep link");
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
} catch (error) {
|
|
458
|
+
console.error('Invalid URL:', error);
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
const extractOfferIdFromDeepLink = (dl) => {
|
|
463
|
+
try {
|
|
464
|
+
const url = new URL(dl);
|
|
465
|
+
const offerid = url.searchParams.get('offerid');
|
|
466
|
+
if (offerid) {
|
|
467
|
+
return offerid;
|
|
468
|
+
} else {
|
|
469
|
+
console.log("'offerid' parameter not found in the deep link");
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
} catch (error) {
|
|
473
|
+
console.error('Invalid URL:', error);
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
module.exports = {
|
|
480
|
+
getInboxMessages,
|
|
481
|
+
updatedInboxMessage,
|
|
482
|
+
setUser,
|
|
483
|
+
getMessageCounts,
|
|
484
|
+
getOfferDataForDeeplink,
|
|
485
|
+
getOfferDataForInboxMessage,
|
|
486
|
+
};
|