infobip-mobile-messaging-react-native-plugin 13.11.0 → 13.11.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.
@@ -87,7 +87,7 @@ repositories {
87
87
  }
88
88
 
89
89
  dependencies {
90
- def mmVersion = '14.6.0'
90
+ def mmVersion = '14.6.2'
91
91
  //react and mm dependencies clash
92
92
  if (!overrideKotlinVersion.empty) {
93
93
  constraints {
@@ -4,6 +4,8 @@ import android.content.Context;
4
4
  import android.content.SharedPreferences;
5
5
  import android.preference.PreferenceManager;
6
6
 
7
+ import android.util.Log;
8
+
7
9
  import org.infobip.mobile.messaging.api.support.http.serialization.JsonSerializer;
8
10
  import org.infobip.mobile.messaging.dal.json.JSONArrayAdapter;
9
11
  import org.infobip.mobile.messaging.dal.json.JSONObjectAdapter;
@@ -39,17 +41,29 @@ class CacheManager {
39
41
  }
40
42
 
41
43
  static void saveEvent(Context context, String event, JSONObject object, String actionId, String actionInputText) {
44
+ if (context == null) {
45
+ Log.e(Utils.TAG, "context is null, can't cache event " + event);
46
+ return;
47
+ }
42
48
  String serialized = serializer.serialize(new Event(event, object, actionId, actionInputText));
43
49
  saveStringsToSet(context, EVENTS_KEY, serialized);
44
50
  }
45
51
 
46
52
  static void saveEvent(Context context, String event, int unreadMessagesCounter) {
53
+ if (context == null) {
54
+ Log.e(Utils.TAG, "context is null, can't cache event " + event);
55
+ return;
56
+ }
47
57
  //int `unreadMessagesCounter` isn't a JSONObject, so it'll go as a second argument
48
58
  String serialized = serializer.serialize(new Event(event, null, unreadMessagesCounter));
49
59
  saveStringsToSet(context, EVENTS_KEY, serialized);
50
60
  }
51
61
 
52
62
  static Event[] loadEvents(Context context, String eventType) {
63
+ if (context == null) {
64
+ Log.e(Utils.TAG, "context is null, can't load cached events " + eventType);
65
+ return new Event[0];
66
+ }
53
67
  Set<String> serialized = getStringSet(context, EVENTS_KEY);
54
68
  if (serialized == null || serialized.isEmpty()) {
55
69
  return new Event[0];
@@ -66,6 +66,10 @@ class ReactNativeEvent {
66
66
  if (eventName == null || map == null) {
67
67
  return;
68
68
  }
69
+ if (reactContext == null) {
70
+ Log.e(Utils.TAG, "reactContext is null, can't send event " + eventName);
71
+ return;
72
+ }
69
73
 
70
74
  reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, map);
71
75
  }
@@ -74,6 +78,10 @@ class ReactNativeEvent {
74
78
  if (eventName == null || array == null) {
75
79
  return;
76
80
  }
81
+ if (reactContext == null) {
82
+ Log.e(Utils.TAG, "reactContext is null, can't send event " + eventName);
83
+ return;
84
+ }
77
85
 
78
86
  reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, array);
79
87
  }
@@ -82,6 +90,10 @@ class ReactNativeEvent {
82
90
  if (eventName == null) {
83
91
  return;
84
92
  }
93
+ if (reactContext == null) {
94
+ Log.e(Utils.TAG, "reactContext is null, can't send event " + eventName);
95
+ return;
96
+ }
85
97
  reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, null);
86
98
  }
87
99
 
@@ -155,22 +155,6 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
155
155
  // Keep: Required for RN built in Event Emitter Calls.
156
156
  }
157
157
 
158
- private static void emitOrCache(String eventType, ReactContext reactContext, JSONObject message, String actionId, String actionInputText) {
159
- if (jsHasListeners) {
160
- ReactNativeEvent.send(eventType, reactContext, message, actionId, actionInputText);
161
- } else {
162
- CacheManager.saveEvent(reactContext, eventType, message, actionId, actionInputText);
163
- }
164
- }
165
-
166
- private static void emitOrCache(String eventType, ReactContext reactContext, int unreadMessagesCounter) {
167
- if (jsHasListeners) {
168
- ReactNativeEvent.send(eventType, reactContext, unreadMessagesCounter);
169
- } else {
170
- CacheManager.saveEvent(reactContext, eventType, unreadMessagesCounter);
171
- }
172
- }
173
-
174
158
  //region BroadcastReceivers
175
159
  //region Events
176
160
  private static final String EVENT_TOKEN_RECEIVED = "tokenReceived";
@@ -191,7 +175,6 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
191
175
  private static final String EVENT_INAPPCHAT_AVAILABILITY_UPDATED = "inAppChat.availabilityUpdated";
192
176
  //endregion
193
177
 
194
-
195
178
  //region MessageStorageBroadcastReceiver
196
179
  private static final Map<String, String> messageStorageEventMap = new HashMap<String, String>() {{
197
180
  put(MessageStoreAdapter.EVENT_MESSAGESTORAGE_START, MessageStoreAdapter.EVENT_MESSAGESTORAGE_START);
@@ -237,7 +220,6 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
237
220
  //endregion
238
221
 
239
222
  //region MessageBroadcastReceiver
240
-
241
223
  /**
242
224
  * For event caching, if plugin not yet initialized
243
225
  */
@@ -279,7 +261,7 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
279
261
  if (!pluginInitialized) {
280
262
  CacheManager.saveEvent(context, event, message, actionId, actionInputText);
281
263
  } else {
282
- emitOrCache(event, getReactContext(context), message, actionId, actionInputText);
264
+ emitOrCache(event, context, message, actionId, actionInputText);
283
265
  }
284
266
  }
285
267
 
@@ -288,16 +270,43 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
288
270
  if (!pluginInitialized) {
289
271
  CacheManager.saveEvent(context, event, unreadChatMessagesCounter);
290
272
  } else {
291
- emitOrCache(event, getReactContext(context), unreadChatMessagesCounter);
273
+ emitOrCache(event, context, unreadChatMessagesCounter);
292
274
  }
293
275
  }
294
276
 
295
277
  @Nullable
296
278
  private ReactContext getReactContext(Context context) {
297
279
  ReactApplication reactApplication = (ReactApplication) context.getApplicationContext();
298
- if (reactApplication == null) return null;
280
+ if (reactApplication == null)
281
+ return null;
299
282
  return reactApplication.getReactNativeHost().getReactInstanceManager().getCurrentReactContext();
300
283
  }
284
+
285
+ private void emitOrCache(String eventType, Context context, JSONObject message, String actionId, String actionInputText) {
286
+ ReactContext reactContext = getReactContext(context);
287
+ if (jsHasListeners && reactContext != null) {
288
+ ReactNativeEvent.send(eventType, reactContext, message, actionId, actionInputText);
289
+ } else if (reactContext != null) {
290
+ CacheManager.saveEvent(reactContext, eventType, message, actionId, actionInputText);
291
+ } else if (context != null) {
292
+ CacheManager.saveEvent(context, eventType, message, actionId, actionInputText);
293
+ } else {
294
+ Log.e(Utils.TAG, "Both reactContext and androidContext are null, can't emit or cache event " + eventType);
295
+ }
296
+ }
297
+
298
+ private void emitOrCache(String eventType, Context context, int unreadMessagesCounter) {
299
+ ReactContext reactContext = getReactContext(context);
300
+ if (jsHasListeners && reactContext != null) {
301
+ ReactNativeEvent.send(eventType, reactContext, unreadMessagesCounter);
302
+ } else if (reactContext != null) {
303
+ CacheManager.saveEvent(reactContext, eventType, unreadMessagesCounter);
304
+ } else if (context != null) {
305
+ CacheManager.saveEvent(context, eventType, unreadMessagesCounter);
306
+ } else {
307
+ Log.e(Utils.TAG, "Both reactContext and androidContext are null, can't emit or cache event " + eventType);
308
+ }
309
+ }
301
310
  }
302
311
  //endregion
303
312
 
@@ -1,7 +1,7 @@
1
1
  require "json"
2
2
 
3
3
  package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
- mmVersion = "13.12.0"
4
+ mmVersion = "13.12.4"
5
5
 
6
6
  Pod::Spec.new do |s|
7
7
  s.name = "infobip-mobile-messaging-react-native-plugin"
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": "13.11.0",
4
+ "version": "13.11.2",
5
5
  "description": "Infobip Mobile Messaging React Native Plugin",
6
6
  "main": "./src/index.js",
7
7
  "scripts": {