Skip to content

Commit 46c7370

Browse files
authored
Merge pull request #805 from Iterable/chore/223-android-realtimeupdate
[SDK-223] Android Realtime update
2 parents bdb25c5 + cf7eac4 commit 46c7370

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

android/src/main/java/com/iterable/reactnative/RNIterableAPIModuleImpl.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.iterable.iterableapi.IterableConfig;
3131
import com.iterable.iterableapi.IterableCustomActionHandler;
3232
import com.iterable.iterableapi.IterableEmbeddedMessage;
33+
import com.iterable.iterableapi.IterableEmbeddedUpdateHandler;
3334
import com.iterable.iterableapi.IterableHelper;
3435
import com.iterable.iterableapi.IterableInAppCloseAction;
3536
import com.iterable.iterableapi.IterableInAppHandler;
@@ -52,7 +53,7 @@
5253
import java.util.concurrent.CountDownLatch;
5354
import java.util.concurrent.TimeUnit;
5455

55-
public class RNIterableAPIModuleImpl implements IterableUrlHandler, IterableCustomActionHandler, IterableInAppHandler, IterableAuthHandler, IterableInAppManager.Listener {
56+
public class RNIterableAPIModuleImpl implements IterableUrlHandler, IterableCustomActionHandler, IterableInAppHandler, IterableAuthHandler, IterableInAppManager.Listener, IterableEmbeddedUpdateHandler {
5657
public static final String NAME = "RNIterableAPI";
5758

5859
private static String TAG = "RNIterableAPIModule";
@@ -92,6 +93,9 @@ public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, S
9293
configBuilder.setAuthHandler(this);
9394
}
9495

96+
// Check if embedded messaging is enabled before building config
97+
boolean enableEmbeddedMessaging = configReadableMap.hasKey("enableEmbeddedMessaging") && configReadableMap.getBoolean("enableEmbeddedMessaging");
98+
9599
IterableConfig config = configBuilder.build();
96100
IterableApi.initialize(reactContext, apiKey, config);
97101

@@ -127,6 +131,11 @@ public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, S
127131
IterableApi.getInstance().getInAppManager().addListener(this);
128132
IterableApi.getInstance().getEmbeddedManager().syncMessages();
129133

134+
// Add embedded update listener if embedded messaging is enabled
135+
if (enableEmbeddedMessaging) {
136+
IterableApi.getInstance().getEmbeddedManager().addUpdateListener(this);
137+
}
138+
130139
// MOB-10421: Figure out what the error cases are and handle them appropriately
131140
// This is just here to match the TS types and let the JS thread know when we are done initializing
132141
promise.resolve(true);
@@ -156,6 +165,9 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap,
156165
// override in the Android SDK. Check with @Ayyanchira and @evantk91 to
157166
// see what the best approach is.
158167

168+
// Check if embedded messaging is enabled before building config
169+
boolean enableEmbeddedMessaging = configReadableMap.hasKey("enableEmbeddedMessaging") && configReadableMap.getBoolean("enableEmbeddedMessaging");
170+
159171
IterableConfig config = configBuilder.build();
160172
IterableApi.initialize(reactContext, apiKey, config);
161173

@@ -191,6 +203,11 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap,
191203
IterableApi.getInstance().getInAppManager().addListener(this);
192204
IterableApi.getInstance().getEmbeddedManager().syncMessages();
193205

206+
// Add embedded update listener if embedded messaging is enabled
207+
if (enableEmbeddedMessaging) {
208+
IterableApi.getInstance().getEmbeddedManager().addUpdateListener(this);
209+
}
210+
194211
// MOB-10421: Figure out what the error cases are and handle them appropriately
195212
// This is just here to match the TS types and let the JS thread know when we are done initializing
196213
promise.resolve(true);
@@ -688,6 +705,18 @@ public void sendEvent(@NonNull String eventName, @Nullable Object eventData) {
688705
public void onInboxUpdated() {
689706
sendEvent(EventName.receivedIterableInboxChanged.name(), null);
690707
}
708+
709+
@Override
710+
public void onMessagesUpdated() {
711+
IterableLogger.d(TAG, "onMessagesUpdated");
712+
sendEvent(EventName.handleEmbeddedMessageUpdateCalled.name(), null);
713+
}
714+
715+
@Override
716+
public void onEmbeddedMessagingDisabled() {
717+
IterableLogger.d(TAG, "onEmbeddedMessagingDisabled");
718+
sendEvent(EventName.handleEmbeddedMessagingDisabledCalled.name(), null);
719+
}
691720
// ---------------------------------------------------------------------------------------
692721
// endregion
693722

@@ -773,6 +802,8 @@ enum EventName {
773802
handleAuthFailureCalled,
774803
handleAuthSuccessCalled,
775804
handleCustomActionCalled,
805+
handleEmbeddedMessageUpdateCalled,
806+
handleEmbeddedMessagingDisabledCalled,
776807
handleInAppCalled,
777808
handleUrlCalled,
778809
receivedIterableEmbeddedMessagesChanged,

0 commit comments

Comments
 (0)