-
Notifications
You must be signed in to change notification settings - Fork 266
feat: IAMs now display when triggers added before first fetch #1635
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,12 @@ @interface OSMessagingController () | |
| /// set when we attempt getInAppMessagesFromServer and no onesignal ID is available yet | ||
| @property (strong, nonatomic, nullable) NSString *shouldFetchOnUserChangeWithSubscriptionID; | ||
|
|
||
| /// Tracks whether the first IAM fetch has completed since this cold start | ||
| @property (nonatomic) BOOL hasCompletedFirstFetch; | ||
|
|
||
| /// Tracks trigger keys added early on cold start (before first fetch completes), for redisplay logic | ||
| @property (strong, nonatomic, nonnull) NSMutableSet<NSString *> *earlySessionTriggers; | ||
|
|
||
| @end | ||
|
|
||
| @implementation OSMessagingController | ||
|
|
@@ -218,6 +224,8 @@ - (instancetype)init { | |
| self.messageDisplayQueue = [NSMutableArray new]; | ||
| self.clickListeners = [NSMutableArray new]; | ||
| self.lifecycleListeners = [NSMutableArray new]; | ||
| self.hasCompletedFirstFetch = NO; | ||
| self.earlySessionTriggers = [NSMutableSet new]; | ||
|
|
||
| let standardUserDefaults = OneSignalUserDefaults.initStandard; | ||
|
|
||
|
|
@@ -404,6 +412,23 @@ - (void)updateInAppMessagesFromServer:(NSArray<OSInAppMessageInternal *> *)newMe | |
| self.messages = newMessages; | ||
| self.calledLoadTags = NO; | ||
| [self resetRedisplayMessagesBySession]; | ||
|
|
||
| // Apply isTriggerChanged for messages that match triggers added too early on cold start | ||
| if (self.earlySessionTriggers.count > 0) { | ||
| [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Processing triggers added early on cold start: %@", self.earlySessionTriggers]]; | ||
| for (OSInAppMessageInternal *message in self.messages) { | ||
| if ([self.redisplayedInAppMessages objectForKey:message.messageId] && | ||
| [self.triggerController hasSharedTriggers:message newTriggersKeys:self.earlySessionTriggers.allObjects]) { | ||
| [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Setting isTriggerChanged=YES for message %@", message]]; | ||
| message.isTriggerChanged = YES; | ||
| } | ||
| } | ||
| [self.earlySessionTriggers removeAllObjects]; | ||
| } | ||
|
|
||
| // Mark that first fetch has completed | ||
| self.hasCompletedFirstFetch = YES; | ||
|
|
||
| [self evaluateMessages]; | ||
| [self deleteOldRedisplayedInAppMessages]; | ||
| } | ||
|
|
@@ -806,6 +831,13 @@ - (void)evaluateRedisplayedInAppMessages:(NSArray<NSString *> *)newTriggersKeys | |
| #pragma mark Trigger Methods | ||
| - (void)addTriggers:(NSDictionary<NSString *, id> *)triggers { | ||
| [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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do we make sure there are no duplicates in this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we make sure this is thread safe?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
abdulraqeeb33 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Tracking triggers added early on cold start: %@", triggers]]; | ||
| [self.earlySessionTriggers addObjectsFromArray:triggers.allKeys]; | ||
| } | ||
|
|
||
| [self.triggerController addTriggers:triggers]; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need some tests for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, missed looking at them.