Skip to content

Commit e7c25d9

Browse files
committed
check for active period
1 parent f933edf commit e7c25d9

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Leanplum-SDK/Classes/LPActionManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ struct LeanplumMessageMatchResult {
3333
BOOL matchedTrigger;
3434
BOOL matchedUnlessTrigger;
3535
BOOL matchedLimit;
36+
BOOL matchedActivePeriod;
3637
};
3738
typedef struct LeanplumMessageMatchResult LeanplumMessageMatchResult;
3839

39-
LeanplumMessageMatchResult LeanplumMessageMatchResultMake(BOOL matchedTrigger, BOOL matchedUnlessTrigger, BOOL matchedLimit);
40+
LeanplumMessageMatchResult LeanplumMessageMatchResultMake(BOOL matchedTrigger, BOOL matchedUnlessTrigger, BOOL matchedLimit, BOOL matchedActivePeriod);
4041

4142
typedef enum {
4243
kLeanplumActionFilterForeground = 0b1,

Leanplum-SDK/Classes/LPActionManager.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737
#import <objc/runtime.h>
3838
#import <objc/message.h>
3939

40-
LeanplumMessageMatchResult LeanplumMessageMatchResultMake(BOOL matchedTrigger, BOOL matchedUnlessTrigger, BOOL matchedLimit)
40+
LeanplumMessageMatchResult LeanplumMessageMatchResultMake(BOOL matchedTrigger, BOOL matchedUnlessTrigger, BOOL matchedLimit, BOOL matchedActivePeriod)
4141
{
4242
LeanplumMessageMatchResult result;
4343
result.matchedTrigger = matchedTrigger;
4444
result.matchedUnlessTrigger = matchedUnlessTrigger;
4545
result.matchedLimit = matchedLimit;
46+
result.matchedActivePeriod = matchedActivePeriod;
4647
return result;
4748
}
4849

@@ -1064,7 +1065,7 @@ - (LeanplumMessageMatchResult)shouldShowMessage:(NSString *)messageId
10641065
withEventName:(NSString *)eventName
10651066
contextualValues:(LPContextualValues *)contextualValues
10661067
{
1067-
LeanplumMessageMatchResult result = LeanplumMessageMatchResultMake(NO, NO, NO);
1068+
LeanplumMessageMatchResult result = LeanplumMessageMatchResultMake(NO, NO, NO, NO);
10681069

10691070
// 1. Must not be muted.
10701071
if ([[NSUserDefaults standardUserDefaults] boolForKey:
@@ -1088,6 +1089,13 @@ - (LeanplumMessageMatchResult)shouldShowMessage:(NSString *)messageId
10881089
// 3. Must match all limit conditions.
10891090
NSDictionary *limitConfig = messageConfig[@"whenLimits"];
10901091
result.matchedLimit = [self matchesLimits:limitConfig messageId:messageId];
1092+
1093+
// 4. Must be within active period
1094+
NSTimeInterval now = [[NSDate date] timeIntervalSince1970];
1095+
NSTimeInterval startTime = [messageConfig[@"startTime"] doubleValue] / 1000.0;
1096+
NSTimeInterval endTime = [messageConfig[@"endTime"] doubleValue] / 1000.0;
1097+
result.matchedActivePeriod = now > startTime && now < endTime;
1098+
10911099
return result;
10921100
}
10931101

Leanplum-SDK/Classes/Leanplum.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ + (void)maybePerformActions:(NSArray *)whenConditions
17271727
}
17281728
}
17291729

1730-
LeanplumMessageMatchResult result = LeanplumMessageMatchResultMake(NO, NO, NO);
1730+
LeanplumMessageMatchResult result = LeanplumMessageMatchResultMake(NO, NO, NO, NO);
17311731
for (NSString *when in whenConditions) {
17321732
LeanplumMessageMatchResult conditionResult =
17331733
[[LPInternalState sharedState].actionManager shouldShowMessage:internalMessageId
@@ -1738,8 +1738,14 @@ + (void)maybePerformActions:(NSArray *)whenConditions
17381738
result.matchedTrigger |= conditionResult.matchedTrigger;
17391739
result.matchedUnlessTrigger |= conditionResult.matchedUnlessTrigger;
17401740
result.matchedLimit |= conditionResult.matchedLimit;
1741+
result.matchedActivePeriod |= conditionResult.matchedActivePeriod;
17411742
}
17421743

1744+
// Make sure it's within the active period.
1745+
if (!result.matchedActivePeriod) {
1746+
continue;
1747+
}
1748+
17431749
// Make sure we cancel before matching in case the criteria overlap.
17441750
if (result.matchedUnlessTrigger) {
17451751
NSString *cancelActionName = [@"__Cancel" stringByAppendingString:actionType];

0 commit comments

Comments
 (0)