Skip to content

Commit

Permalink
Merge pull request #2137 from OneSignal/IAM-display-forever
Browse files Browse the repository at this point in the history
[FIX] IAM with dynamic trigger showing forever
  • Loading branch information
jinliu9508 authored Jul 25, 2024
2 parents 7491122 + 26a1dfd commit cb37657
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
private fun makeRedisplayMessagesAvailableWithTriggers(
newTriggersKeys: Collection<String>,
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
}
Expand Down Expand Up @@ -643,7 +647,6 @@ internal class InAppMessagesManager(
Logging.debug("InAppMessagesManager.onTriggerCompleted: called with triggerId: $triggerId")
val triggerIds: MutableSet<String> = HashSet()
triggerIds.add(triggerId)
makeRedisplayMessagesAvailableWithTriggers(triggerIds)
}

/**
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cb37657

Please sign in to comment.