Skip to content

Commit ab2c42f

Browse files
authored
Merge pull request #103 from Iterable/chore/MOB-381-support-itbl-custom-actions
[MOB-381] Reserve iterable:// URLs for SDK-defined actions, route itbl:// to custom action handler for compatibility
2 parents 9b57e20 + 6c5944c commit ab2c42f

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public final class IterableConstants {
178178

179179
// URL schemes
180180
public static final String URL_SCHEME_ITBL = "itbl://";
181+
public static final String URL_SCHEME_ITERABLE = "iterable://";
181182
public static final String URL_SCHEME_ACTION = "action://";
182183

183184
public static final String ITBL_KEY_SDK_VERSION = "SDKVersion";

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppManager.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,13 @@ public void execute(Uri url) {
141141
String actionName = urlString.replace(IterableConstants.URL_SCHEME_ACTION, "");
142142
IterableActionRunner.executeAction(context, IterableAction.actionCustomAction(actionName), IterableActionSource.IN_APP);
143143
} else if (urlString.startsWith(IterableConstants.URL_SCHEME_ITBL)) {
144-
// Handle itbl:// URLs
145-
handleIterableCustomAction(urlString.replace(IterableConstants.URL_SCHEME_ITBL, ""), message);
144+
// Handle itbl:// URLs, pass that to the custom action handler for compatibility
145+
String actionName = urlString.replace(IterableConstants.URL_SCHEME_ITBL, "");
146+
IterableActionRunner.executeAction(context, IterableAction.actionCustomAction(actionName), IterableActionSource.IN_APP);
147+
} else if (urlString.startsWith(IterableConstants.URL_SCHEME_ITERABLE)) {
148+
// Handle iterable:// URLs - reserved for actions defined by the SDK only
149+
String actionName = urlString.replace(IterableConstants.URL_SCHEME_ITERABLE, "");
150+
handleIterableCustomAction(actionName, message);
146151
} else {
147152
IterableActionRunner.executeAction(context, IterableAction.actionOpenUrl(urlString), IterableActionSource.IN_APP);
148153
}

iterableapi/src/test/java/com/iterable/iterableapi/IterableInAppManagerTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ public IterableConfig.Builder run(IterableConfig.Builder builder) {
216216
assertEquals("actionName", actionCaptor.getValue().getType());
217217
assertEquals(IterableActionSource.IN_APP, contextCaptor.getValue().source);
218218

219+
// Verify that legacy itbl:// links are also routed to the custom action handler
220+
reset(inAppDisplayerMock);
221+
reset(customActionHandler);
222+
inAppManager.showMessage(message);
223+
verify(inAppDisplayerMock).showMessage(any(IterableInAppMessage.class), callbackCaptor.capture());
224+
callbackCaptor.getValue().execute(Uri.parse("itbl://legacyCustomAction"));
225+
verify(customActionHandler).handleIterableCustomAction(actionCaptor.capture(), contextCaptor.capture());
226+
assertEquals("legacyCustomAction", actionCaptor.getValue().getType());
227+
assertEquals(IterableActionSource.IN_APP, contextCaptor.getValue().source);
228+
219229
reset(inAppDisplayerMock);
220230
inAppManager.showMessage(message);
221231
verify(inAppDisplayerMock).showMessage(any(IterableInAppMessage.class), callbackCaptor.capture());
@@ -224,6 +234,16 @@ public IterableConfig.Builder run(IterableConfig.Builder builder) {
224234
verify(urlHandler).handleIterableURL(urlCaptor.capture(), contextCaptor.capture());
225235
assertEquals("https://www.google.com", urlCaptor.getValue().toString());
226236
assertEquals(IterableActionSource.IN_APP, contextCaptor.getValue().source);
237+
238+
// Verify that iterable:// links are not routed to either custom action handler or url handler
239+
reset(inAppDisplayerMock);
240+
reset(customActionHandler);
241+
reset(urlHandler);
242+
inAppManager.showMessage(message);
243+
verify(inAppDisplayerMock).showMessage(any(IterableInAppMessage.class), callbackCaptor.capture());
244+
callbackCaptor.getValue().execute(Uri.parse("iterable://someInternalAction"));
245+
verify(customActionHandler, never()).handleIterableCustomAction(any(IterableAction.class), any(IterableActionContext.class));
246+
verify(urlHandler, never()).handleIterableURL(any(Uri.class), any(IterableActionContext.class));
227247
}
228248

229249
}

0 commit comments

Comments
 (0)