|
30 | 30 | import com.iterable.iterableapi.IterableConfig; |
31 | 31 | import com.iterable.iterableapi.IterableCustomActionHandler; |
32 | 32 | import com.iterable.iterableapi.IterableEmbeddedMessage; |
| 33 | +import com.iterable.iterableapi.IterableEmbeddedUpdateHandler; |
33 | 34 | import com.iterable.iterableapi.IterableHelper; |
34 | 35 | import com.iterable.iterableapi.IterableInAppCloseAction; |
35 | 36 | import com.iterable.iterableapi.IterableInAppHandler; |
|
52 | 53 | import java.util.concurrent.CountDownLatch; |
53 | 54 | import java.util.concurrent.TimeUnit; |
54 | 55 |
|
55 | | -public class RNIterableAPIModuleImpl implements IterableUrlHandler, IterableCustomActionHandler, IterableInAppHandler, IterableAuthHandler, IterableInAppManager.Listener { |
| 56 | +public class RNIterableAPIModuleImpl implements IterableUrlHandler, IterableCustomActionHandler, IterableInAppHandler, IterableAuthHandler, IterableInAppManager.Listener, IterableEmbeddedUpdateHandler { |
56 | 57 | public static final String NAME = "RNIterableAPI"; |
57 | 58 |
|
58 | 59 | private static String TAG = "RNIterableAPIModule"; |
@@ -92,6 +93,9 @@ public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, S |
92 | 93 | configBuilder.setAuthHandler(this); |
93 | 94 | } |
94 | 95 |
|
| 96 | + // Check if embedded messaging is enabled before building config |
| 97 | + boolean enableEmbeddedMessaging = configReadableMap.hasKey("enableEmbeddedMessaging") && configReadableMap.getBoolean("enableEmbeddedMessaging"); |
| 98 | + |
95 | 99 | IterableConfig config = configBuilder.build(); |
96 | 100 | IterableApi.initialize(reactContext, apiKey, config); |
97 | 101 |
|
@@ -127,6 +131,11 @@ public void initializeWithApiKey(String apiKey, ReadableMap configReadableMap, S |
127 | 131 | IterableApi.getInstance().getInAppManager().addListener(this); |
128 | 132 | IterableApi.getInstance().getEmbeddedManager().syncMessages(); |
129 | 133 |
|
| 134 | + // Add embedded update listener if embedded messaging is enabled |
| 135 | + if (enableEmbeddedMessaging) { |
| 136 | + IterableApi.getInstance().getEmbeddedManager().addUpdateListener(this); |
| 137 | + } |
| 138 | + |
130 | 139 | // MOB-10421: Figure out what the error cases are and handle them appropriately |
131 | 140 | // This is just here to match the TS types and let the JS thread know when we are done initializing |
132 | 141 | promise.resolve(true); |
@@ -156,6 +165,9 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap, |
156 | 165 | // override in the Android SDK. Check with @Ayyanchira and @evantk91 to |
157 | 166 | // see what the best approach is. |
158 | 167 |
|
| 168 | + // Check if embedded messaging is enabled before building config |
| 169 | + boolean enableEmbeddedMessaging = configReadableMap.hasKey("enableEmbeddedMessaging") && configReadableMap.getBoolean("enableEmbeddedMessaging"); |
| 170 | + |
159 | 171 | IterableConfig config = configBuilder.build(); |
160 | 172 | IterableApi.initialize(reactContext, apiKey, config); |
161 | 173 |
|
@@ -191,6 +203,11 @@ public void initialize2WithApiKey(String apiKey, ReadableMap configReadableMap, |
191 | 203 | IterableApi.getInstance().getInAppManager().addListener(this); |
192 | 204 | IterableApi.getInstance().getEmbeddedManager().syncMessages(); |
193 | 205 |
|
| 206 | + // Add embedded update listener if embedded messaging is enabled |
| 207 | + if (enableEmbeddedMessaging) { |
| 208 | + IterableApi.getInstance().getEmbeddedManager().addUpdateListener(this); |
| 209 | + } |
| 210 | + |
194 | 211 | // MOB-10421: Figure out what the error cases are and handle them appropriately |
195 | 212 | // This is just here to match the TS types and let the JS thread know when we are done initializing |
196 | 213 | promise.resolve(true); |
@@ -688,6 +705,18 @@ public void sendEvent(@NonNull String eventName, @Nullable Object eventData) { |
688 | 705 | public void onInboxUpdated() { |
689 | 706 | sendEvent(EventName.receivedIterableInboxChanged.name(), null); |
690 | 707 | } |
| 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 | + } |
691 | 720 | // --------------------------------------------------------------------------------------- |
692 | 721 | // endregion |
693 | 722 |
|
@@ -773,6 +802,8 @@ enum EventName { |
773 | 802 | handleAuthFailureCalled, |
774 | 803 | handleAuthSuccessCalled, |
775 | 804 | handleCustomActionCalled, |
| 805 | + handleEmbeddedMessageUpdateCalled, |
| 806 | + handleEmbeddedMessagingDisabledCalled, |
776 | 807 | handleInAppCalled, |
777 | 808 | handleUrlCalled, |
778 | 809 | receivedIterableEmbeddedMessagesChanged, |
|
0 commit comments