infobip-mobile-messaging-react-native-plugin 12.5.1 → 12.5.3

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 CHANGED
@@ -15,8 +15,8 @@ The document describes library integration steps for your React Native project.
15
15
  - React Native (v0.70.8)
16
16
 
17
17
  For iOS project:
18
- - Xcode and Command Line Tools (13.2.1)
19
- - CocoaPods (v1.11.3)
18
+ - Xcode and Command Line Tools (16.1)
19
+ - CocoaPods (v1.15.2)
20
20
  - Minimum deployment target 12.4
21
21
 
22
22
  For Android project:
@@ -86,7 +86,7 @@ repositories {
86
86
  }
87
87
 
88
88
  dependencies {
89
- def mmVersion = '13.1.1'
89
+ def mmVersion = '13.2.3'
90
90
  //react and mm dependencies clash
91
91
  if (!overrideKotlinVersion.empty) {
92
92
  constraints {
@@ -52,8 +52,10 @@ import org.infobip.mobile.messaging.chat.InAppChat;
52
52
  import org.infobip.mobile.messaging.chat.core.InAppChatEvent;
53
53
  import org.infobip.mobile.messaging.dal.bundle.MessageBundleMapper;
54
54
  import org.infobip.mobile.messaging.inbox.Inbox;
55
+ import org.infobip.mobile.messaging.inbox.InboxMapper;
55
56
  import org.infobip.mobile.messaging.inbox.MobileInbox;
56
57
  import org.infobip.mobile.messaging.inbox.MobileInboxFilterOptions;
58
+ import org.infobip.mobile.messaging.inbox.MobileInboxFilterOptionsJson;
57
59
  import org.infobip.mobile.messaging.interactive.InteractiveEvent;
58
60
  import org.infobip.mobile.messaging.interactive.MobileInteractive;
59
61
  import org.infobip.mobile.messaging.interactive.NotificationAction;
@@ -67,14 +69,12 @@ import org.infobip.mobile.messaging.storage.SQLiteMessageStore;
67
69
  import org.infobip.mobile.messaging.util.Cryptor;
68
70
  import org.infobip.mobile.messaging.util.DeviceInformation;
69
71
  import org.infobip.mobile.messaging.util.PreferenceHelper;
70
- import org.infobip.reactlibrary.mobilemessaging.datamappers.CustomEventJson;
71
- import org.infobip.reactlibrary.mobilemessaging.datamappers.InboxJson;
72
- import org.infobip.reactlibrary.mobilemessaging.datamappers.InstallationJson;
73
- import org.infobip.reactlibrary.mobilemessaging.datamappers.MessageJson;
74
- import org.infobip.reactlibrary.mobilemessaging.datamappers.MobileInboxFilterOptionsJson;
75
- import org.infobip.reactlibrary.mobilemessaging.datamappers.PersonalizationCtx;
72
+ import org.infobip.mobile.messaging.plugins.CustomEventJson;
73
+ import org.infobip.mobile.messaging.plugins.InstallationJson;
74
+ import org.infobip.mobile.messaging.plugins.MessageJson;
75
+ import org.infobip.mobile.messaging.plugins.PersonalizationCtx;
76
+ import org.infobip.mobile.messaging.plugins.UserJson;
76
77
  import org.infobip.reactlibrary.mobilemessaging.datamappers.ReactNativeJson;
77
- import org.infobip.reactlibrary.mobilemessaging.datamappers.UserJson;
78
78
  import org.json.JSONArray;
79
79
  import org.json.JSONException;
80
80
  import org.json.JSONObject;
@@ -587,7 +587,7 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
587
587
  @ReactMethod
588
588
  public void fetchInboxMessages(@NonNull String token, @NonNull String externalUserId, ReadableMap args, final Callback successCallback, final Callback errorCallback) throws JSONException {
589
589
  try {
590
- mobileMessagingInbox().fetchInbox(token, externalUserId, MobileInboxFilterOptionsJson.resolveMobileInboxFilterOptions(ReactNativeJson.convertMapToJson(args)), inboxResultListener(successCallback, errorCallback));
590
+ mobileMessagingInbox().fetchInbox(token, externalUserId, MobileInboxFilterOptionsJson.mobileInboxFilterOptionsFromJSON(ReactNativeJson.convertMapToJson(args)), inboxResultListener(successCallback, errorCallback));
591
591
  } catch (IllegalArgumentException e) {
592
592
  Log.d(Utils.TAG, "Error fetching inbox:" + e.getMessage());
593
593
  }
@@ -596,7 +596,7 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
596
596
  @ReactMethod
597
597
  public void fetchInboxMessagesWithoutToken(@NonNull String externalUserId, ReadableMap args, final Callback successCallback, final Callback errorCallback) throws JSONException {
598
598
  try {
599
- mobileMessagingInbox().fetchInbox(externalUserId, MobileInboxFilterOptionsJson.resolveMobileInboxFilterOptions(ReactNativeJson.convertMapToJson(args)), inboxResultListener(successCallback, errorCallback));
599
+ mobileMessagingInbox().fetchInbox(externalUserId, MobileInboxFilterOptionsJson.mobileInboxFilterOptionsFromJSON(ReactNativeJson.convertMapToJson(args)), inboxResultListener(successCallback, errorCallback));
600
600
  } catch (IllegalArgumentException e) {
601
601
  Log.d(Utils.TAG, "Error fetching inbox:" + e.getMessage());
602
602
  }
@@ -621,7 +621,12 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
621
621
  @Override
622
622
  public void onResult(Result<Inbox, MobileMessagingError> result) {
623
623
  if (result.isSuccess()) {
624
- ReadableMap readableMap = InboxJson.toReadableMap(result.getData());
624
+ ReadableMap readableMap = null;
625
+ try {
626
+ readableMap = ReactNativeJson.convertJsonToMap(InboxMapper.toJSON(result.getData()));
627
+ } catch (JSONException e) {
628
+ e.printStackTrace();
629
+ }
625
630
  successCallback.invoke(readableMap);
626
631
  } else {
627
632
  errorCallback.invoke(Utils.callbackError(result.getError().getMessage(), null));
@@ -675,7 +680,12 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
675
680
  @Override
676
681
  public void onResult(Result<User, MobileMessagingError> result) {
677
682
  if (result.isSuccess()) {
678
- ReadableMap readableMap = UserJson.toReadableMap(result.getData());
683
+ ReadableMap readableMap = null;
684
+ try {
685
+ readableMap = ReactNativeJson.convertJsonToMap(UserJson.toJSON(result.getData()));
686
+ } catch (JSONException e) {
687
+ e.printStackTrace();
688
+ }
679
689
  successCallback.invoke(readableMap);
680
690
  } else {
681
691
  errorCallback.invoke(Utils.callbackError(result.getError().getMessage(), null));
@@ -687,8 +697,13 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
687
697
  @ReactMethod
688
698
  public void getUser(final Callback successCallback) {
689
699
  User user = mobileMessaging().getUser();
690
- ReadableMap userReadableMap = UserJson.toReadableMap(user);
691
- successCallback.invoke(userReadableMap);
700
+ ReadableMap readableMap = null;
701
+ try {
702
+ readableMap = ReactNativeJson.convertJsonToMap(UserJson.toJSON(user));
703
+ } catch (JSONException e) {
704
+ e.printStackTrace();
705
+ }
706
+ successCallback.invoke(readableMap);
692
707
  }
693
708
 
694
709
  @ReactMethod
@@ -708,7 +723,12 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
708
723
  @Override
709
724
  public void onResult(Result<Installation, MobileMessagingError> result) {
710
725
  if (result.isSuccess()) {
711
- ReadableMap readableMap = InstallationJson.toReadableMap(result.getData());
726
+ ReadableMap readableMap = null;
727
+ try {
728
+ readableMap = ReactNativeJson.convertJsonToMap(InstallationJson.toJSON(result.getData()));
729
+ } catch (JSONException e) {
730
+ e.printStackTrace();
731
+ }
712
732
  successCallback.invoke(readableMap);
713
733
  } else {
714
734
  errorCallback.invoke(Utils.callbackError(result.getError().getMessage(), null));
@@ -720,8 +740,13 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
720
740
  @ReactMethod
721
741
  public void getInstallation(final Callback successCallback) {
722
742
  Installation installation = mobileMessaging().getInstallation();
723
- ReadableMap installationReadableMap = InstallationJson.toReadableMap(installation);
724
- successCallback.invoke(installationReadableMap);
743
+ ReadableMap readableMap = null;
744
+ try {
745
+ readableMap = ReactNativeJson.convertJsonToMap(InstallationJson.toJSON(installation));
746
+ } catch (JSONException e) {
747
+ e.printStackTrace();
748
+ }
749
+ successCallback.invoke(readableMap);
725
750
  }
726
751
 
727
752
  @ReactMethod
@@ -732,7 +757,12 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
732
757
  @Override
733
758
  public void onResult(Result<User, MobileMessagingError> result) {
734
759
  if (result.isSuccess()) {
735
- ReadableMap readableMap = UserJson.toReadableMap(result.getData());
760
+ ReadableMap readableMap = null;
761
+ try {
762
+ readableMap = ReactNativeJson.convertJsonToMap(UserJson.toJSON(result.getData()));
763
+ } catch (JSONException e) {
764
+ e.printStackTrace();
765
+ }
736
766
  successCallback.invoke(readableMap);
737
767
  } else {
738
768
  errorCallback.invoke(Utils.callbackError(result.getError().getMessage(), null));
@@ -788,7 +818,12 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
788
818
  @Override
789
819
  public void onResult(Result<List<Installation>, MobileMessagingError> result) {
790
820
  if (result.isSuccess()) {
791
- ReadableArray readableArray = InstallationJson.toReadableArray(result.getData());
821
+ ReadableArray readableArray = null;
822
+ try {
823
+ readableArray = ReactNativeJson.convertJsonToArray(InstallationJson.toJSON(result.getData()));
824
+ } catch (JSONException e) {
825
+ e.printStackTrace();
826
+ }
792
827
  successCallback.invoke(readableArray);
793
828
  } else {
794
829
  errorCallback.invoke(Utils.callbackError(result.getError().getMessage(), null));
@@ -19,10 +19,10 @@ Pod::Spec.new do |s|
19
19
  s.requires_arc = true
20
20
 
21
21
  s.dependency "React-Core"
22
- s.dependency "MobileMessaging/Core", "12.14.0"
23
- s.dependency "MobileMessaging/InAppChat", "12.14.0"
24
- s.dependency "MobileMessaging/Inbox", "12.14.0"
22
+ s.dependency "MobileMessaging/Core", "12.14.1"
23
+ s.dependency "MobileMessaging/InAppChat", "12.14.1"
24
+ s.dependency "MobileMessaging/Inbox", "12.14.1"
25
25
  if defined?($WebRTCUIEnabled)
26
- s.dependency "MobileMessaging/WebRTCUI", "12.14.0"
26
+ s.dependency "MobileMessaging/WebRTCUI", "12.14.1"
27
27
  end
28
28
  end
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "infobip-mobile-messaging-react-native-plugin",
3
3
  "title": "Infobip Mobile Messaging React Native Plugin",
4
- "version": "12.5.1",
4
+ "version": "12.5.3",
5
5
  "description": "Infobip Mobile Messaging React Native Plugin",
6
6
  "main": "./src/index.js",
7
7
  "scripts": {
@@ -1,42 +0,0 @@
1
- package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
-
3
- import android.util.Log;
4
-
5
- import com.google.gson.reflect.TypeToken;
6
-
7
- import org.infobip.mobile.messaging.CustomAttributesMapper;
8
- import org.infobip.mobile.messaging.CustomEvent;
9
- import org.infobip.mobile.messaging.api.appinstance.UserCustomEventAtts;
10
- import org.infobip.mobile.messaging.api.support.http.serialization.JsonSerializer;
11
- import org.json.JSONObject;
12
-
13
- import java.lang.reflect.Type;
14
- import java.util.Map;
15
-
16
- /**
17
- * User data mapper for JSON conversion
18
- */
19
- public class CustomEventJson extends CustomEvent {
20
-
21
- public static CustomEvent fromJSON(JSONObject json) {
22
- CustomEvent customEvent = new CustomEvent();
23
- try {
24
- if (json.has(UserCustomEventAtts.definitionId)) {
25
- customEvent.setDefinitionId(json.optString(UserCustomEventAtts.definitionId));
26
- }
27
- } catch (Exception e) {
28
- throw new IllegalArgumentException("Error when serializing CustomEvent object:" + Log.getStackTraceString(e));
29
- }
30
- try {
31
- if (json.has(UserCustomEventAtts.properties)) {
32
- Type type = new TypeToken<Map<String, Object>>() {
33
- }.getType();
34
- Map<String, Object> properties = new JsonSerializer().deserialize(json.optString(UserCustomEventAtts.properties), type);
35
- customEvent.setProperties(CustomAttributesMapper.customAttsFromBackend(properties));
36
- }
37
- } catch (Exception e) {
38
- throw new IllegalArgumentException("Error when serializing CustomEvent object:" + Log.getStackTraceString(e));
39
- }
40
- return customEvent;
41
- }
42
- }
@@ -1,31 +0,0 @@
1
- package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
-
3
- import com.facebook.react.bridge.ReadableMap;
4
- import org.infobip.mobile.messaging.inbox.Inbox;
5
- import org.infobip.mobile.messaging.inbox.InboxMapper;
6
- import org.json.JSONException;
7
- import org.json.JSONObject;
8
-
9
- public class InboxJson extends Inbox {
10
-
11
- public static JSONObject toJSON(final Inbox inbox) {
12
- if (inbox == null) {
13
- return new JSONObject();
14
- }
15
- try {
16
- return new JSONObject(inbox.toString());
17
- } catch (JSONException e) {
18
- e.printStackTrace();
19
- return new JSONObject();
20
- }
21
- }
22
-
23
- public static ReadableMap toReadableMap(final Inbox inbox) {
24
- try {
25
- return ReactNativeJson.convertJsonToMap(toJSON(inbox));
26
- } catch (JSONException e) {
27
- e.printStackTrace();
28
- return null;
29
- }
30
- }
31
- }
@@ -1,106 +0,0 @@
1
- package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
-
3
- import androidx.annotation.NonNull;
4
-
5
- import com.facebook.react.bridge.ReadableArray;
6
- import com.facebook.react.bridge.ReadableMap;
7
- import com.google.gson.reflect.TypeToken;
8
-
9
- import org.infobip.mobile.messaging.CustomAttributeValue;
10
- import org.infobip.mobile.messaging.CustomAttributesMapper;
11
- import org.infobip.mobile.messaging.Installation;
12
- import org.infobip.mobile.messaging.InstallationMapper;
13
- import org.infobip.mobile.messaging.api.support.http.serialization.JsonSerializer;
14
- import org.json.JSONArray;
15
- import org.json.JSONException;
16
- import org.json.JSONObject;
17
-
18
- import java.lang.reflect.Type;
19
- import java.util.List;
20
- import java.util.Map;
21
-
22
- public class InstallationJson extends Installation {
23
-
24
- public static JSONArray toJSON(final List<Installation> installations) {
25
- if (installations == null) {
26
- return null;
27
- }
28
- JSONArray installationsJson = new JSONArray();
29
- for (Installation installation : installations) {
30
- installationsJson.put(toJSON(installation));
31
- }
32
- return installationsJson;
33
- }
34
-
35
- @NonNull
36
- public static Installation resolveInstallation(JSONObject args) throws JSONException {
37
- if (args == null) {
38
- throw new IllegalArgumentException("Cannot resolve installation from arguments");
39
- }
40
-
41
- return InstallationJson.fromJSON(args);
42
- }
43
-
44
- public static JSONObject toJSON(final Installation installation) {
45
- try {
46
- String json = InstallationMapper.toJson(installation);
47
- JSONObject jsonObject = new JSONObject(json);
48
- cleanupJsonMapForClient(installation.getCustomAttributes(), jsonObject);
49
- return jsonObject;
50
- } catch (JSONException e) {
51
- e.printStackTrace();
52
- return new JSONObject();
53
- }
54
- }
55
-
56
- public static ReadableMap toReadableMap(final Installation installation) {
57
- try {
58
- return ReactNativeJson.convertJsonToMap(InstallationJson.toJSON(installation));
59
- } catch (JSONException e) {
60
- e.printStackTrace();
61
- return null;
62
- }
63
- }
64
-
65
- public static ReadableArray toReadableArray(final List<Installation> installations) {
66
- try {
67
- return ReactNativeJson.convertJsonToArray(InstallationJson.toJSON(installations));
68
- } catch (JSONException e) {
69
- e.printStackTrace();
70
- return null;
71
- }
72
- }
73
-
74
- private static Installation fromJSON(JSONObject json) {
75
- Installation installation = new Installation();
76
-
77
- try {
78
- if (json.has("isPushRegistrationEnabled")) {
79
- installation.setPushRegistrationEnabled(json.optBoolean("isPushRegistrationEnabled"));
80
- }
81
- if (json.has("isPrimaryDevice")) {
82
- installation.setPrimaryDevice(json.optBoolean("isPrimaryDevice"));
83
- }
84
- if (json.has("customAttributes")) {
85
- Type type = new TypeToken<Map<String, Object>>() {
86
- }.getType();
87
- Map<String, Object> customAttributes = new JsonSerializer().deserialize(json.optString("customAttributes"), type);
88
- installation.setCustomAttributes(CustomAttributesMapper.customAttsFromBackend(customAttributes));
89
- }
90
- } catch (Exception e) {
91
- //error parsing
92
- }
93
-
94
- return installation;
95
- }
96
-
97
- private static void cleanupJsonMapForClient(Map<String, CustomAttributeValue> customAttributes, JSONObject jsonObject) throws JSONException {
98
- jsonObject.remove("map");
99
- if (jsonObject.has("customAttributes")) {
100
- if (customAttributes != null) {
101
- jsonObject.put("customAttributes", new JSONObject(CustomAttributesMapper.customAttsToBackend(customAttributes)));
102
- }
103
- }
104
- }
105
- }
106
-
@@ -1,141 +0,0 @@
1
- package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
-
3
- import android.os.Bundle;
4
- import android.util.Log;
5
-
6
- import androidx.annotation.NonNull;
7
-
8
- import org.infobip.mobile.messaging.Message;
9
- import org.infobip.reactlibrary.mobilemessaging.Utils;
10
- import org.json.JSONArray;
11
- import org.json.JSONException;
12
- import org.json.JSONObject;
13
-
14
- import java.lang.reflect.Method;
15
- import java.util.ArrayList;
16
- import java.util.List;
17
-
18
- public class MessageJson {
19
- /**
20
- * Creates new json object based on message bundle
21
- *
22
- * @param bundle message bundle
23
- * @return message object in json format
24
- */
25
- public static JSONObject bundleToJSON(Bundle bundle) {
26
- Message message = Message.createFrom(bundle);
27
- if (message == null) {
28
- return null;
29
- }
30
-
31
- return toJSON(message);
32
- }
33
-
34
- /**
35
- * Creates json from a message object
36
- *
37
- * @param message message object
38
- * @return message json
39
- */
40
- public static JSONObject toJSON(Message message) {
41
- try {
42
- return new JSONObject()
43
- .putOpt("messageId", message.getMessageId())
44
- .putOpt("title", message.getTitle())
45
- .putOpt("body", message.getBody())
46
- .putOpt("sound", message.getSound())
47
- .putOpt("vibrate", message.isVibrate())
48
- .putOpt("icon", message.getIcon())
49
- .putOpt("silent", message.isSilent())
50
- .putOpt("category", message.getCategory())
51
- .putOpt("from", message.getFrom())
52
- .putOpt("receivedTimestamp", message.getReceivedTimestamp())
53
- .putOpt("customPayload", message.getCustomPayload())
54
- .putOpt("contentUrl", message.getContentUrl())
55
- .putOpt("seen", message.getSeenTimestamp() != 0)
56
- .putOpt("seenDate", message.getSeenTimestamp())
57
- .putOpt("chat", message.isChatMessage())
58
- .putOpt("browserUrl", message.getBrowserUrl())
59
- .putOpt("webViewUrl", message.getWebViewUrl())
60
- .putOpt("deeplink", message.getDeeplink())
61
- .putOpt("inAppOpenTitle", message.getInAppOpenTitle())
62
- .putOpt("inAppDismissTitle", message.getInAppDismissTitle());
63
- } catch (JSONException e) {
64
- Log.w(Utils.TAG, "Cannot convert message to JSON: " + e.getMessage());
65
- Log.d(Utils.TAG, Log.getStackTraceString(e));
66
- return null;
67
- }
68
- }
69
-
70
- /**
71
- * Creates array of json objects from list of messages
72
- *
73
- * @param messages list of messages
74
- * @return array of jsons representing messages
75
- */
76
- public static JSONArray toJSONArray(@NonNull Message messages[]) {
77
- JSONArray array = new JSONArray();
78
- for (Message message : messages) {
79
- JSONObject json = toJSON(message);
80
- if (json == null) {
81
- continue;
82
- }
83
- array.put(json);
84
- }
85
- return array;
86
- }
87
-
88
- /**
89
- * Creates new messages from json object
90
- *
91
- * @param json json object
92
- * @return new {@link Message} object.
93
- */
94
- private static Message fromJSON(JSONObject json) {
95
- if (json == null) {
96
- return null;
97
- }
98
-
99
- Message message = new Message();
100
- message.setMessageId(json.optString("messageId", null));
101
- message.setTitle(json.optString("title", null));
102
- message.setBody(json.optString("body", null));
103
- message.setSound(json.optString("sound", null));
104
- message.setVibrate(json.optBoolean("vibrate", true));
105
- message.setIcon(json.optString("icon", null));
106
- message.setSilent(json.optBoolean("silent", false));
107
- message.setCategory(json.optString("category", null));
108
- message.setFrom(json.optString("from", null));
109
- message.setReceivedTimestamp(json.optLong("receivedTimestamp", 0));
110
- message.setCustomPayload(json.optJSONObject("customPayload"));
111
- message.setContentUrl(json.optString("contentUrl", null));
112
- message.setSeenTimestamp(json.optLong("seenDate", 0));
113
- message.setBrowserUrl(json.optString("browserUrl", null));
114
- message.setWebViewUrl(json.optString("webViewUrl", null));
115
- message.setDeeplink(json.optString("deeplink", null));
116
- message.setInAppOpenTitle(json.optString("inAppOpenTitle", null));
117
- message.setInAppDismissTitle(json.optString("inAppDismissTitle", null));
118
- if (json.optBoolean("chat", false)) {
119
- message.setMessageType(Message.MESSAGE_TYPE_CHAT);
120
- }
121
- return message;
122
- }
123
-
124
- @NonNull
125
- public static List<Message> resolveMessages(JSONArray args) throws JSONException {
126
- if (args == null || args.length() < 1 || args.getString(0) == null) {
127
- throw new IllegalArgumentException("Cannot resolve messages from arguments");
128
- }
129
-
130
- List<Message> messages = new ArrayList<Message>(args.length());
131
- for (int i = 0; i < args.length(); i++) {
132
- Message m = fromJSON(args.optJSONObject(i));
133
- if (m == null) {
134
- continue;
135
- }
136
-
137
- messages.add(m);
138
- }
139
- return messages;
140
- }
141
- }
@@ -1,8 +0,0 @@
1
- package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
-
3
- public class MobileInboxFilterOptionsAttrs {
4
- public static final String fromDateTime = "fromDateTime";
5
- public static final String toDateTime = "toDateTime";
6
- public static final String topic = "topic";
7
- public static final String limit = "limit";
8
- }
@@ -1,84 +0,0 @@
1
- package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
-
3
- import androidx.annotation.NonNull;
4
- import android.util.Log;
5
-
6
- import org.infobip.mobile.messaging.api.support.http.serialization.JsonSerializer;
7
- import org.infobip.mobile.messaging.inbox.MobileInboxFilterOptions;
8
- import org.infobip.reactlibrary.mobilemessaging.Utils;
9
- import org.json.JSONException;
10
- import org.json.JSONObject;
11
-
12
- import java.text.SimpleDateFormat;
13
- import java.util.Date;
14
-
15
- /**
16
- * Inbox filter data mapper for JSON conversion
17
- */
18
- public class MobileInboxFilterOptionsJson extends MobileInboxFilterOptions {
19
-
20
- private static final JsonSerializer nullSerializer = new JsonSerializer(true);
21
-
22
- public MobileInboxFilterOptionsJson(Date fromDateTime, Date toDateTime, String topic, Integer limit) {
23
- super(fromDateTime, toDateTime, topic, limit);
24
- }
25
-
26
- public static JSONObject toJSON(final MobileInboxFilterOptions mobileInboxFilterOptions) {
27
- if (mobileInboxFilterOptions == null) {
28
- return new JSONObject();
29
- }
30
- try {
31
- return new JSONObject(nullSerializer.serialize(mobileInboxFilterOptions));
32
- } catch (JSONException e) {
33
- e.printStackTrace();
34
- return new JSONObject();
35
- }
36
- }
37
-
38
- @NonNull
39
- public static MobileInboxFilterOptions resolveMobileInboxFilterOptions(JSONObject args) throws IllegalArgumentException {
40
- if (args == null) {
41
- throw new IllegalArgumentException("Cannot resolve inbox filters from arguments");
42
- }
43
- return MobileInboxFilterOptionsJson.mobileInboxFilterOptionsFromJSON(args);
44
- }
45
-
46
- private static MobileInboxFilterOptions mobileInboxFilterOptionsFromJSON(JSONObject json) throws IllegalArgumentException {
47
- MobileInboxFilterOptions mobileInboxFilterOptions = null;
48
- String fromDate = null;
49
- String toDate = null;
50
- String topic = null;
51
- Integer limit = null;
52
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");
53
- try {
54
- if (json.has(MobileInboxFilterOptionsAttrs.fromDateTime)) {
55
- fromDate = json.optString(MobileInboxFilterOptionsAttrs.fromDateTime);
56
- }
57
- if (json.has(MobileInboxFilterOptionsAttrs.toDateTime)) {
58
- toDate = json.optString(MobileInboxFilterOptionsAttrs.toDateTime);
59
- }
60
- if (json.has(MobileInboxFilterOptionsAttrs.topic)) {
61
- topic = json.optString(MobileInboxFilterOptionsAttrs.topic);
62
- }
63
- if (json.has(MobileInboxFilterOptionsAttrs.limit)) {
64
- limit = json.optInt(MobileInboxFilterOptionsAttrs.limit);
65
- }
66
- mobileInboxFilterOptions = new MobileInboxFilterOptions(null, null, null, null);
67
- if(fromDate != null) {
68
- mobileInboxFilterOptions.setFromDateTime(sdf.parse(fromDate));
69
- }
70
- if(toDate != null) {
71
- mobileInboxFilterOptions.setToDateTime(sdf.parse(toDate));
72
- }
73
- if(topic != null) {
74
- mobileInboxFilterOptions.setTopic(topic);
75
- }
76
- if(limit != null) {
77
- mobileInboxFilterOptions.setLimit(limit);
78
- }
79
- } catch (Exception e) {
80
- e.printStackTrace();
81
- }
82
- return mobileInboxFilterOptions;
83
- }
84
- }
@@ -1,26 +0,0 @@
1
- package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
-
3
- import org.infobip.mobile.messaging.UserAttributes;
4
- import org.infobip.mobile.messaging.UserIdentity;
5
- import org.json.JSONException;
6
- import org.json.JSONObject;
7
-
8
- public class PersonalizationCtx {
9
- public UserIdentity userIdentity;
10
- public UserAttributes userAttributes;
11
- public boolean forceDepersonalize;
12
- public boolean keepAsLead;
13
-
14
- public static PersonalizationCtx resolvePersonalizationCtx(JSONObject args) throws JSONException, IllegalArgumentException {
15
- if (args == null) {
16
- throw new IllegalArgumentException("Cannot resolve personalization context from arguments");
17
- }
18
-
19
- PersonalizationCtx ctx = new PersonalizationCtx();
20
- ctx.forceDepersonalize = args.optBoolean("forceDepersonalize", false);
21
- ctx.userIdentity = UserJson.userIdentityFromJson(args.getJSONObject("userIdentity"));
22
- ctx.userAttributes = UserJson.userAttributesFromJson(args.optJSONObject("userAttributes"));
23
- ctx.keepAsLead = args.optBoolean("keepAsLead", false);
24
- return ctx;
25
- }
26
- }
@@ -1,212 +0,0 @@
1
- package org.infobip.reactlibrary.mobilemessaging.datamappers;
2
-
3
- import androidx.annotation.NonNull;
4
-
5
- import com.facebook.react.bridge.ReadableMap;
6
- import com.google.gson.reflect.TypeToken;
7
-
8
- import org.infobip.mobile.messaging.CustomAttributeValue;
9
- import org.infobip.mobile.messaging.CustomAttributesMapper;
10
- import org.infobip.mobile.messaging.User;
11
- import org.infobip.mobile.messaging.UserAttributes;
12
- import org.infobip.mobile.messaging.UserIdentity;
13
- import org.infobip.mobile.messaging.UserMapper;
14
- import org.infobip.mobile.messaging.api.appinstance.UserAtts;
15
- import org.infobip.mobile.messaging.api.support.http.serialization.JsonSerializer;
16
- import org.infobip.mobile.messaging.util.DateTimeUtil;
17
- import org.json.JSONArray;
18
- import org.json.JSONException;
19
- import org.json.JSONObject;
20
-
21
- import java.lang.reflect.Type;
22
- import java.text.ParseException;
23
- import java.util.Date;
24
- import java.util.HashSet;
25
- import java.util.Map;
26
- import java.util.Set;
27
-
28
- /**
29
- * User data mapper for JSON conversion
30
- */
31
- public class UserJson extends User {
32
-
33
- public static JSONObject toJSON(final User user) {
34
- if (user == null) {
35
- return new JSONObject();
36
- }
37
- try {
38
- JSONObject jsonObject = new JSONObject(UserMapper.toJson(user));
39
- cleanupJsonMapForClient(user.getCustomAttributes(), jsonObject);
40
- return jsonObject;
41
- } catch (JSONException e) {
42
- e.printStackTrace();
43
- return new JSONObject();
44
- }
45
- }
46
-
47
- @NonNull
48
- public static User resolveUser(JSONObject args) throws IllegalArgumentException {
49
- if (args == null) {
50
- throw new IllegalArgumentException("Cannot resolve user from arguments");
51
- }
52
-
53
- return UserJson.fromJSON(args);
54
- }
55
-
56
- public static ReadableMap toReadableMap(final User user) {
57
- try {
58
- return ReactNativeJson.convertJsonToMap(toJSON(user));
59
- } catch (JSONException e) {
60
- e.printStackTrace();
61
- return null;
62
- }
63
- }
64
-
65
- private static User fromJSON(JSONObject json) throws IllegalArgumentException {
66
- User user = new User();
67
-
68
- try {
69
- if (json.has(UserAtts.externalUserId)) {
70
- user.setExternalUserId(json.optString(UserAtts.externalUserId));
71
- }
72
- if (json.has(UserAtts.firstName)) {
73
- user.setFirstName(json.optString(UserAtts.firstName));
74
- }
75
- if (json.has(UserAtts.lastName)) {
76
- user.setLastName(json.optString(UserAtts.lastName));
77
- }
78
- if (json.has(UserAtts.middleName)) {
79
- user.setMiddleName(json.optString(UserAtts.middleName));
80
- }
81
- if (json.has(UserAtts.gender)) {
82
- user.setGender(UserMapper.genderFromBackend(json.optString(UserAtts.gender)));
83
- }
84
- if (json.has(UserAtts.birthday)) {
85
- Date bday = null;
86
- try {
87
- bday = DateTimeUtil.dateFromYMDString(json.optString(UserAtts.birthday));
88
- user.setBirthday(bday);
89
- } catch (ParseException e) {
90
- }
91
- }
92
- if (json.has(UserAtts.phones)) {
93
- user.setPhones(jsonArrayFromJsonObjectToSet(json, UserAtts.phones));
94
- }
95
- if (json.has(UserAtts.emails)) {
96
- user.setEmails(jsonArrayFromJsonObjectToSet(json, UserAtts.emails));
97
- }
98
- if (json.has(UserAtts.tags)) {
99
- user.setTags(jsonArrayFromJsonObjectToSet(json, UserAtts.tags));
100
- }
101
- } catch (Exception e) {
102
- e.printStackTrace();
103
- }
104
-
105
- try {
106
- if (json.has(UserAtts.customAttributes)) {
107
- java.lang.reflect.Type type = new TypeToken<Map<String, Object>>() {
108
- }.getType();
109
- Map<String, Object> customAttributes = new JsonSerializer().deserialize(json.optString(UserAtts.customAttributes), type);
110
- if (!CustomAttributesMapper.validate(customAttributes)) {
111
- throw new IllegalArgumentException("Custom attributes are invalid.");
112
- }
113
- user.setCustomAttributes(CustomAttributesMapper.customAttsFromBackend(customAttributes));
114
- }
115
- } catch (Exception e) {
116
- e.printStackTrace();
117
- }
118
-
119
- return user;
120
- }
121
-
122
- public static UserAttributes userAttributesFromJson(JSONObject json) throws IllegalArgumentException {
123
- if (json == null) {
124
- return null;
125
- }
126
-
127
- UserAttributes userAttributes = new UserAttributes();
128
-
129
- try {
130
- if (json.has(UserAtts.firstName)) {
131
- userAttributes.setFirstName(json.optString(UserAtts.firstName));
132
- }
133
- if (json.has(UserAtts.lastName)) {
134
- userAttributes.setLastName(json.optString(UserAtts.lastName));
135
- }
136
- if (json.has(UserAtts.middleName)) {
137
- userAttributes.setMiddleName(json.optString(UserAtts.middleName));
138
- }
139
- if (json.has(UserAtts.gender)) {
140
- userAttributes.setGender(UserMapper.genderFromBackend(json.optString(UserAtts.gender)));
141
- }
142
- if (json.has(UserAtts.birthday)) {
143
- Date bday = null;
144
- try {
145
- bday = DateTimeUtil.dateFromYMDString(json.optString(UserAtts.birthday));
146
- userAttributes.setBirthday(bday);
147
- } catch (ParseException e) {
148
- }
149
- }
150
- if (json.has(UserAtts.tags)) {
151
- userAttributes.setTags(jsonArrayFromJsonObjectToSet(json, UserAtts.tags));
152
- }
153
- } catch (Exception e) {
154
- e.printStackTrace();
155
- }
156
-
157
- try {
158
- if (json.has(UserAtts.customAttributes)) {
159
- java.lang.reflect.Type type = new TypeToken<Map<String, Object>>() {
160
- }.getType();
161
- Map<String, Object> customAttributes = new JsonSerializer().deserialize(json.optString(UserAtts.customAttributes), type);
162
- if (!CustomAttributesMapper.validate(customAttributes)) {
163
- throw new IllegalArgumentException("Custom attributes are invalid.");
164
- }
165
- userAttributes.setCustomAttributes(CustomAttributesMapper.customAttsFromBackend(customAttributes));
166
- }
167
- } catch (Exception e) {
168
- e.printStackTrace();
169
- }
170
-
171
- return userAttributes;
172
- }
173
-
174
- public static UserIdentity userIdentityFromJson(JSONObject json) {
175
- UserIdentity userIdentity = new UserIdentity();
176
- try {
177
- if (json.has(UserAtts.externalUserId)) {
178
- userIdentity.setExternalUserId(json.optString(UserAtts.externalUserId));
179
- }
180
- if (json.has(UserAtts.phones)) {
181
- userIdentity.setPhones(jsonArrayFromJsonObjectToSet(json, UserAtts.phones));
182
- }
183
- if (json.has(UserAtts.emails)) {
184
- userIdentity.setEmails(jsonArrayFromJsonObjectToSet(json, UserAtts.emails));
185
- }
186
- } catch (Exception e) {
187
- e.printStackTrace();
188
- }
189
- return userIdentity;
190
- }
191
-
192
- private static Set<String> jsonArrayFromJsonObjectToSet(JSONObject jsonObject, String arrayName) {
193
- Set<String> set = new HashSet<String>();
194
- JSONArray jsonArray = jsonObject.optJSONArray(arrayName);
195
- if (jsonArray != null) {
196
- for (int i = 0; i < jsonArray.length(); i++) {
197
- set.add(jsonArray.optString(i));
198
- }
199
- }
200
- return set;
201
- }
202
-
203
- //TODO: duplicates in InstallationJson
204
- private static void cleanupJsonMapForClient(Map<String, CustomAttributeValue> customAttributes, JSONObject jsonObject) throws JSONException {
205
- jsonObject.remove("map");
206
- if (jsonObject.has("customAttributes")) {
207
- if (customAttributes != null) {
208
- jsonObject.put("customAttributes", new JSONObject(CustomAttributesMapper.customAttsToBackend(customAttributes)));
209
- }
210
- }
211
- }
212
- }