diff --git a/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/InAppMessagesManager.kt b/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/InAppMessagesManager.kt index 2e70f1c07a..6513e3f548 100644 --- a/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/InAppMessagesManager.kt +++ b/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/InAppMessagesManager.kt @@ -451,13 +451,17 @@ internal class InAppMessagesManager( * * Make all messages with redisplay available if: * - Already displayed - * - At least one Trigger has changed + * - At least one existing Trigger has changed OR a new trigger is added when there is only dynamic trigger */ - private fun makeRedisplayMessagesAvailableWithTriggers(newTriggersKeys: Collection) { + private fun makeRedisplayMessagesAvailableWithTriggers( + newTriggersKeys: Collection, + isNewTriggerAdded: Boolean, + ) { for (message in messages) { - if (!message.isTriggerChanged && redisplayedInAppMessages.contains(message) && - _triggerController.isTriggerOnMessage(message, newTriggersKeys) - ) { + val isMessageDisplayed = redisplayedInAppMessages.contains(message) + val isTriggerOnMessage = _triggerController.isTriggerOnMessage(message, newTriggersKeys) + val isOnlyDynamicTriggers = _triggerController.messageHasOnlyDynamicTriggers(message) + if (!message.isTriggerChanged && isMessageDisplayed && (isTriggerOnMessage || isNewTriggerAdded && isOnlyDynamicTriggers)) { Logging.debug("InAppMessagesManager.makeRedisplayMessagesAvailableWithTriggers: Trigger changed for message: $message") message.isTriggerChanged = true } @@ -643,7 +647,6 @@ internal class InAppMessagesManager( Logging.debug("InAppMessagesManager.onTriggerCompleted: called with triggerId: $triggerId") val triggerIds: MutableSet = HashSet() triggerIds.add(triggerId) - makeRedisplayMessagesAvailableWithTriggers(triggerIds) } /** @@ -653,9 +656,11 @@ internal class InAppMessagesManager( * * @see OSInAppMessageController.setDataForRedisplay */ - override fun onTriggerConditionChanged() { + override fun onTriggerConditionChanged(triggerId: String) { Logging.debug("InAppMessagesManager.onTriggerConditionChanged()") + makeRedisplayMessagesAvailableWithTriggers(listOf(triggerId), false) + suspendifyOnThread { // This method is called when a time-based trigger timer fires, meaning the message can // probably be shown now. So the current message conditions should be re-evaluated @@ -666,7 +671,7 @@ internal class InAppMessagesManager( override fun onTriggerChanged(newTriggerKey: String) { Logging.debug("InAppMessagesManager.onTriggerChanged(newTriggerKey: $newTriggerKey)") - makeRedisplayMessagesAvailableWithTriggers(listOf(newTriggerKey)) + makeRedisplayMessagesAvailableWithTriggers(listOf(newTriggerKey), true) suspendifyOnThread { // This method is called when a time-based trigger timer fires, meaning the message can diff --git a/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/triggers/ITriggerHandler.kt b/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/triggers/ITriggerHandler.kt index 861ddcfdf8..c834d32390 100644 --- a/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/triggers/ITriggerHandler.kt +++ b/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/triggers/ITriggerHandler.kt @@ -16,7 +16,7 @@ internal interface ITriggerHandler { /** * Called when a time-based trigger (dynamic trigger) will now evaluate to true. */ - fun onTriggerConditionChanged() + fun onTriggerConditionChanged(triggerId: String) /** * Called when a new trigger has been added, or an existing trigger's value has been diff --git a/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/triggers/impl/DynamicTriggerController.kt b/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/triggers/impl/DynamicTriggerController.kt index 8f12b54575..b7dd35afd7 100644 --- a/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/triggers/impl/DynamicTriggerController.kt +++ b/OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/triggers/impl/DynamicTriggerController.kt @@ -89,7 +89,7 @@ internal class DynamicTriggerController( object : TimerTask() { override fun run() { scheduledMessages.remove(triggerId) - events.fire { it.onTriggerConditionChanged() } + events.fire { it.onTriggerConditionChanged(triggerId) } } }, triggerId,