reactnative-plugin-appice 1.7.12 → 1.7.14

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