Skip to content
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
4 changes: 4 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
3C2D8A5928B4C4E300BE41F6 /* OSDelta.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C2D8A5828B4C4E300BE41F6 /* OSDelta.swift */; };
3C2DB2F12DE6CB5E0006B905 /* OneSignalBadgeHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C2DB2EF2DE6CB5E0006B905 /* OneSignalBadgeHelpers.h */; settings = {ATTRIBUTES = (Public, ); }; };
3C2DB2F22DE6CB5E0006B905 /* OneSignalBadgeHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C2DB2F02DE6CB5E0006B905 /* OneSignalBadgeHelpers.m */; };
3C30FE362F21FBE1001B9C25 /* EarlyTriggerTrackingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C30FE352F21FBE1001B9C25 /* EarlyTriggerTrackingTests.swift */; };
3C3D34E92E95EAA5006A2924 /* LiveActivityConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C3D34E82E95EAA5006A2924 /* LiveActivityConstants.swift */; };
3C3D8D782E92DB7500C3E977 /* OSLiveActivityViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C3D8D772E92DB7500C3E977 /* OSLiveActivityViewExtensions.swift */; };
3C44673E296D099D0039A49E /* OneSignalMobileProvision.m in Sources */ = {isa = PBXBuildFile; fileRef = 912411FD1E73342200E41FD7 /* OneSignalMobileProvision.m */; };
Expand Down Expand Up @@ -1310,6 +1311,7 @@
3C2D8A5828B4C4E300BE41F6 /* OSDelta.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSDelta.swift; sourceTree = "<group>"; };
3C2DB2EF2DE6CB5E0006B905 /* OneSignalBadgeHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalBadgeHelpers.h; sourceTree = "<group>"; };
3C2DB2F02DE6CB5E0006B905 /* OneSignalBadgeHelpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalBadgeHelpers.m; sourceTree = "<group>"; };
3C30FE352F21FBE1001B9C25 /* EarlyTriggerTrackingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EarlyTriggerTrackingTests.swift; sourceTree = "<group>"; };
3C3D34E82E95EAA5006A2924 /* LiveActivityConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveActivityConstants.swift; sourceTree = "<group>"; };
3C3D8D772E92DB7500C3E977 /* OSLiveActivityViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSLiveActivityViewExtensions.swift; sourceTree = "<group>"; };
3C448B9B2936ADFD002F96BC /* OSBackgroundTaskHandlerImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSBackgroundTaskHandlerImpl.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2168,6 +2170,7 @@
3C01519B2C2E29F90079E076 /* IAMRequestTests.m */,
3C7021E82ECF0CF4001768C6 /* IAMIntegrationTests.swift */,
3CAA4BB62F0BAFBA00A16682 /* TriggerTests.swift */,
3C30FE352F21FBE1001B9C25 /* EarlyTriggerTrackingTests.swift */,
3CB35FCA2F0FA20B000E6E0F /* OSMessagingControllerUserStateTests.swift */,
3C7021E72ECF0CF3001768C6 /* OneSignalInAppMessagesTests-Bridging-Header.h */,
);
Expand Down Expand Up @@ -4313,6 +4316,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3C30FE362F21FBE1001B9C25 /* EarlyTriggerTrackingTests.swift in Sources */,
3CAA4BB72F0BAFBA00A16682 /* TriggerTests.swift in Sources */,
3C7021E92ECF0CF4001768C6 /* IAMIntegrationTests.swift in Sources */,
3C01519C2C2E29F90079E076 /* IAMRequestTests.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {

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.

Copy link
Contributor Author

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?

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.

[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];
}
Expand Down Expand Up @@ -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) {

Choose a reason for hiding this comment

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

how do we make sure there are no duplicates in this?

Choose a reason for hiding this comment

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

How do we make sure this is thread safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Choose a reason for hiding this comment

The 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

[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];
}

Expand Down
Loading
Loading