Skip to content

Commit

Permalink
Adding a new trigger redisplays message only if dynamic trigger exists
Browse files Browse the repository at this point in the history
  • Loading branch information
jinliu9508 committed Jul 18, 2024
1 parent 7582adf commit 0f42d93
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ internal class InAppMessagesManager(
*
* Make all messages with redisplay available if:
* - Already displayed
* - At least one existing Trigger has changed OR a new trigger is added
* - At least one existing Trigger has changed OR a new trigger is added when dynamic trigger exists
*/
private fun makeRedisplayMessagesAvailableWithTriggers(
newTriggersKeys: Collection<String>,
Expand All @@ -460,7 +460,10 @@ internal class InAppMessagesManager(
for (message in messages) {
if (!message.isTriggerChanged &&
redisplayedInAppMessages.contains(message) &&
(_triggerController.isTriggerOnMessage(message, newTriggersKeys) || isNewTriggerAdded)
(
_triggerController.isTriggerOnMessage(message, newTriggersKeys) ||
isNewTriggerAdded && _triggerController.messageContainsDynamicTrigger(message)
)
) {
Logging.debug("InAppMessagesManager.makeRedisplayMessagesAvailableWithTriggers: Trigger changed for message: $message")
message.isTriggerChanged = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ internal class Trigger(json: JSONObject) {
*/
val value: Any?

/**
* Trigger not kind of CUSTOM or UNKNOWN is considered a dynamic or time-based trigger
*/
val isDynamicTrigger: Boolean
get() = kind != Trigger.OSTriggerKind.CUSTOM && kind != Trigger.OSTriggerKind.UNKNOWN

init {
triggerId = json.getString("id")
kind = OSTriggerKind.fromString(json.getString("kind"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ internal interface ITriggerController : IEventNotifier<ITriggerHandler> {
* @return true if the message only has dynamic triggers, false otherwise.
*/
fun messageHasOnlyDynamicTriggers(message: InAppMessage): Boolean

/**
* Determine if the provided message contains at least one dynamic trigger.
*
* @param message The message to check.
* @return true if the message contains at least one dynamic triggers, false otherwise.
*/
fun messageContainsDynamicTrigger(message: InAppMessage): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal class TriggerController(
return false
}

if (trigger.kind != Trigger.OSTriggerKind.CUSTOM) {
if (trigger.isDynamicTrigger) {
return _dynamicTriggerController.dynamicTriggerShouldFire(trigger)
}

Expand Down Expand Up @@ -201,7 +201,7 @@ internal class TriggerController(
if (message.triggers == null || message.triggers.isEmpty()) return false
for (andConditions in message.triggers) {
for (trigger in andConditions) {
if (trigger.kind == Trigger.OSTriggerKind.CUSTOM || trigger.kind == Trigger.OSTriggerKind.UNKNOWN) {
if (!trigger.isDynamicTrigger) {
// At least one trigger is not dynamic
return false
}
Expand All @@ -210,6 +210,18 @@ internal class TriggerController(
return true
}

override fun messageContainsDynamicTrigger(message: InAppMessage): Boolean {
if (message.triggers == null || message.triggers.isEmpty()) return false
for (andConditions in message.triggers) {
for (trigger in andConditions) {
if (trigger.isDynamicTrigger) {
return true
}
}
}
return false
}

override fun onModelAdded(
model: TriggerModel,
tag: String,
Expand Down

0 comments on commit 0f42d93

Please sign in to comment.