Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.iterable.iterableapi.IterableConfig;
import com.iterable.iterableapi.IterableCustomActionHandler;
import com.iterable.iterableapi.IterableEmbeddedMessage;
import com.iterable.iterableapi.IterableEmbeddedUpdateHandler;
import com.iterable.iterableapi.IterableHelper;
import com.iterable.iterableapi.IterableInAppCloseAction;
import com.iterable.iterableapi.IterableInAppHandler;
Expand All @@ -52,7 +53,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class RNIterableAPIModuleImpl implements IterableUrlHandler, IterableCustomActionHandler, IterableInAppHandler, IterableAuthHandler, IterableInAppManager.Listener {
public class RNIterableAPIModuleImpl implements IterableUrlHandler, IterableCustomActionHandler, IterableInAppHandler, IterableAuthHandler, IterableInAppManager.Listener, IterableEmbeddedUpdateHandler {
public static final String NAME = "RNIterableAPI";

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

// Check if embedded messaging is enabled before building config
boolean enableEmbeddedMessaging = configReadableMap.hasKey("enableEmbeddedMessaging") && configReadableMap.getBoolean("enableEmbeddedMessaging");

IterableConfig config = configBuilder.build();
IterableApi.initialize(reactContext, apiKey, config);

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

// Add embedded update listener if embedded messaging is enabled
if (enableEmbeddedMessaging) {
IterableApi.getInstance().getEmbeddedManager().addUpdateListener(this);
}

// MOB-10421: 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);
Expand Down Expand Up @@ -156,6 +165,9 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap,
// override in the Android SDK. Check with @Ayyanchira and @evantk91 to
// see what the best approach is.

// Check if embedded messaging is enabled before building config
boolean enableEmbeddedMessaging = configReadableMap.hasKey("enableEmbeddedMessaging") && configReadableMap.getBoolean("enableEmbeddedMessaging");

IterableConfig config = configBuilder.build();
IterableApi.initialize(reactContext, apiKey, config);

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

// Add embedded update listener if embedded messaging is enabled
if (enableEmbeddedMessaging) {
IterableApi.getInstance().getEmbeddedManager().addUpdateListener(this);
}

// MOB-10421: 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);
Expand Down Expand Up @@ -688,6 +705,18 @@ public void sendEvent(@NonNull String eventName, @Nullable Object eventData) {
public void onInboxUpdated() {
sendEvent(EventName.receivedIterableInboxChanged.name(), null);
}

@Override
public void onMessagesUpdated() {
IterableLogger.d(TAG, "onMessagesUpdated");
sendEvent(EventName.handleEmbeddedMessageUpdateCalled.name(), null);
}

@Override
public void onEmbeddedMessagingDisabled() {
IterableLogger.d(TAG, "onEmbeddedMessagingDisabled");
sendEvent(EventName.handleEmbeddedMessagingDisabledCalled.name(), null);
}
// ---------------------------------------------------------------------------------------
// endregion

Expand Down Expand Up @@ -773,6 +802,8 @@ enum EventName {
handleAuthFailureCalled,
handleAuthSuccessCalled,
handleCustomActionCalled,
handleEmbeddedMessageUpdateCalled,
handleEmbeddedMessagingDisabledCalled,
handleInAppCalled,
handleUrlCalled,
receivedIterableEmbeddedMessagesChanged,
Expand Down
Loading