From ad2aee2ab0d4a20ab57baa4a0300528ad15078c5 Mon Sep 17 00:00:00 2001 From: hardikmashru Date: Fri, 17 May 2024 18:38:16 +0530 Subject: [PATCH 1/3] fix inAppConsume --- .../java/com/iterable/iterableapi/IterableApi.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java index ffc04eaf6..3fb4dcd53 100644 --- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java +++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java @@ -894,6 +894,10 @@ public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable Iterab if (!checkSDKInitialization()) { return; } + if (message == null) { + IterableLogger.e(TAG, "inAppConsume: message is null"); + return; + } apiClient.inAppConsume(message, source, clickLocation, inboxSessionId, null, null); } @@ -912,6 +916,13 @@ public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable Iterab if (!checkSDKInitialization()) { return; } + if (message == null) { + IterableLogger.e(TAG, "inAppConsume: message is null"); + if (failureHandler != null) { + failureHandler.onFailure("inAppConsume: message is null", null); + } + return; + } apiClient.inAppConsume(message, source, clickLocation, inboxSessionId, successHandler, failureHandler); } From 3ccee652210eb3c5652fdd27f1746c11959b4b69 Mon Sep 17 00:00:00 2001 From: hardikmashru Date: Tue, 21 May 2024 12:40:32 +0530 Subject: [PATCH 2/3] refactor inAppConsume --- .../com/iterable/iterableapi/IterableApi.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java index 3fb4dcd53..73822efce 100644 --- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java +++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java @@ -870,11 +870,7 @@ public void inAppConsume(@NonNull String messageId) { */ public void inAppConsume(@NonNull String messageId, @Nullable IterableHelper.SuccessHandler successHandler, @Nullable IterableHelper.FailureHandler failureHandler) { IterableInAppMessage message = getInAppManager().getMessageById(messageId); - if (message == null) { - IterableLogger.e(TAG, "inAppConsume: message is null"); - if (failureHandler != null) { - failureHandler.onFailure("inAppConsume: message is null", null); - } + if (handleNullMessage(message, failureHandler)) { return; } inAppConsume(message, null, null, successHandler, failureHandler); @@ -916,14 +912,29 @@ public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable Iterab if (!checkSDKInitialization()) { return; } + if (handleNullMessage(message, failureHandler)) { + return; + } + apiClient.inAppConsume(message, source, clickLocation, inboxSessionId, successHandler, failureHandler); + } + + /** + * Handles the case when the provided message is null. + * If the message is null and a failure handler is provided, it calls the onFailure method of the failure handler. + * + * @param message The in-app message to be checked. + * @param failureHandler The failure handler to be called if the message is null. + * @return True if the message is null, false otherwise. + */ + private boolean handleNullMessage(@Nullable IterableInAppMessage message, @Nullable IterableHelper.FailureHandler failureHandler) { if (message == null) { IterableLogger.e(TAG, "inAppConsume: message is null"); if (failureHandler != null) { failureHandler.onFailure("inAppConsume: message is null", null); } - return; + return true; } - apiClient.inAppConsume(message, source, clickLocation, inboxSessionId, successHandler, failureHandler); + return false; } /** From e37178aa9f529765901fc1c63918020097a8dce4 Mon Sep 17 00:00:00 2001 From: Hardik Mashru Date: Tue, 21 May 2024 13:54:56 +0530 Subject: [PATCH 3/3] Update IterableApi.java --- .../main/java/com/iterable/iterableapi/IterableApi.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java index 73822efce..43a6a7722 100644 --- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java +++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java @@ -870,7 +870,7 @@ public void inAppConsume(@NonNull String messageId) { */ public void inAppConsume(@NonNull String messageId, @Nullable IterableHelper.SuccessHandler successHandler, @Nullable IterableHelper.FailureHandler failureHandler) { IterableInAppMessage message = getInAppManager().getMessageById(messageId); - if (handleNullMessage(message, failureHandler)) { + if (checkIfMessageIsNull(message, failureHandler)) { return; } inAppConsume(message, null, null, successHandler, failureHandler); @@ -890,8 +890,7 @@ public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable Iterab if (!checkSDKInitialization()) { return; } - if (message == null) { - IterableLogger.e(TAG, "inAppConsume: message is null"); + if (checkIfMessageIsNull(message, null)) { return; } apiClient.inAppConsume(message, source, clickLocation, inboxSessionId, null, null); @@ -912,7 +911,7 @@ public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable Iterab if (!checkSDKInitialization()) { return; } - if (handleNullMessage(message, failureHandler)) { + if (checkIfMessageIsNull(message, failureHandler)) { return; } apiClient.inAppConsume(message, source, clickLocation, inboxSessionId, successHandler, failureHandler); @@ -926,7 +925,7 @@ public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable Iterab * @param failureHandler The failure handler to be called if the message is null. * @return True if the message is null, false otherwise. */ - private boolean handleNullMessage(@Nullable IterableInAppMessage message, @Nullable IterableHelper.FailureHandler failureHandler) { + private boolean checkIfMessageIsNull(@Nullable IterableInAppMessage message, @Nullable IterableHelper.FailureHandler failureHandler) { if (message == null) { IterableLogger.e(TAG, "inAppConsume: message is null"); if (failureHandler != null) {