-
Notifications
You must be signed in to change notification settings - Fork 42
[SDK-223] - Embedded Listener RN Android Bridge #801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: loren/embedded/master
Are you sure you want to change the base?
Conversation
|
Coverage Impact ⬇️ Merging this pull request will decrease total coverage on Modified Files with Diff Coverage (2)
🤖 Increase coverage with AI coding...🚦 See full report on Qlty Cloud » 🛟 Help
|
| * subscription.remove(); | ||
| * ``` | ||
| */ | ||
| addMessagesUpdatedListener(callback: () => void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should instead have onEmbeddedMessageUpdate and handle the unsubscribe function internally, as this is how we have done other listeners in the app.
We can then add this to the removeAllEventListeners function in Iterable.ts,
| IterableApi.getInstance().getEmbeddedManager().addUpdateListener(this); | ||
| IterableApi.getInstance().getEmbeddedManager().syncMessages(); | ||
|
|
||
| // 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); | ||
| } | ||
|
|
||
| public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap, String version, String apiEndPointOverride, Promise promise) { | ||
| IterableLogger.d(TAG, "initialize2WithApiKey: " + 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); | ||
| } | ||
|
|
||
| // 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. | ||
|
|
||
| IterableConfig config = configBuilder.build(); | ||
| IterableApi.initialize(reactContext, apiKey, config); | ||
|
|
||
| // Update retry policy on existing authManager if it was already created | ||
| // This fixes the issue where retryInterval is not respected after | ||
| // re-initialization | ||
| // TODO [SDK-197]: Fix the root cause of this issue, instead of this hack | ||
| try { | ||
| // Use reflection to access package-private fields and methods | ||
| java.lang.reflect.Field configRetryPolicyField = config.getClass().getDeclaredField("retryPolicy"); | ||
| configRetryPolicyField.setAccessible(true); | ||
| Object retryPolicy = configRetryPolicyField.get(config); | ||
|
|
||
| if (retryPolicy != null) { | ||
| java.lang.reflect.Method getAuthManagerMethod = IterableApi.getInstance().getClass().getDeclaredMethod("getAuthManager"); | ||
| getAuthManagerMethod.setAccessible(true); | ||
| IterableAuthManager authManager = (IterableAuthManager) getAuthManagerMethod.invoke(IterableApi.getInstance()); | ||
|
|
||
| if (authManager != null) { | ||
| // Update the retry policy field on the authManager | ||
| java.lang.reflect.Field authRetryPolicyField = authManager.getClass().getDeclaredField("authRetryPolicy"); | ||
| authRetryPolicyField.setAccessible(true); | ||
| authRetryPolicyField.set(authManager, retryPolicy); | ||
| IterableLogger.d(TAG, "Updated retry policy on existing authManager"); | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage()); | ||
| } | ||
|
|
||
| IterableApi.getInstance().setDeviceAttribute("reactNativeSDKVersion", version); | ||
|
|
||
| IterableApi.getInstance().getInAppManager().addListener(this); | ||
| IterableApi.getInstance().getEmbeddedManager().addUpdateListener(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These puts themselves as listeners to updateListener at bridge. This will bridge to receive callback when list of EmbeddedMessages change.
| @Override | ||
| public void onMessagesUpdated() { | ||
| IterableLogger.d(TAG, "onMessagesUpdated"); | ||
| sendEvent(EventName.receivedIterableEmbeddedMessagesChanged.name(), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the callback that should trigger the call on TS level indicating its time to check local messages as sync has been performed.
| @Override | ||
| public void onEmbeddedMessagingDisabled() { | ||
| IterableLogger.d(TAG, "onEmbeddedMessagingDisabled"); | ||
| sendEvent(EventName.receivedIterableEmbeddedMessagingDisabled.name(), null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During the sync, if native code recognize feature disablement, this callback will be invoked. sendEvent will then call method on EventName.receivedIterableEmbeddedMessagingDisabled. TS layer also needs to be there where TS layer have list of listener it calls to indicate this disabled feature notice.

🔹 JIRA Ticket(s) if any
✏️ Description