Skip to content

Commit

Permalink
add a check to dynamic trigger to prevent it from firing multiple time
Browse files Browse the repository at this point in the history
  • Loading branch information
jinliu9508 committed Jul 1, 2024
1 parent 96459e9 commit 49be2fc
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,31 @@ internal class DynamicTriggerController(
}

var currentTimeInterval: Long = 0
val lastTimeAppDismissed = _state.lastTimeInAppDismissed
when (trigger.kind) {
Trigger.OSTriggerKind.SESSION_TIME ->
Trigger.OSTriggerKind.SESSION_TIME -> {
currentTimeInterval = _time.currentTimeMillis - _session.startTime
// if last time IAM dismissed also satisfied this trigger, do not fire it again
val lastTimeDismissedInterval =
if (lastTimeAppDismissed == null) {
0
} else {
_time.currentTimeMillis - lastTimeAppDismissed
}
if (evaluateTimeIntervalWithOperator(
lastTimeDismissedInterval.toDouble(),
currentTimeInterval.toDouble(),
trigger.operatorType,
)
) {
return false
}
}
Trigger.OSTriggerKind.TIME_SINCE_LAST_IN_APP -> {
if (_state.inAppMessageIdShowing != null) {
return false
}
val lastTimeAppDismissed = _state.lastTimeInAppDismissed

currentTimeInterval =
if (lastTimeAppDismissed == null) {
DEFAULT_LAST_IN_APP_TIME_AGO
Expand Down

0 comments on commit 49be2fc

Please sign in to comment.