Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] IAM with dynamic trigger showing forever #2137

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
jkasten2 marked this conversation as resolved.
Show resolved Hide resolved
*/
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isMessageDisplayed is an incorrect name for this, however the pre-existing redisplayedInAppMessages is also a misleading name. A recommend a better name such as canRedisplay instead of isMessageDisplayed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I just fixed this.

val isTriggerOnMessage = _triggerController.isTriggerOnMessage(message, newTriggersKeys)
val isOnlyDynamicTriggers = _triggerController.messageHasOnlyDynamicTriggers(message)
if (!message.isTriggerChanged && isMessageDisplayed && (isTriggerOnMessage || isNewTriggerAdded && isOnlyDynamicTriggers)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is acceptable for now, however keep in mind for the future ideally we won't want to have an if statement with a nested && and || like this in most scenarios, including this one.

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
Loading