cordova-plugin-appice 2.2.1 → 2.2.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.
- package/example/www/index.html +89 -52
- package/example/www/js/AppInboxMessage.js +58 -0
- package/example/www/js/index.js +580 -99
- package/package.json +1 -1
- package/plugin.xml +6 -5
- package/src/android/AppICEPlugin.java +567 -54
- package/src/ios/AppICEPlugin.h +17 -1
- package/src/ios/AppICEPlugin.m +384 -12
- package/www/AppICE.js +86 -3
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.appice.cordova;
|
|
2
2
|
|
|
3
3
|
import static com.appice.cordova.AppICEPushHandler.handleLandingPage;
|
|
4
|
-
|
|
5
4
|
import android.content.Context;
|
|
6
5
|
import android.content.Intent;
|
|
7
6
|
import android.content.SharedPreferences;
|
|
@@ -31,13 +30,22 @@ import java.util.HashMap;
|
|
|
31
30
|
import java.util.Iterator;
|
|
32
31
|
import java.util.List;
|
|
33
32
|
import java.util.Map;
|
|
33
|
+
import java.util.logging.LogManager;
|
|
34
34
|
|
|
35
35
|
import semusi.activitysdk.Api;
|
|
36
36
|
import semusi.activitysdk.ContextData;
|
|
37
37
|
import semusi.activitysdk.ContextSdk;
|
|
38
38
|
import semusi.activitysdk.SdkConfig;
|
|
39
|
-
import semusi.context.utility.Utility;
|
|
40
39
|
import semusi.model.user.User;
|
|
40
|
+
import semusi.context.utility.Utility;
|
|
41
|
+
import org.json.JSONException;
|
|
42
|
+
|
|
43
|
+
import semusi.context.ui.appInbox.AppICEInboxMessage;
|
|
44
|
+
import semusi.context.ui.appInbox.IAppICESuccessCallback;
|
|
45
|
+
import semusi.activitysdk.IAppICEDataCallback;
|
|
46
|
+
|
|
47
|
+
import androidx.annotation.NonNull;
|
|
48
|
+
import androidx.annotation.Nullable;
|
|
41
49
|
|
|
42
50
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|
43
51
|
|
|
@@ -85,6 +93,7 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
85
93
|
|
|
86
94
|
@Override
|
|
87
95
|
public void onDestroy() {
|
|
96
|
+
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
@Override
|
|
@@ -104,7 +113,6 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
104
113
|
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
|
105
114
|
super.initialize(cordova, webView);
|
|
106
115
|
|
|
107
|
-
|
|
108
116
|
onNewIntent(cordova.getActivity().getIntent());
|
|
109
117
|
}
|
|
110
118
|
|
|
@@ -138,8 +146,8 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
138
146
|
ContextSdk.pushNotificationClicked(payload, cordova.getActivity().getApplicationContext());
|
|
139
147
|
}
|
|
140
148
|
}
|
|
141
|
-
} catch (Throwable
|
|
142
|
-
|
|
149
|
+
} catch (Throwable e) {
|
|
150
|
+
callbackContext.error(e.getMessage());
|
|
143
151
|
}
|
|
144
152
|
}
|
|
145
153
|
|
|
@@ -158,9 +166,11 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
158
166
|
}
|
|
159
167
|
}
|
|
160
168
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
/*
|
|
170
|
+
* ====================================
|
|
171
|
+
* // SDK CONFIG SETTING APIS
|
|
172
|
+
* //===================================
|
|
173
|
+
*/
|
|
164
174
|
@CordovaMethod
|
|
165
175
|
private void validateIntegration(JSONArray data, CallbackContext callbackContext) {
|
|
166
176
|
try {
|
|
@@ -236,11 +246,12 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
236
246
|
}
|
|
237
247
|
}
|
|
238
248
|
} catch (Throwable e) {
|
|
239
|
-
|
|
249
|
+
Utility.loginfo("initSdk: error "+e);
|
|
240
250
|
}
|
|
241
251
|
|
|
242
252
|
config.setAnalyticsTrackingAllowedState(true);
|
|
243
|
-
Api.initSdk(appId, appKey, apiKey, region, baseUrl, listCert,
|
|
253
|
+
Api.initSdk(appId, appKey, apiKey, region, baseUrl, listCert,
|
|
254
|
+
cordova.getActivity().getApplicationContext());
|
|
244
255
|
Api.startContext(cordova.getActivity().getApplicationContext(), config);
|
|
245
256
|
|
|
246
257
|
callbackContext.success();
|
|
@@ -253,12 +264,11 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
253
264
|
@CordovaMethod
|
|
254
265
|
private void isDeviceReady(JSONArray data, CallbackContext callbackContext) {
|
|
255
266
|
try {
|
|
256
|
-
if (statusFlag==false) {
|
|
267
|
+
if (statusFlag == false) {
|
|
257
268
|
checkIfAnyPendingCallback(cordova.getActivity());
|
|
258
269
|
}
|
|
259
270
|
statusFlag = true;
|
|
260
271
|
callbackContext.success();
|
|
261
|
-
|
|
262
272
|
} catch (Throwable e) {
|
|
263
273
|
callbackContext.error(e.getMessage());
|
|
264
274
|
}
|
|
@@ -269,7 +279,8 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
269
279
|
webView.getView().post(new Runnable() {
|
|
270
280
|
@Override
|
|
271
281
|
public void run() {
|
|
272
|
-
webView.loadUrl(
|
|
282
|
+
webView.loadUrl(
|
|
283
|
+
"javascript:cordova.fireDocumentEvent('pushNotificationClicked'," + pendingCallbackStr + ");");
|
|
273
284
|
resetTempData(CALLBACK_CONSTANTS, context);
|
|
274
285
|
}
|
|
275
286
|
});
|
|
@@ -306,9 +317,11 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
306
317
|
}
|
|
307
318
|
}
|
|
308
319
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
320
|
+
/*
|
|
321
|
+
* =================================
|
|
322
|
+
* // GET SDK DETAILS
|
|
323
|
+
* //================================
|
|
324
|
+
*/
|
|
312
325
|
@CordovaMethod
|
|
313
326
|
private void getCurrentContext(JSONArray data, CallbackContext callbackContext) {
|
|
314
327
|
// Get user current context from system
|
|
@@ -342,9 +355,11 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
342
355
|
}
|
|
343
356
|
}
|
|
344
357
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
358
|
+
/*
|
|
359
|
+
* ======================================
|
|
360
|
+
* // DEVICE SETTING APIS
|
|
361
|
+
* //=====================================
|
|
362
|
+
*/
|
|
348
363
|
@CordovaMethod
|
|
349
364
|
private void setDeviceId(JSONArray data, CallbackContext callbackContext) {
|
|
350
365
|
// Set new deviceId in system
|
|
@@ -381,9 +396,11 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
381
396
|
}
|
|
382
397
|
}
|
|
383
398
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
399
|
+
/*
|
|
400
|
+
* =============================
|
|
401
|
+
* // META DATA SETTING APIS
|
|
402
|
+
* //=============================
|
|
403
|
+
*/
|
|
387
404
|
@CordovaMethod
|
|
388
405
|
private void getAppKey(JSONArray data, CallbackContext callbackContext) {
|
|
389
406
|
// Gather existing app-key from system
|
|
@@ -417,9 +434,9 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
417
434
|
}
|
|
418
435
|
}
|
|
419
436
|
|
|
420
|
-
|
|
437
|
+
// =================================
|
|
421
438
|
// ALIAS SETTING APIS
|
|
422
|
-
|
|
439
|
+
// ==================================
|
|
423
440
|
@CordovaMethod
|
|
424
441
|
private void setAlias(JSONArray data, CallbackContext callbackContext) {
|
|
425
442
|
// Set new deviceId in system
|
|
@@ -445,9 +462,9 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
445
462
|
}
|
|
446
463
|
}
|
|
447
464
|
|
|
448
|
-
|
|
465
|
+
// ================================
|
|
449
466
|
// USER PROFILE SETTING APIS
|
|
450
|
-
|
|
467
|
+
// ================================
|
|
451
468
|
@CordovaMethod
|
|
452
469
|
private void setUserId(JSONArray data, CallbackContext callbackContext) {
|
|
453
470
|
ArrayList<String> userIdList = new ArrayList<>();
|
|
@@ -474,6 +491,16 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
474
491
|
}
|
|
475
492
|
}
|
|
476
493
|
|
|
494
|
+
@CordovaMethod
|
|
495
|
+
private void getUserId(JSONArray data, CallbackContext callbackContext) {
|
|
496
|
+
try {
|
|
497
|
+
String sdkUserId = ContextSdk.getUserId(cordova.getActivity().getApplicationContext());
|
|
498
|
+
callbackContext.success(sdkUserId.toString());
|
|
499
|
+
} catch (Throwable e) {
|
|
500
|
+
callbackContext.error(e.getMessage());
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
477
504
|
@CordovaMethod
|
|
478
505
|
private void setUser(JSONArray data, CallbackContext callbackContext) {
|
|
479
506
|
// Set user in system
|
|
@@ -511,9 +538,9 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
511
538
|
}
|
|
512
539
|
}
|
|
513
540
|
|
|
514
|
-
|
|
541
|
+
// =========================================
|
|
515
542
|
// CUSTOM VARIABLE AND EVENT SETTING APIS
|
|
516
|
-
|
|
543
|
+
// ==========================================
|
|
517
544
|
@CordovaMethod
|
|
518
545
|
private void setCustomVariable(JSONArray data, CallbackContext callbackContext) {
|
|
519
546
|
// Set custom variable in system
|
|
@@ -583,7 +610,7 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
583
610
|
}
|
|
584
611
|
}
|
|
585
612
|
} catch (Throwable e) {
|
|
586
|
-
|
|
613
|
+
Utility.loginfo("tagEvent: error "+e);
|
|
587
614
|
}
|
|
588
615
|
|
|
589
616
|
ContextSdk.tagEventObj(key, mapData, cordova.getActivity().getApplicationContext());
|
|
@@ -594,9 +621,9 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
594
621
|
}
|
|
595
622
|
}
|
|
596
623
|
|
|
597
|
-
|
|
624
|
+
// =========================================
|
|
598
625
|
// CHILD KEY SETTING APIS
|
|
599
|
-
|
|
626
|
+
// ==========================================
|
|
600
627
|
|
|
601
628
|
@CordovaMethod
|
|
602
629
|
private void setChildId(JSONArray data, CallbackContext callbackContext) {
|
|
@@ -623,9 +650,9 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
623
650
|
}
|
|
624
651
|
}
|
|
625
652
|
|
|
626
|
-
|
|
653
|
+
// =========================================
|
|
627
654
|
// PLAY STORE SETTING APIS
|
|
628
|
-
|
|
655
|
+
// =========================================
|
|
629
656
|
@CordovaMethod
|
|
630
657
|
private void openPlayServiceUpdate(JSONArray data, CallbackContext callbackContext) {
|
|
631
658
|
// Open up google play service update UI for user
|
|
@@ -637,9 +664,9 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
637
664
|
}
|
|
638
665
|
}
|
|
639
666
|
|
|
640
|
-
|
|
667
|
+
// ==================================
|
|
641
668
|
// PUSH NOTIFICATION SETTING APIS
|
|
642
|
-
|
|
669
|
+
// ==================================
|
|
643
670
|
@CordovaMethod
|
|
644
671
|
private void setSmallIcon(JSONArray data, CallbackContext callbackContext) {
|
|
645
672
|
// Set small icon in system
|
|
@@ -670,7 +697,7 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
670
697
|
try {
|
|
671
698
|
this.callbackContext = callbackContext;
|
|
672
699
|
} catch (Throwable e) {
|
|
673
|
-
|
|
700
|
+
Utility.loginfo("onNotificationOpen: error "+e);
|
|
674
701
|
}
|
|
675
702
|
}
|
|
676
703
|
|
|
@@ -684,7 +711,6 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
684
711
|
}
|
|
685
712
|
} catch (Throwable e) {
|
|
686
713
|
callbackContext.error(e.getMessage());
|
|
687
|
-
Log.e(TAG, "pushNotificationClicked: error ", e);
|
|
688
714
|
}
|
|
689
715
|
}
|
|
690
716
|
|
|
@@ -704,7 +730,6 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
704
730
|
}
|
|
705
731
|
} catch (Throwable e) {
|
|
706
732
|
callbackContext.error(e.getMessage());
|
|
707
|
-
Log.e(TAG, "pushNotificationClicked: error ", e);
|
|
708
733
|
}
|
|
709
734
|
}
|
|
710
735
|
|
|
@@ -719,17 +744,16 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
719
744
|
result.setKeepCallback(true);
|
|
720
745
|
callbackContext.sendPluginResult(result);
|
|
721
746
|
}
|
|
722
|
-
} catch (Throwable
|
|
723
|
-
|
|
747
|
+
} catch (Throwable e) {
|
|
748
|
+
Utility.loginfo("Runnable: error "+e);
|
|
724
749
|
}
|
|
725
750
|
}
|
|
726
751
|
}).start();
|
|
727
752
|
}
|
|
728
753
|
|
|
729
|
-
|
|
730
|
-
//==================================
|
|
754
|
+
// ==================================
|
|
731
755
|
// SESSION SETTING APIS
|
|
732
|
-
|
|
756
|
+
// ==================================
|
|
733
757
|
@CordovaMethod
|
|
734
758
|
private void setSessionTimeout(JSONArray data, CallbackContext callbackContext) {
|
|
735
759
|
// Set session timeout in system
|
|
@@ -754,10 +778,9 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
754
778
|
}
|
|
755
779
|
}
|
|
756
780
|
|
|
757
|
-
|
|
758
|
-
//===============================
|
|
781
|
+
// ===============================
|
|
759
782
|
// VISUAL PLAYBACK SETTING APIS
|
|
760
|
-
|
|
783
|
+
// ===============================
|
|
761
784
|
|
|
762
785
|
@CordovaMethod
|
|
763
786
|
private void isSemusiSensing(JSONArray data, CallbackContext callbackContext) {
|
|
@@ -833,7 +856,8 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
833
856
|
}
|
|
834
857
|
|
|
835
858
|
View rootView = cordova.getActivity().getWindow().getDecorView().getRootView();
|
|
836
|
-
ContextSdk.trackTouches(root, cordova.getActivity().getApplicationContext(), rootView,
|
|
859
|
+
ContextSdk.trackTouches(root, cordova.getActivity().getApplicationContext(), rootView,
|
|
860
|
+
cordova.getActivity());
|
|
837
861
|
|
|
838
862
|
callbackContext.success();
|
|
839
863
|
} catch (Throwable e) {
|
|
@@ -898,7 +922,8 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
898
922
|
}
|
|
899
923
|
|
|
900
924
|
View rootView = cordova.getActivity().getWindow().getDecorView().getRootView();
|
|
901
|
-
ContextSdk.trackSwipes(root, cordova.getActivity().getApplicationContext(), rootView,
|
|
925
|
+
ContextSdk.trackSwipes(root, cordova.getActivity().getApplicationContext(), rootView,
|
|
926
|
+
cordova.getActivity());
|
|
902
927
|
|
|
903
928
|
callbackContext.success();
|
|
904
929
|
} catch (Throwable e) {
|
|
@@ -948,11 +973,12 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
948
973
|
}
|
|
949
974
|
|
|
950
975
|
View rootView = cordova.getActivity().getWindow().getDecorView().getRootView();
|
|
951
|
-
ContextSdk.trackScreens(root, cordova.getActivity().getApplicationContext(), rootView,
|
|
976
|
+
ContextSdk.trackScreens(root, cordova.getActivity().getApplicationContext(), rootView,
|
|
977
|
+
cordova.getActivity());
|
|
952
978
|
|
|
953
979
|
callbackContext.success();
|
|
954
980
|
} catch (Throwable e) {
|
|
955
|
-
|
|
981
|
+
Utility.loginfo("trackScreens run: error "+e);
|
|
956
982
|
}
|
|
957
983
|
}
|
|
958
984
|
}).start();
|
|
@@ -969,7 +995,7 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
969
995
|
edit.putString(key, value);
|
|
970
996
|
edit.apply();
|
|
971
997
|
} catch (Throwable e) {
|
|
972
|
-
|
|
998
|
+
Utility.loginfo("storeTempData: error "+e);
|
|
973
999
|
}
|
|
974
1000
|
}
|
|
975
1001
|
|
|
@@ -981,11 +1007,10 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
981
1007
|
edit.remove(key);
|
|
982
1008
|
edit.apply();
|
|
983
1009
|
} catch (Throwable e) {
|
|
984
|
-
|
|
1010
|
+
Utility.loginfo("resetTempData: error "+e);
|
|
985
1011
|
}
|
|
986
1012
|
}
|
|
987
1013
|
|
|
988
|
-
|
|
989
1014
|
public static String loadTempData(String key, Context ctx) {
|
|
990
1015
|
String name = "";
|
|
991
1016
|
try {
|
|
@@ -993,8 +1018,496 @@ public class AppICEPlugin extends CordovaPlugin {
|
|
|
993
1018
|
Context.MODE_PRIVATE);
|
|
994
1019
|
name = sp.getString(key, "");
|
|
995
1020
|
} catch (Throwable e) {
|
|
996
|
-
|
|
1021
|
+
Utility.loginfo("loadTempData: error "+e);
|
|
997
1022
|
}
|
|
998
1023
|
return name;
|
|
999
1024
|
}
|
|
1025
|
+
|
|
1026
|
+
// ==================================
|
|
1027
|
+
// APP INBOX APIS
|
|
1028
|
+
// ==================================
|
|
1029
|
+
|
|
1030
|
+
/**
|
|
1031
|
+
* Get inbox messages list.
|
|
1032
|
+
*
|
|
1033
|
+
* @param type the message type
|
|
1034
|
+
* 1 = ALL
|
|
1035
|
+
* 2 = UNREAD
|
|
1036
|
+
* 3 = READ
|
|
1037
|
+
* 4 = VIEWED
|
|
1038
|
+
* 5 = DELETED
|
|
1039
|
+
* @param userIds the same way we are passing the value in setUserId same value
|
|
1040
|
+
* we need here. ie. [ "useridA" ]
|
|
1041
|
+
* @callback will have the string json array
|
|
1042
|
+
*/
|
|
1043
|
+
|
|
1044
|
+
@CordovaMethod
|
|
1045
|
+
private void getInboxMessagesForUserIds(JSONArray data, CallbackContext callbackContext) {
|
|
1046
|
+
cordova.getThreadPool().execute(new Runnable() {
|
|
1047
|
+
public void run() {
|
|
1048
|
+
ArrayList<String> userIdList = new ArrayList<>();
|
|
1049
|
+
JSONArray messagesArray = new JSONArray();
|
|
1050
|
+
try {
|
|
1051
|
+
JSONObject jsonObject = data.getJSONObject(0);
|
|
1052
|
+
// Extract values from the JSON object
|
|
1053
|
+
int type = jsonObject.optInt("type");
|
|
1054
|
+
JSONArray userIdArray = jsonObject.optJSONArray("userId");
|
|
1055
|
+
|
|
1056
|
+
if (userIdArray != null) {
|
|
1057
|
+
for (int i = 0; i < userIdArray.length(); i++) {
|
|
1058
|
+
userIdList.add((String) userIdArray.get(i));
|
|
1059
|
+
}
|
|
1060
|
+
if (userIdList != null) {
|
|
1061
|
+
try {
|
|
1062
|
+
String[] userId = userIdList.toArray(new String[userIdList.size()]);
|
|
1063
|
+
List<AppICEInboxMessage> inboxItems = ContextSdk.getInboxMessage(type, userId,
|
|
1064
|
+
cordova.getActivity().getApplicationContext());
|
|
1065
|
+
for (int i = 0; i < inboxItems.size(); i++) {
|
|
1066
|
+
AppICEInboxMessage inboxMessage = inboxItems.get(i);
|
|
1067
|
+
messagesArray.put(inboxMessage.toJson());
|
|
1068
|
+
|
|
1069
|
+
}
|
|
1070
|
+
callbackContext.success(messagesArray);
|
|
1071
|
+
} catch (Throwable e) {
|
|
1072
|
+
callbackContext.error(e.getMessage());
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
} catch (Throwable e) {
|
|
1077
|
+
callbackContext.error(e.getMessage());
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
/**
|
|
1085
|
+
* Get inbox messages list.
|
|
1086
|
+
*
|
|
1087
|
+
* @param type the message type
|
|
1088
|
+
* 1 = ALL
|
|
1089
|
+
* 2 = UNREAD
|
|
1090
|
+
* 3 = READ
|
|
1091
|
+
* 4 = VIEWED
|
|
1092
|
+
* 5 = DELETED
|
|
1093
|
+
* @callback will have the string json array
|
|
1094
|
+
*/
|
|
1095
|
+
|
|
1096
|
+
@CordovaMethod
|
|
1097
|
+
private void getInboxMessages(JSONArray data, CallbackContext callbackContext) {
|
|
1098
|
+
cordova.getThreadPool().execute(new Runnable() {
|
|
1099
|
+
public void run() {
|
|
1100
|
+
JSONArray messagesArray = new JSONArray();
|
|
1101
|
+
try {
|
|
1102
|
+
JSONObject jsonObject = data.getJSONObject(0);
|
|
1103
|
+
// Extract values from the JSON object
|
|
1104
|
+
int type = jsonObject.optInt("type");
|
|
1105
|
+
List<AppICEInboxMessage> inboxItems = ContextSdk.getInboxMessage(type,
|
|
1106
|
+
cordova.getActivity().getApplicationContext());
|
|
1107
|
+
for (int i = 0; i < inboxItems.size(); i++) {
|
|
1108
|
+
AppICEInboxMessage inboxMessage = inboxItems.get(i);
|
|
1109
|
+
messagesArray.put(inboxMessage.toJson());
|
|
1110
|
+
|
|
1111
|
+
}
|
|
1112
|
+
callbackContext.success(messagesArray);
|
|
1113
|
+
} catch (Throwable e) {
|
|
1114
|
+
callbackContext.error(e.getMessage());
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Get appinbox cData through mediakey
|
|
1123
|
+
* mediakey is a kind of key just like in json we find key value
|
|
1124
|
+
*
|
|
1125
|
+
* @param {inboxMessage} ReadableMap
|
|
1126
|
+
* @param {String} mediakey : will get this key from cData json
|
|
1127
|
+
* @Callback will recive Map<String, Object> object
|
|
1128
|
+
*/
|
|
1129
|
+
@CordovaMethod
|
|
1130
|
+
private void getMediaData(JSONArray data, CallbackContext callbackContext) {
|
|
1131
|
+
try {
|
|
1132
|
+
JSONObject jsonObject = data.optJSONObject(0);
|
|
1133
|
+
JSONObject inboxMessage = jsonObject.optJSONObject("inboxMessages");
|
|
1134
|
+
String mediaKey = jsonObject.optString("mediaKey");
|
|
1135
|
+
AppICEInboxMessage inboxMessageInstance = AppICEInboxMessage.getAppICEInboxMessage(inboxMessage.toString(),
|
|
1136
|
+
cordova.getActivity().getApplicationContext());
|
|
1137
|
+
if (inboxMessageInstance != null) {
|
|
1138
|
+
Map<String, Object> map = inboxMessageInstance.getMediaData(mediaKey);
|
|
1139
|
+
if (map != null) {
|
|
1140
|
+
JSONObject mapJSON = new JSONObject(map);
|
|
1141
|
+
callbackContext.success(mapJSON);
|
|
1142
|
+
}
|
|
1143
|
+
} else {
|
|
1144
|
+
callbackContext.error("Invalid inbox message format");
|
|
1145
|
+
}
|
|
1146
|
+
} catch (Throwable e) {
|
|
1147
|
+
callbackContext.error(e.getMessage());
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* To get Media URL from getMediaData
|
|
1153
|
+
* inboxMessage {AppICEInboxMessage as a ReadableMap}
|
|
1154
|
+
* mediaData customData
|
|
1155
|
+
*
|
|
1156
|
+
* @callback callback will receive mediaUrl{string}
|
|
1157
|
+
*/
|
|
1158
|
+
@CordovaMethod
|
|
1159
|
+
private void getMediaUrl(JSONArray data, CallbackContext callbackContext) {
|
|
1160
|
+
try {
|
|
1161
|
+
JSONObject jsonObject = data.optJSONObject(0);
|
|
1162
|
+
JSONObject inboxMessage = jsonObject.optJSONObject("inboxMessages");
|
|
1163
|
+
JSONObject mediaData = jsonObject.optJSONObject("mediaData");
|
|
1164
|
+
|
|
1165
|
+
AppICEInboxMessage inboxMessageInstance = AppICEInboxMessage.getAppICEInboxMessage(inboxMessage.toString(),
|
|
1166
|
+
cordova.getActivity().getApplicationContext());
|
|
1167
|
+
if (inboxMessageInstance != null) {
|
|
1168
|
+
Map<String, Object> mediaDataMap = JSONObjectToMap(mediaData);
|
|
1169
|
+
String mediaUrl = inboxMessageInstance.getMediaUrl(mediaDataMap);
|
|
1170
|
+
callbackContext.success(mediaUrl);
|
|
1171
|
+
} else {
|
|
1172
|
+
callbackContext.error("Invalid inbox message format");
|
|
1173
|
+
}
|
|
1174
|
+
} catch (Throwable e) {
|
|
1175
|
+
callbackContext.error(e.getMessage());
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* To get Media type from customdata
|
|
1181
|
+
* inboxMessage {AppICEInboxMessage as a ReadableMap}
|
|
1182
|
+
* mediaData customData : this we will recived from getmediadata callback
|
|
1183
|
+
*
|
|
1184
|
+
* @callback callback will receive mediaType{string}
|
|
1185
|
+
*/
|
|
1186
|
+
@CordovaMethod
|
|
1187
|
+
private void getMediaType(JSONArray data, CallbackContext callbackContext) {
|
|
1188
|
+
try {
|
|
1189
|
+
JSONObject jsonObject = data.getJSONObject(0);
|
|
1190
|
+
JSONObject inboxMessage = jsonObject.optJSONObject("inboxMessages");
|
|
1191
|
+
JSONObject mediaData = jsonObject.optJSONObject("mediaData");
|
|
1192
|
+
|
|
1193
|
+
AppICEInboxMessage inboxMessageInstance = AppICEInboxMessage.getAppICEInboxMessage(inboxMessage.toString(),
|
|
1194
|
+
cordova.getActivity().getApplicationContext());
|
|
1195
|
+
if (inboxMessageInstance != null) {
|
|
1196
|
+
Map<String, Object> mediaTypeMap = JSONObjectToMap(mediaData);
|
|
1197
|
+
String mediaType = inboxMessageInstance.getMediaType(mediaTypeMap);
|
|
1198
|
+
callbackContext.success(mediaType);
|
|
1199
|
+
|
|
1200
|
+
} else {
|
|
1201
|
+
callbackContext.error("Invalid inbox message format");
|
|
1202
|
+
}
|
|
1203
|
+
} catch (Throwable e) {
|
|
1204
|
+
callbackContext.error(e.getMessage());
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* To get Media Thumbnail from customdata
|
|
1210
|
+
* inboxMessage {AppICEInboxMessage as a ReadableMap}
|
|
1211
|
+
* mediaData customData : this we will recived from getmediadata callback
|
|
1212
|
+
*
|
|
1213
|
+
* @callback callback will receive Thumbnail{string}
|
|
1214
|
+
*/
|
|
1215
|
+
@CordovaMethod
|
|
1216
|
+
private void getMediaThumbnail(JSONArray data, CallbackContext callbackContext) {
|
|
1217
|
+
try {
|
|
1218
|
+
JSONObject jsonObject = data.getJSONObject(0);
|
|
1219
|
+
JSONObject inboxMessage = jsonObject.optJSONObject("inboxMessages");
|
|
1220
|
+
JSONObject mediaData = jsonObject.optJSONObject("mediaData");
|
|
1221
|
+
|
|
1222
|
+
AppICEInboxMessage inboxMessageInstance = AppICEInboxMessage.getAppICEInboxMessage(inboxMessage.toString(),
|
|
1223
|
+
cordova.getActivity().getApplicationContext());
|
|
1224
|
+
if (inboxMessageInstance != null) {
|
|
1225
|
+
Map<String, Object> MediaThumbnailMap = JSONObjectToMap(mediaData);
|
|
1226
|
+
String MediaThumbnail = inboxMessageInstance.getMediaThumbnail(MediaThumbnailMap);
|
|
1227
|
+
callbackContext.success(MediaThumbnail);
|
|
1228
|
+
} else {
|
|
1229
|
+
callbackContext.error("Invalid inbox message format");
|
|
1230
|
+
}
|
|
1231
|
+
} catch (Throwable e) {
|
|
1232
|
+
callbackContext.error(e.getMessage());
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
private Map<String, Object> JSONObjectToMap(JSONObject jsonObject) {
|
|
1237
|
+
Map<String, Object> resultMap = new HashMap<>();
|
|
1238
|
+
try {
|
|
1239
|
+
// Convert JSONObject to map-like structure
|
|
1240
|
+
Iterator<String> keys = jsonObject.keys();
|
|
1241
|
+
while (keys.hasNext()) {
|
|
1242
|
+
String key = keys.next();
|
|
1243
|
+
Object value = jsonObject.get(key);
|
|
1244
|
+
resultMap.put(key, value);
|
|
1245
|
+
}
|
|
1246
|
+
} catch (JSONException e) {
|
|
1247
|
+
e.printStackTrace();
|
|
1248
|
+
}
|
|
1249
|
+
return resultMap;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
/**
|
|
1253
|
+
* Get inbox messages count.
|
|
1254
|
+
*
|
|
1255
|
+
* @param type the message type
|
|
1256
|
+
* 1 = ALL
|
|
1257
|
+
* 2 = UNREAD
|
|
1258
|
+
* 3 = READ
|
|
1259
|
+
* 4 = VIEWED
|
|
1260
|
+
* 5 = DELETED
|
|
1261
|
+
* @param userIds the same way we are passing the value in setUserId same value
|
|
1262
|
+
* we need here. ie. [ "useridA" ]
|
|
1263
|
+
* @callback will have the integer
|
|
1264
|
+
*/
|
|
1265
|
+
@CordovaMethod
|
|
1266
|
+
private void getMessageCountForUserIds(JSONArray data, CallbackContext callbackContext) {
|
|
1267
|
+
ArrayList<String> userIdList = new ArrayList<>();
|
|
1268
|
+
int count = 0;
|
|
1269
|
+
try {
|
|
1270
|
+
JSONObject object = data.optJSONObject(0);
|
|
1271
|
+
int type = object.optInt("type");
|
|
1272
|
+
JSONArray arr = object.optJSONArray("userId");
|
|
1273
|
+
if (arr != null) {
|
|
1274
|
+
for (int i = 0; i < arr.length(); i++) {
|
|
1275
|
+
userIdList.add((String) arr.get(i));
|
|
1276
|
+
}
|
|
1277
|
+
if (userIdList != null) {
|
|
1278
|
+
try {
|
|
1279
|
+
String[] userIds = userIdList.toArray(new String[userIdList.size()]);
|
|
1280
|
+
count = ContextSdk.getMessageCount(type, userIds,
|
|
1281
|
+
cordova.getActivity().getApplicationContext());
|
|
1282
|
+
callbackContext.success(count);
|
|
1283
|
+
} catch (Throwable e) {
|
|
1284
|
+
callbackContext.error(e.getMessage());
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
} catch (Throwable e) {
|
|
1289
|
+
callbackContext.error(e.getMessage());
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Get inbox messages count.
|
|
1294
|
+
*
|
|
1295
|
+
* @param type the message type
|
|
1296
|
+
* 1 = ALL
|
|
1297
|
+
* 2 = UNREAD
|
|
1298
|
+
* 3 = READ
|
|
1299
|
+
* 4 = VIEWED
|
|
1300
|
+
* 5 = DELETED
|
|
1301
|
+
* @callback will have the integer
|
|
1302
|
+
*/
|
|
1303
|
+
@CordovaMethod
|
|
1304
|
+
private void getMessageCount(JSONArray data, CallbackContext callbackContext) {
|
|
1305
|
+
int count = 0;
|
|
1306
|
+
try {
|
|
1307
|
+
JSONObject object = data.optJSONObject(0);
|
|
1308
|
+
int type = object.optInt("type");
|
|
1309
|
+
count = ContextSdk.getMessageCount(type, cordova.getActivity().getApplicationContext());
|
|
1310
|
+
callbackContext.success(count);
|
|
1311
|
+
} catch (Throwable e) {
|
|
1312
|
+
callbackContext.error(e.getMessage());
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* Get messages payload based on message id.
|
|
1318
|
+
*
|
|
1319
|
+
* @param messageId - message id of the notification
|
|
1320
|
+
* @param userId - single userid in string ie. "useridA"
|
|
1321
|
+
* @callback will have the json object
|
|
1322
|
+
*/
|
|
1323
|
+
@CordovaMethod
|
|
1324
|
+
private void getInboxMessageForIdWithUserId(JSONArray data, CallbackContext callbackContext) {
|
|
1325
|
+
try {
|
|
1326
|
+
JSONObject object = data.optJSONObject(0);
|
|
1327
|
+
String messageId = object.optString("messageId");
|
|
1328
|
+
String userId = object.optString("userId");
|
|
1329
|
+
AppICEInboxMessage inboxMessage = ContextSdk.getInboxMessageForId(messageId, userId,
|
|
1330
|
+
cordova.getActivity().getApplicationContext());
|
|
1331
|
+
if (inboxMessage != null) {
|
|
1332
|
+
callbackContext.success(inboxMessage.toJson());
|
|
1333
|
+
}
|
|
1334
|
+
} catch (Throwable e) {
|
|
1335
|
+
callbackContext.error(e.getMessage());
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* Get messages payload based on message id.
|
|
1341
|
+
*
|
|
1342
|
+
* @param messageId - message id of the notification
|
|
1343
|
+
* @callback will have the json object
|
|
1344
|
+
*/
|
|
1345
|
+
@CordovaMethod
|
|
1346
|
+
private void getInboxMessageForId(JSONArray data, CallbackContext callbackContext) {
|
|
1347
|
+
try {
|
|
1348
|
+
JSONObject object = data.optJSONObject(0);
|
|
1349
|
+
String messageId = object.optString("messageId");
|
|
1350
|
+
AppICEInboxMessage inboxMessage = ContextSdk.getInboxMessageForId(messageId,
|
|
1351
|
+
cordova.getActivity().getApplicationContext());
|
|
1352
|
+
if (inboxMessage != null) {
|
|
1353
|
+
callbackContext.success(inboxMessage.toJson());
|
|
1354
|
+
}
|
|
1355
|
+
} catch (Throwable e) {
|
|
1356
|
+
callbackContext.error(e.getMessage());
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* update message status ex. UNREAD to READ.
|
|
1363
|
+
*
|
|
1364
|
+
* @param messageId - message id of the notification
|
|
1365
|
+
* @param type - integer value for status
|
|
1366
|
+
* @param userId - single userid in string
|
|
1367
|
+
* @callback will have the boolean
|
|
1368
|
+
*/
|
|
1369
|
+
@CordovaMethod
|
|
1370
|
+
private void updateInboxMessageForUserId(JSONArray data, CallbackContext callbackContext) {
|
|
1371
|
+
try {
|
|
1372
|
+
JSONObject object = data.optJSONObject(0);
|
|
1373
|
+
String messageId = object.optString("messageId");
|
|
1374
|
+
int type = object.optInt("type");
|
|
1375
|
+
String userId = object.optString("userId");
|
|
1376
|
+
|
|
1377
|
+
if (userId != null) {
|
|
1378
|
+
boolean isUpdated = ContextSdk.updatedInboxMessage(messageId, type, userId,
|
|
1379
|
+
cordova.getActivity().getApplicationContext());
|
|
1380
|
+
callbackContext.success(String.valueOf(isUpdated));
|
|
1381
|
+
}
|
|
1382
|
+
} catch (Throwable e) {
|
|
1383
|
+
callbackContext.error(e.getMessage());
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Updates the status of an inbox message.
|
|
1389
|
+
*
|
|
1390
|
+
* @param data A JSONArray containing the message ID and update type.
|
|
1391
|
+
* @param callbackContext The callback context to return the result.
|
|
1392
|
+
*/
|
|
1393
|
+
@CordovaMethod
|
|
1394
|
+
private void updateInboxMessage(JSONArray data, CallbackContext callbackContext) {
|
|
1395
|
+
try {
|
|
1396
|
+
JSONObject object = data.optJSONObject(0);
|
|
1397
|
+
String messageId = object.optString("messageId");
|
|
1398
|
+
int type = object.optInt("type");
|
|
1399
|
+
boolean isUpdated = ContextSdk.updateInboxMessage(messageId, type, cordova.getActivity().getApplicationContext());
|
|
1400
|
+
callbackContext.success(String.valueOf(isUpdated));
|
|
1401
|
+
} catch (Throwable e) {
|
|
1402
|
+
callbackContext.error(e.getMessage());
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
|
|
1407
|
+
/**
|
|
1408
|
+
* To sync with server if server will have any new data to update.
|
|
1409
|
+
*
|
|
1410
|
+
* @param timeout - integer value for status
|
|
1411
|
+
* @callback will have the boolean
|
|
1412
|
+
*/
|
|
1413
|
+
@CordovaMethod
|
|
1414
|
+
private void synchronizeInbox(JSONArray data, CallbackContext callbackContext) {
|
|
1415
|
+
try {
|
|
1416
|
+
int timeout = data.optJSONObject(0).optInt("timeout");
|
|
1417
|
+
ContextSdk.synchronizeInbox(new IAppICESuccessCallback() {
|
|
1418
|
+
@Override
|
|
1419
|
+
public void callback(boolean isAppInboxRefreshed) {
|
|
1420
|
+
callbackContext.success(String.valueOf(isAppInboxRefreshed));
|
|
1421
|
+
}
|
|
1422
|
+
}, timeout, cordova.getActivity().getApplicationContext());
|
|
1423
|
+
} catch (Throwable e) {
|
|
1424
|
+
callbackContext.error(e.getMessage());
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* This method is to get user details from the given user id
|
|
1430
|
+
* this method takes user id in form of Array and return User class objects and
|
|
1431
|
+
* return them
|
|
1432
|
+
* from callback
|
|
1433
|
+
*
|
|
1434
|
+
* @param userIds An array of user IDs
|
|
1435
|
+
* @param callback will return instance of User class
|
|
1436
|
+
*/
|
|
1437
|
+
@CordovaMethod
|
|
1438
|
+
private void getUserForIds(JSONArray data, CallbackContext callbackContext) {
|
|
1439
|
+
ArrayList<String> userIdList = new ArrayList<>();
|
|
1440
|
+
try {
|
|
1441
|
+
JSONObject jsonObject = data.optJSONObject(0);
|
|
1442
|
+
JSONArray userIdArray = jsonObject.optJSONArray("userIds");
|
|
1443
|
+
if (userIdArray != null) {
|
|
1444
|
+
for (int i = 0; i < userIdArray.length(); i++) {
|
|
1445
|
+
userIdList.add((String) userIdArray.get(i));
|
|
1446
|
+
}
|
|
1447
|
+
if (userIdList != null) {
|
|
1448
|
+
try {
|
|
1449
|
+
List<User> users = ContextSdk.getUser(userIdList,
|
|
1450
|
+
cordova.getActivity().getApplicationContext());
|
|
1451
|
+
JSONArray usersJsonArray = new JSONArray();
|
|
1452
|
+
for (int i = 0; i < users.size(); i++) {
|
|
1453
|
+
User user = users.get(i);
|
|
1454
|
+
usersJsonArray.put(user.toString());
|
|
1455
|
+
}
|
|
1456
|
+
callbackContext.success(usersJsonArray.toString());
|
|
1457
|
+
} catch (Throwable e) {
|
|
1458
|
+
callbackContext.error(e.getMessage());
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
} catch (Throwable e) {
|
|
1463
|
+
callbackContext.error(e.getMessage());
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
/**
|
|
1468
|
+
* To sync up data with server
|
|
1469
|
+
* callback will have boolean true or false
|
|
1470
|
+
*/
|
|
1471
|
+
@CordovaMethod
|
|
1472
|
+
private void synchronizeData(JSONArray data, CallbackContext callbackContext) {
|
|
1473
|
+
try {
|
|
1474
|
+
int timeout = data.optJSONObject(0).optInt("timeout");
|
|
1475
|
+
ContextSdk.synchronizeData(new IAppICEDataCallback() {
|
|
1476
|
+
@Override
|
|
1477
|
+
public void onSuccess() {
|
|
1478
|
+
callbackContext.success(String.valueOf(true));
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
@Override
|
|
1482
|
+
public void onFailure(String message) {
|
|
1483
|
+
callbackContext.success(String.valueOf(false));
|
|
1484
|
+
}
|
|
1485
|
+
}, timeout, cordova.getActivity().getApplicationContext());
|
|
1486
|
+
} catch (Throwable e) {
|
|
1487
|
+
callbackContext.error(e.getMessage());
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
/**
|
|
1492
|
+
* Schedules a campaign with the given ID, duration, and user ID.
|
|
1493
|
+
*
|
|
1494
|
+
* @param data A JSONArray containing the campaign parameters.
|
|
1495
|
+
* @param callbackContext The callback context to return the result.
|
|
1496
|
+
*/
|
|
1497
|
+
@CordovaMethod
|
|
1498
|
+
private void scheduleCampaign(JSONArray data, CallbackContext callbackContext) {
|
|
1499
|
+
try {
|
|
1500
|
+
JSONObject object = data.optJSONObject(0);
|
|
1501
|
+
String cmpid = object.optString("cmpid");
|
|
1502
|
+
int dur = object.optInt("dur");
|
|
1503
|
+
String userId = object.optString("userId");
|
|
1504
|
+
if (userId != null) {
|
|
1505
|
+
ContextSdk.scheduleCampaign(cmpid, dur, userId);
|
|
1506
|
+
callbackContext.success();
|
|
1507
|
+
}
|
|
1508
|
+
} catch (Throwable e) {
|
|
1509
|
+
callbackContext.error(e.getMessage());
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1000
1513
|
}
|