Skip to content
Closed
Show file tree
Hide file tree
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 @@ -69,6 +69,8 @@ public class RNIterableAPIModuleImpl implements IterableUrlHandler, IterableCust

private final InboxSessionManager sessionManager = new InboxSessionManager();

private boolean pushOpenHandlerPresent = false;

public RNIterableAPIModuleImpl(ReactApplicationContext reactContext) {
this.reactContext = reactContext;
}
Expand All @@ -93,6 +95,8 @@ public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, S
configBuilder.setAuthHandler(this);
}

pushOpenHandlerPresent = configReadableMap.hasKey("pushOpenHandlerPresent") && configReadableMap.getBoolean("pushOpenHandlerPresent");

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

Expand Down Expand Up @@ -136,6 +140,9 @@ public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, S
IterableApi.getInstance().getEmbeddedManager().addUpdateListener(this);
}

// Emit push open event for cold-start push opens
emitPushOpenIfPresent();

// 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 All @@ -161,6 +168,8 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap,
configBuilder.setAuthHandler(this);
}

pushOpenHandlerPresent = configReadableMap.hasKey("pushOpenHandlerPresent") && configReadableMap.getBoolean("pushOpenHandlerPresent");

// NOTE: There does not seem to be a way to set the API endpoint
// override in the Android SDK. Check with @Ayyanchira and @evantk91 to
// see what the best approach is.
Expand Down Expand Up @@ -208,6 +217,9 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap,
IterableApi.getInstance().getEmbeddedManager().addUpdateListener(this);
}

// Emit push open event for cold-start push opens
emitPushOpenIfPresent();

// 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 @@ -596,6 +608,12 @@ public boolean handleIterableCustomAction(@NonNull IterableAction action, @NonNu
} catch (JSONException e) {
IterableLogger.e(TAG, "Failed handling custom action");
}

// Also emit push open event when the custom action originated from a push notification
if (pushOpenHandlerPresent && actionContext.source.ordinal() == 0 /* PUSH */) {
emitPushOpenIfPresent();
}

// The Android SDK will not bring the app into focus is this is `true`. It still respects the `openApp` bool flag.
return false;
}
Expand Down Expand Up @@ -635,6 +653,12 @@ public boolean handleIterableURL(@NonNull Uri uri, @NonNull IterableActionContex
} catch (JSONException e) {
IterableLogger.e(TAG, e.getLocalizedMessage());
}

// Also emit push open event when the URL action originated from a push notification
if (pushOpenHandlerPresent && actionContext.source.ordinal() == 0 /* PUSH */) {
emitPushOpenIfPresent();
}

return true;
}

Expand Down Expand Up @@ -701,6 +725,18 @@ public void sendEvent(@NonNull String eventName, @Nullable Object eventData) {
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, eventData);
}

private void emitPushOpenIfPresent() {
if (!pushOpenHandlerPresent) {
return;
}
Bundle payloadData = IterableApi.getInstance().getPayloadData();
if (payloadData != null) {
WritableMap eventData = Arguments.createMap();
eventData.putMap("pushPayload", Arguments.fromBundle(payloadData));
sendEvent(EventName.handlePushOpenCalled.name(), eventData);
}
}

@Override
public void onInboxUpdated() {
sendEvent(EventName.receivedIterableInboxChanged.name(), null);
Expand Down Expand Up @@ -809,6 +845,7 @@ enum EventName {
handleEmbeddedMessageUpdateCalled,
handleEmbeddedMessagingDisabledCalled,
handleInAppCalled,
handlePushOpenCalled,
handleUrlCalled,
receivedIterableEmbeddedMessagesChanged,
receivedIterableInboxChanged
Expand Down
32 changes: 30 additions & 2 deletions ios/RNIterableAPI/ReactIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import React
case handleAuthFailureCalled
case handleEmbeddedMessageUpdateCalled
case handleEmbeddedMessagingDisabledCalled
case handlePushOpenCalled
}

@objc public static var supportedEvents: [String] {
Expand Down Expand Up @@ -599,6 +600,8 @@ import React

private let inboxSessionManager = InboxSessionManager()

private var pushOpenHandlerPresent = false

@objc func initialize(
withApiKey apiKey: String,
config configDict: NSDictionary,
Expand Down Expand Up @@ -644,6 +647,8 @@ import React
self, selector: #selector(receivedIterableInboxChanged),
name: Notification.Name.iterableInboxChanged, object: nil)

self.pushOpenHandlerPresent = configDict["pushOpenHandlerPresent"] as? Bool ?? false

DispatchQueue.main.async {
IterableAPI.initialize2(
apiKey: apiKey,
Expand All @@ -655,14 +660,21 @@ import React
}

IterableAPI.setDeviceAttribute(name: "reactNativeSDKVersion", value: version)

// Add embedded update listener if any callback is present
let onEmbeddedMessageUpdatePresent = configDict["onEmbeddedMessageUpdatePresent"] as? Bool ?? false
let onEmbeddedMessagingDisabledPresent = configDict["onEmbeddedMessagingDisabledPresent"] as? Bool ?? false

if onEmbeddedMessageUpdatePresent || onEmbeddedMessagingDisabledPresent {
IterableAPI.embeddedManager.addUpdateListener(self)
}

// Emit push open event for cold-start push opens
if self.pushOpenHandlerPresent, let pushPayload = IterableAPI.lastPushPayload {
self.delegate?.sendEvent(
withName: EventName.handlePushOpenCalled.rawValue,
body: ["pushPayload": pushPayload])
}
}
}

Expand Down Expand Up @@ -710,6 +722,14 @@ extension ReactIterableAPI: IterableURLDelegate {
"url": url.absoluteString,
"context": contextDict,
] as [String: Any])

// Also emit push open event when the URL action originated from a push notification
if pushOpenHandlerPresent && context.source == .push {
let pushPayload = IterableAPI.lastPushPayload ?? [:]
delegate?.sendEvent(
withName: EventName.handlePushOpenCalled.rawValue,
body: ["pushPayload": pushPayload])
}
return true
}

Expand Down Expand Up @@ -749,6 +769,14 @@ extension ReactIterableAPI: IterableCustomActionDelegate {
"action": actionDict,
"context": contextDict,
])

// Also emit push open event when the custom action originated from a push notification
if pushOpenHandlerPresent && context.source == .push {
let pushPayload = IterableAPI.lastPushPayload ?? [:]
delegate?.sendEvent(
withName: EventName.handlePushOpenCalled.rawValue,
body: ["pushPayload": pushPayload])
}
return true
}
}
Expand Down
Loading
Loading