feat: IAMs now display when triggers added before first fetch#1635
feat: IAMs now display when triggers added before first fetch#1635
Conversation
6b3b1a9 to
4cd7760
Compare
| [self evaluateRedisplayedInAppMessages:triggers.allKeys]; | ||
|
|
||
| // Track triggers added early on cold start (before first fetch completes) for redisplay logic | ||
| if (!self.hasCompletedFirstFetch) { |
There was a problem hiding this comment.
how do we make sure there are no duplicates in this?
There was a problem hiding this comment.
How do we make sure this is thread safe?
There was a problem hiding this comment.
Duplicates? Unsure what you mean, earlySessionTriggers is a set.
If clients are concurrently calling addTrigger from 2 threads, then the existing code would already be an issue?
There was a problem hiding this comment.
yeah as we discussed on the call, this is something we should work on soon. Please create a tech debt ticket for this @nan-li . thanks
iOS_SDK/OneSignalSDK/OneSignalInAppMessages/Controller/OSMessagingController.m
Show resolved
Hide resolved
| [self resetRedisplayMessagesBySession]; | ||
|
|
||
| // Apply isTriggerChanged for messages that match triggers added too early on cold start | ||
| if (self.earlySessionTriggers.count > 0) { |
There was a problem hiding this comment.
I have tests in EarlyTriggerTrackingTests.swfit. I think the lines you are are pointing out here have tests in
testMessagesMatchingEarlyTriggers_getIsTriggerChangedFlag. Is there something else in particular you want tested?
There was a problem hiding this comment.
ah right, missed looking at them.
- Addresses issue where in-app messages wouldn't display on cold starts if their triggers were added very early (before IAM fetch completed). - Tracks triggers added before first fetch completes, then applies the isTriggerChanged flag to matching messages when they are received from the server, ensuring redisplay logic works correctly.
Add comprehensive test coverage for the early trigger tracking feature that enables IAMs to display when triggers are added before the first fetch completes on cold start.
4cd7760 to
c50dee3
Compare
| [self resetRedisplayMessagesBySession]; | ||
|
|
||
| // Apply isTriggerChanged for messages that match triggers added too early on cold start | ||
| if (self.earlySessionTriggers.count > 0) { |
There was a problem hiding this comment.
ah right, missed looking at them.
| [self evaluateRedisplayedInAppMessages:triggers.allKeys]; | ||
|
|
||
| // Track triggers added early on cold start (before first fetch completes) for redisplay logic | ||
| if (!self.hasCompletedFirstFetch) { |
There was a problem hiding this comment.
yeah as we discussed on the call, this is something we should work on soon. Please create a tech debt ticket for this @nan-li . thanks
Description
One Line Summary
Display IAMs with triggers added before first fetch on cold start.
Details
On subsequent cold starts, if triggers were added very early in the app lifecycle (before the first IAM fetch completed), in-app messages matching those triggers would not display even though they should have been eligible for redisplay.
Root cause: When the trigger is added, evaluateRedisplayedInAppMessages was called when the messages were empty, so message.isTriggerChanged was never set for messages that arrived later from the server.
Solution: Track trigger keys added before the first fetch completes in earlySessionTriggers, then apply isTriggerChanged to matching redisplay messages when they arrive from the server. This ensures the redisplay logic correctly identifies that triggers have changed and clears the message from seenInAppMessages.
Motivation
Provide feature that is requested
Scope
This only affects cold starts (process restarts) and does not impact warm starts from backgrounding, where existing redisplay behavior is preserved.
Testing
Unit testing
WIP
Manual testing
Tested on iOS 18.5 simulator
Add trigger immediately after initialization, and confirm the IAM now displays after the changes in this PR.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is