-
Notifications
You must be signed in to change notification settings - Fork 33
/
RNIterableAPIModule.java
651 lines (539 loc) · 25 KB
/
RNIterableAPIModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
package com.iterable.reactnative;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
import com.iterable.iterableapi.InboxSessionManager;
import com.iterable.iterableapi.IterableAction;
import com.iterable.iterableapi.IterableActionContext;
import com.iterable.iterableapi.IterableApi;
import com.iterable.iterableapi.IterableAuthHandler;
import com.iterable.iterableapi.IterableConfig;
import com.iterable.iterableapi.IterableCustomActionHandler;
import com.iterable.iterableapi.IterableAttributionInfo;
import com.iterable.iterableapi.IterableHelper;
import com.iterable.iterableapi.IterableInAppCloseAction;
import com.iterable.iterableapi.IterableInAppHandler;
import com.iterable.iterableapi.IterableInAppLocation;
import com.iterable.iterableapi.IterableInAppManager;
import com.iterable.iterableapi.IterableInAppMessage;
import com.iterable.iterableapi.IterableInboxSession;
import com.iterable.iterableapi.IterableLogger;
import com.iterable.iterableapi.IterableUrlHandler;
import com.iterable.iterableapi.RNIterableInternal;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class RNIterableAPIModule extends ReactContextBaseJavaModule implements IterableUrlHandler, IterableCustomActionHandler, IterableInAppHandler, IterableAuthHandler, IterableInAppManager.Listener {
private final ReactApplicationContext reactContext;
private static String TAG = "RNIterableAPIModule";
private InAppResponse inAppResponse = InAppResponse.SHOW;
//A CountDownLatch. This helps decide whether to handle the in-app in Default way by waiting for JS to respond in runtime.
private CountDownLatch jsCallBackLatch;
private CountDownLatch authHandlerCallbackLatch;
private String passedAuthToken = null;
private final InboxSessionManager sessionManager = new InboxSessionManager();
public RNIterableAPIModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}
// ---------------------------------------------------------------------------------------
// region IterableSDK calls
@Override
public String getName() {
return "RNIterableAPI";
}
@ReactMethod
public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, String version, Promise promise) {
IterableLogger.d(TAG, "initializeWithApiKey: " + apiKey);
IterableConfig.Builder configBuilder = Serialization.getConfigFromReadableMap(configReadableMap);
if (configReadableMap.hasKey("urlHandlerPresent") && configReadableMap.getBoolean("urlHandlerPresent") == true) {
configBuilder.setUrlHandler(this);
}
if (configReadableMap.hasKey("customActionHandlerPresent") && configReadableMap.getBoolean("customActionHandlerPresent") == true) {
configBuilder.setCustomActionHandler(this);
}
if (configReadableMap.hasKey("inAppHandlerPresent") && configReadableMap.getBoolean("inAppHandlerPresent") == true) {
configBuilder.setInAppHandler(this);
}
if (configReadableMap.hasKey("authHandlerPresent") && configReadableMap.getBoolean("authHandlerPresent") == true) {
configBuilder.setAuthHandler(this);
}
IterableApi.initialize(reactContext, apiKey, configBuilder.build());
IterableApi.getInstance().setDeviceAttribute("reactNativeSDKVersion", version);
IterableApi.getInstance().getInAppManager().addListener(this);
// TODO: Figure out what the error cases are and handle them appropriately
// This is just here to match the TS types and let the JS thread know when we are done initializing
promise.resolve(true);
}
@ReactMethod
public void setEmail(@Nullable String email) {
IterableLogger.d(TAG, "setEmail: " + email);
IterableApi.getInstance().setEmail(email);
}
@ReactMethod
public void setEmail(@Nullable String email, @Nullable String authToken) {
IterableLogger.d(TAG, "setEmail: " + email + " authToken: " + authToken);
IterableApi.getInstance().setEmail(email, authToken);
}
@ReactMethod
public void updateEmail(String email) {
IterableLogger.d(TAG, "updateEmail: " + email);
IterableApi.getInstance().updateEmail(email);
}
@ReactMethod
public void updateEmail(String email, @Nullable String authToken) {
IterableLogger.d(TAG, "updateEmail: " + email + " authToken: " + authToken);
IterableApi.getInstance().updateEmail(email, authToken);
}
@ReactMethod
public void getEmail(Promise promise) {
promise.resolve(RNIterableInternal.getEmail());
}
@ReactMethod
public void sampleMethod(String stringArgument, int numberArgument, Callback callback) {
// TODO: Implement some actually useful functionality
callback.invoke("Received numberArgument: " + numberArgument + " stringArgument: " + stringArgument);
}
@ReactMethod
public void setUserId(@Nullable String userId) {
IterableLogger.d(TAG, "setUserId: " + userId);
IterableApi.getInstance().setUserId(userId);
}
@ReactMethod
public void setUserId(@Nullable String userId, @Nullable String authToken) {
IterableLogger.d(TAG, "setUserId: " + userId + " authToken: " + authToken);
IterableApi.getInstance().setUserId(userId, authToken);
}
@ReactMethod
public void updateUser(ReadableMap dataFields, Boolean mergeNestedObjects) {
IterableLogger.v(TAG, "updateUser");
IterableApi.getInstance().updateUser(optSerializedDataFields(dataFields), mergeNestedObjects);
}
@ReactMethod
public void getUserId(Promise promise) {
promise.resolve(RNIterableInternal.getUserId());
}
@ReactMethod
public void trackEvent(String name, ReadableMap dataFields) {
IterableLogger.v(TAG, "trackEvent");
IterableApi.getInstance().track(name, optSerializedDataFields(dataFields));
}
@ReactMethod
public void updateCart(ReadableArray items) {
IterableLogger.v(TAG, "updateCart");
IterableApi.getInstance().updateCart(Serialization.commerceItemsFromReadableArray(items));
}
@ReactMethod
public void trackPurchase(Double total, ReadableArray items, ReadableMap dataFields) {
IterableLogger.v(TAG, "trackPurchase");
IterableApi.getInstance().trackPurchase(total, Serialization.commerceItemsFromReadableArray(items), optSerializedDataFields(dataFields));
}
@ReactMethod
public void trackPushOpenWithCampaignId(Integer campaignId, Integer templateId, String messageId, Boolean appAlreadyRunning, ReadableMap dataFields) {
RNIterableInternal.trackPushOpenWithCampaignId(campaignId, templateId, messageId, optSerializedDataFields(dataFields));
}
@ReactMethod
public void updateSubscriptions(ReadableArray emailListIds, ReadableArray unsubscribedChannelIds, ReadableArray unsubscribedMessageTypeIds, ReadableArray subscribedMessageTypeIds, Integer campaignId, Integer templateId) {
IterableLogger.v(TAG, "updateSubscriptions");
Integer finalCampaignId = null, finalTemplateId = null;
if (campaignId > 0) {
finalCampaignId = campaignId;
}
if (templateId > 0) {
finalTemplateId = templateId;
}
IterableApi.getInstance().updateSubscriptions(readableArrayToIntegerArray(emailListIds),
readableArrayToIntegerArray(unsubscribedChannelIds),
readableArrayToIntegerArray(unsubscribedMessageTypeIds),
readableArrayToIntegerArray(subscribedMessageTypeIds),
finalCampaignId,
finalTemplateId
);
}
@ReactMethod
public void showMessage(String messageId, boolean consume, final Promise promise) {
if (messageId == null || messageId == "") {
promise.reject("", "messageId is null or empty");
return;
}
IterableApi.getInstance().getInAppManager().showMessage(RNIterableInternal.getMessageById(messageId), consume, new IterableHelper.IterableUrlCallback() {
@Override
public void execute(@Nullable Uri url) {
promise.resolve(url.toString());
}
});
}
@ReactMethod
public void setReadForMessage(String messageId, boolean read) {
IterableLogger.v(TAG, "setReadForMessage");
IterableApi.getInstance().getInAppManager().setRead(RNIterableInternal.getMessageById(messageId), read);
}
@ReactMethod
public void removeMessage(String messageId, Integer location, Integer deleteSource) {
IterableLogger.v(TAG, "removeMessage");
IterableApi.getInstance().getInAppManager().removeMessage(RNIterableInternal.getMessageById(messageId), Serialization.getIterableDeleteActionTypeFromInteger(deleteSource), Serialization.getIterableInAppLocationFromInteger(location));
}
@ReactMethod
public void getHtmlInAppContentForMessage(String messageId, final Promise promise) {
IterableLogger.printInfo();
IterableInAppMessage message = RNIterableInternal.getMessageById(messageId);
if (message == null) {
promise.reject("", "Could not find message with id: " + messageId);
return;
}
JSONObject messageContent = Serialization.messageContentToJsonObject(message.getContent());
if (messageContent == null) {
promise.reject("", "messageContent is null for message id: " + messageId);
return;
}
try {
promise.resolve(Serialization.convertJsonToMap(messageContent));
} catch (JSONException e) {
promise.reject("", "Failed to convert JSONObject to ReadableMap");
}
}
@ReactMethod
public void getAttributionInfo(Promise promise) {
IterableLogger.printInfo();
IterableAttributionInfo attributionInfo = IterableApi.getInstance().getAttributionInfo();
if (attributionInfo != null) {
try {
promise.resolve(Serialization.convertJsonToMap(attributionInfo.toJSONObject()));
} catch (JSONException e) {
IterableLogger.e(TAG, "Failed converting attribution info to JSONObject");
promise.reject("", "Failed to convert AttributionInfo to ReadableMap");
}
} else {
promise.resolve(null);
}
}
@ReactMethod
public void setAttributionInfo(ReadableMap attributionInfoReadableMap) {
IterableLogger.printInfo();
try {
JSONObject attributionInfoJson = Serialization.convertMapToJson(attributionInfoReadableMap);
IterableAttributionInfo attributionInfo = IterableAttributionInfo.fromJSONObject(attributionInfoJson);
RNIterableInternal.setAttributionInfo(attributionInfo);
} catch (JSONException e) {
IterableLogger.e(TAG, "Failed converting ReadableMap to JSON");
}
}
@ReactMethod
public void getLastPushPayload(Promise promise) {
Bundle payloadData = IterableApi.getInstance().getPayloadData();
if (payloadData != null) {
promise.resolve(Arguments.fromBundle(IterableApi.getInstance().getPayloadData()));
} else {
IterableLogger.d(TAG, "No payload data found");
promise.resolve(null);
}
}
@ReactMethod
public void disableDeviceForCurrentUser() {
IterableLogger.v(TAG, "disableDevice");
IterableApi.getInstance().disablePush();
}
@ReactMethod
public void handleAppLink(String uri, Promise promise) {
IterableLogger.printInfo();
promise.resolve(IterableApi.getInstance().handleAppLink(uri));
}
// ---------------------------------------------------------------------------------------
// endregion
// ---------------------------------------------------------------------------------------
// region Track APIs
@ReactMethod
public void trackInAppOpen(String messageId, @Nullable Integer location) {
IterableInAppMessage message = RNIterableInternal.getMessageById(messageId);
if (message == null) {
IterableLogger.d(TAG, "Failed to get in-app for message ID: " + messageId);
return;
}
IterableApi.getInstance().trackInAppOpen(message, Serialization.getIterableInAppLocationFromInteger(location));
}
@ReactMethod
public void trackInAppClick(String messageId, @Nullable Integer location, String clickedUrl) {
IterableInAppMessage message = RNIterableInternal.getMessageById(messageId);
IterableInAppLocation inAppOpenLocation = Serialization.getIterableInAppLocationFromInteger(location);
if (message == null) {
IterableLogger.d(TAG, "Failed to get in-app for message ID: " + messageId);
return;
}
if (clickedUrl == null) {
IterableLogger.d(TAG, "clickedUrl is null");
return;
}
if (inAppOpenLocation == null) {
IterableLogger.d(TAG, "in-app open location is null");
return;
}
IterableApi.getInstance().trackInAppClick(message, clickedUrl, inAppOpenLocation);
}
@ReactMethod
public void trackInAppClose(String messageId, Integer location, Integer source, @Nullable String clickedUrl) {
IterableInAppMessage inAppMessage = RNIterableInternal.getMessageById(messageId);
IterableInAppLocation inAppCloseLocation = Serialization.getIterableInAppLocationFromInteger(location);
IterableInAppCloseAction closeAction = Serialization.getIterableInAppCloseSourceFromInteger(source);
if (inAppMessage == null) {
IterableLogger.d(TAG, "Failed to get in-app for message ID: " + messageId);
return;
}
if (inAppCloseLocation == null) {
IterableLogger.d(TAG, "in-app close location is null");
return;
}
if (closeAction == null) {
IterableLogger.d(TAG, "in-app close action is null");
return;
}
IterableApi.getInstance().trackInAppClose(inAppMessage, clickedUrl, closeAction, inAppCloseLocation);
}
// ---------------------------------------------------------------------------------------
// endregion
// ---------------------------------------------------------------------------------------
// region In App APIs
@ReactMethod
public void inAppConsume(String messageId, Integer location, Integer source) {
if (messageId == null) {
return;
}
IterableApi.getInstance().inAppConsume(RNIterableInternal.getMessageById(messageId), Serialization.getIterableDeleteActionTypeFromInteger(source), Serialization.getIterableInAppLocationFromInteger(location));
}
@ReactMethod
public void getInAppMessages(Promise promise) {
IterableLogger.d(TAG, "getMessages");
try {
JSONArray inAppMessageJsonArray = Serialization.serializeInAppMessages(IterableApi.getInstance().getInAppManager().getMessages());
promise.resolve(Serialization.convertJsonToArray(inAppMessageJsonArray));
} catch (JSONException e) {
IterableLogger.e(TAG, e.getLocalizedMessage());
promise.reject("", "Failed to fetch messages with error " + e.getLocalizedMessage());
}
}
@ReactMethod
public void getInboxMessages(Promise promise) {
IterableLogger.d(TAG, "getInboxMessages");
try {
JSONArray inboxMessageJsonArray = Serialization.serializeInAppMessages(IterableApi.getInstance().getInAppManager().getInboxMessages());
promise.resolve(Serialization.convertJsonToArray(inboxMessageJsonArray));
} catch (JSONException e) {
IterableLogger.e(TAG, e.getLocalizedMessage());
promise.reject("", "Failed to fetch messages with error " + e.getLocalizedMessage());
}
}
@ReactMethod
public void setInAppShowResponse(Integer number) {
IterableLogger.printInfo();
inAppResponse = Serialization.getInAppResponse(number);
if (jsCallBackLatch != null) {
jsCallBackLatch.countDown();
}
}
@ReactMethod
public void setAutoDisplayPaused(final boolean paused) {
IterableLogger.printInfo();
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
IterableApi.getInstance().getInAppManager().setAutoDisplayPaused(paused);
}
});
}
@ReactMethod
public void wakeApp() {
Intent launcherIntent = getMainActivityIntent(reactContext);
launcherIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
if (launcherIntent.resolveActivity(reactContext.getPackageManager()) != null) {
reactContext.startActivity(launcherIntent);
}
}
public Intent getMainActivityIntent(Context context) {
Context appContext = context.getApplicationContext();
PackageManager packageManager = appContext.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(appContext.getPackageName());
if (intent == null) {
intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setPackage(appContext.getPackageName());
}
return intent;
}
// ---------------------------------------------------------------------------------------
// endregion
// ---------------------------------------------------------------------------------------
// region Inbox In-App Session Tracking APIs
@ReactMethod
public void startSession(ReadableArray visibleRows) {
List<IterableInboxSession.Impression> serializedRows = Serialization.impressionsFromReadableArray(visibleRows);
sessionManager.startSession(serializedRows);
}
@ReactMethod
public void endSession() {
sessionManager.endSession();
}
@ReactMethod
public void updateVisibleRows(ReadableArray visibleRows) {
List<IterableInboxSession.Impression> serializedRows = Serialization.impressionsFromReadableArray(visibleRows);
sessionManager.updateVisibleRows(serializedRows);
}
// ---------------------------------------------------------------------------------------
// endregion
// ---------------------------------------------------------------------------------------
// region Private Serialization Functions
private static Integer[] readableArrayToIntegerArray(ReadableArray array) {
if (array == null) {
return null;
}
Integer[] integers = new Integer[array.size()];
for (int i = 0; i < array.size(); i++) {
integers[i] = array.getInt(i);
}
return integers;
}
@Nullable
private static JSONObject optSerializedDataFields(ReadableMap dataFields) {
JSONObject dataFieldsJson = null;
if (dataFields != null) {
try {
dataFieldsJson = Serialization.convertMapToJson(dataFields);
} catch (JSONException e) {
IterableLogger.d(TAG, "Failed to convert dataFields to JSON");
}
}
return dataFieldsJson;
}
// ---------------------------------------------------------------------------------------
// endregion
// ---------------------------------------------------------------------------------------
// region IterableSDK callbacks
@Override
public boolean handleIterableCustomAction(@NonNull IterableAction action, @NonNull IterableActionContext actionContext) {
IterableLogger.printInfo();
JSONObject actionJson = Serialization.actionToJson(action);
JSONObject actionContextJson = Serialization.actionContextToJson(actionContext);
JSONObject eventDataJson = new JSONObject();
try {
eventDataJson.put("action", actionJson);
eventDataJson.put("context", actionContextJson);
WritableMap eventData = Serialization.convertJsonToMap(eventDataJson);
sendEvent(EventName.handleCustomActionCalled.name(), eventData);
} catch (JSONException e) {
IterableLogger.e(TAG, "Failed handling custom action");
}
// The Android SDK will not bring the app into focus is this is `true`. It still respects the `openApp` bool flag.
return false;
}
@NonNull
@Override
public InAppResponse onNewInApp(@NonNull IterableInAppMessage message) {
IterableLogger.printInfo();
JSONObject messageJson = RNIterableInternal.getInAppMessageJson(message);
try {
WritableMap eventData = Serialization.convertJsonToMap(messageJson);
jsCallBackLatch = new CountDownLatch(1);
sendEvent(EventName.handleInAppCalled.name(), eventData);
jsCallBackLatch.await(2, TimeUnit.SECONDS);
jsCallBackLatch = null;
return inAppResponse;
} catch (InterruptedException | JSONException e) {
IterableLogger.e(TAG, "new in-app module failed");
return InAppResponse.SHOW;
}
}
@Override
public boolean handleIterableURL(@NonNull Uri uri, @NonNull IterableActionContext actionContext) {
IterableLogger.printInfo();
JSONObject actionContextJson = Serialization.actionContextToJson(actionContext);
JSONObject eventDataJson = new JSONObject();
try {
eventDataJson.put("url", uri.toString());
eventDataJson.put("context", actionContextJson);
WritableMap eventData = Serialization.convertJsonToMap(eventDataJson);
sendEvent(EventName.handleUrlCalled.name(), eventData);
} catch (JSONException e) {
IterableLogger.e(TAG, e.getLocalizedMessage());
}
return true;
}
@Override
public String onAuthTokenRequested() {
IterableLogger.printInfo();
try {
authHandlerCallbackLatch = new CountDownLatch(1);
sendEvent(EventName.handleAuthCalled.name(), null);
authHandlerCallbackLatch.await(30, TimeUnit.SECONDS);
authHandlerCallbackLatch = null;
return passedAuthToken;
} catch (InterruptedException e) {
IterableLogger.e(TAG, "auth handler module failed");
return null;
}
}
@Override
public void onTokenRegistrationSuccessful(String authToken) {
IterableLogger.v(TAG, "authToken successfully set");
//TODO: Pass successhandler to event listener
sendEvent(EventName.handleAuthSuccessCalled.name(), null);
}
@Override
public void onTokenRegistrationFailed(Throwable object) {
IterableLogger.v(TAG, "Failed to set authToken");
sendEvent(EventName.handleAuthFailureCalled.name(), null);
}
@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
}
@ReactMethod
public void removeListeners(Integer count) {
// Keep: Required for RN built in Event Emitter Calls.
}
// ---------------------------------------------------------------------------------------
// endregion
// ---------------------------------------------------------------------------------------
// region Misc Bridge Functions
@ReactMethod
public void passAlongAuthToken(String authToken) {
passedAuthToken = authToken;
if (authHandlerCallbackLatch != null) {
authHandlerCallbackLatch.countDown();
}
}
public void sendEvent(@NonNull String eventName, @Nullable Object eventData) {
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, eventData);
}
@Override
public void onInboxUpdated() {
sendEvent(EventName.receivedIterableInboxChanged.name(), null);
}
// ---------------------------------------------------------------------------------------
// endregion
}
enum EventName {
handleUrlCalled,
handleCustomActionCalled,
handleInAppCalled,
handleAuthCalled,
receivedIterableInboxChanged,
handleAuthSuccessCalled,
handleAuthFailureCalled
}