|
18 | 18 | NSString *const kREDIRECT_HEADER = @"X-WZRK-RD"; |
19 | 19 | NSString *const kREDIRECT_NOTIF_VIEWED_HEADER = @"X-WZRK-SPIKY-RD"; |
20 | 20 | NSString *const kMUTE_HEADER = @"X-WZRK-MUTE"; |
| 21 | +NSString *const kMUTE_DURATION_HEADER = @"X-WZRK-MUTE-DURATION"; |
21 | 22 |
|
22 | | -NSString *const kMUTED_TS_KEY = @"CLTAP_MUTED_TS_KEY"; |
| 23 | +NSString *const kMUTE_EXPIRY_TS_KEY = @"CLTAP_MUTE_EXPIRY_TS_KEY"; |
23 | 24 | NSTimeInterval const kMUTE_SECONDS = 24 * 60 * 60; |
24 | 25 |
|
25 | 26 | @interface CTDomainFactory () |
26 | 27 | @property (nonatomic, strong) CleverTapInstanceConfig *config; |
27 | 28 | @property (nonatomic, strong) CTRequestSender *requestSender; |
28 | 29 |
|
29 | | -@property (nonatomic, assign) NSTimeInterval lastMutedTs; |
| 30 | +@property (nonatomic, assign) NSTimeInterval muteExpiryTs; |
30 | 31 |
|
31 | 32 | #if CLEVERTAP_SSL_PINNING |
32 | 33 | @property(nonatomic, strong) CTPinnedNSURLSessionDelegate *urlSessionDelegate; |
@@ -71,22 +72,23 @@ - (void)setRequestSender:(CTRequestSender *)requestSender { |
71 | 72 |
|
72 | 73 | - (void)loadMutedTs { |
73 | 74 | if (self.config.isDefaultInstance) { |
74 | | - self.lastMutedTs = [CTPreferences getIntForKey:[CTPreferences storageKeyWithSuffix:kMUTED_TS_KEY config: self.config] withResetValue:[CTPreferences getIntForKey:kMUTED_TS_KEY withResetValue:0]]; |
| 75 | + self.muteExpiryTs = [CTPreferences getIntForKey:[CTPreferences storageKeyWithSuffix:kMUTE_EXPIRY_TS_KEY config: self.config] withResetValue:[CTPreferences getIntForKey:kMUTE_EXPIRY_TS_KEY withResetValue:0]]; |
75 | 76 | } else { |
76 | | - self.lastMutedTs = [CTPreferences getIntForKey:[CTPreferences storageKeyWithSuffix:kMUTED_TS_KEY config: self.config] withResetValue:0]; |
| 77 | + self.muteExpiryTs = [CTPreferences getIntForKey:[CTPreferences storageKeyWithSuffix:kMUTE_EXPIRY_TS_KEY config: self.config] withResetValue:0]; |
77 | 78 | } |
78 | 79 | } |
79 | 80 |
|
80 | 81 | - (BOOL)isMuted { |
81 | | - return [NSDate new].timeIntervalSince1970 - self.lastMutedTs < kMUTE_SECONDS; |
| 82 | + return [NSDate new].timeIntervalSince1970 < self.muteExpiryTs; |
82 | 83 | } |
83 | 84 |
|
84 | 85 | - (void)clearRedirectDomain { |
85 | 86 | self.redirectDomain = nil; |
86 | 87 | self.redirectNotifViewedDomain = nil; |
87 | 88 | [self persistRedirectDomain]; // if nil persist will remove |
| 89 | + [self persistRedirectNotifViewedDomain]; // if nil persist will remove |
88 | 90 | self.redirectDomain = [self loadRedirectDomain]; // reload explicit domain if we have one else will be nil |
89 | | - self.redirectNotifViewedDomain = [self loadRedirectNotifViewedDomain]; // reload explicit notification viewe domain if we have one else will be nil |
| 91 | + self.redirectNotifViewedDomain = [self loadRedirectNotifViewedDomain]; // reload explicit notification viewed domain if we have one else will be nil |
90 | 92 | } |
91 | 93 |
|
92 | 94 | - (NSString *)loadRedirectDomain { |
@@ -167,8 +169,19 @@ - (void)persistRedirectNotifViewedDomain { |
167 | 169 | } |
168 | 170 |
|
169 | 171 | - (void)persistMutedTs { |
170 | | - self.lastMutedTs = [NSDate new].timeIntervalSince1970; |
171 | | - [CTPreferences putInt:self.lastMutedTs forKey:[CTPreferences storageKeyWithSuffix:kMUTED_TS_KEY config: self.config]]; |
| 172 | + NSTimeInterval expiryTs = [NSDate new].timeIntervalSince1970 + kMUTE_SECONDS; |
| 173 | + self.muteExpiryTs = expiryTs; |
| 174 | + [CTPreferences putInt:self.muteExpiryTs forKey:[CTPreferences storageKeyWithSuffix:kMUTE_EXPIRY_TS_KEY config: self.config]]; |
| 175 | +} |
| 176 | + |
| 177 | +- (void)persistMutedExpiry:(NSTimeInterval)expiryTs { |
| 178 | + self.muteExpiryTs = expiryTs; |
| 179 | + [CTPreferences putInt:self.muteExpiryTs forKey:[CTPreferences storageKeyWithSuffix:kMUTE_EXPIRY_TS_KEY config: self.config]]; |
| 180 | +} |
| 181 | + |
| 182 | +- (void)unmute { |
| 183 | + self.muteExpiryTs = 0; |
| 184 | + [CTPreferences putInt:0 forKey:[CTPreferences storageKeyWithSuffix:kMUTE_EXPIRY_TS_KEY config:self.config]]; |
172 | 185 | } |
173 | 186 |
|
174 | 187 | #pragma mark - Handshake Handling |
@@ -244,7 +257,13 @@ - (void)updateMutedFromResponseHeaders:(NSDictionary *)headers { |
244 | 257 | NSString *mutedString = headers[kMUTE_HEADER]; |
245 | 258 | BOOL muted = (mutedString == nil ? NO : [mutedString boolValue]); |
246 | 259 | if (muted) { |
247 | | - [self persistMutedTs]; |
| 260 | + NSString *muteDurationString = headers[kMUTE_DURATION_HEADER]; |
| 261 | + if (muteDurationString != nil) { |
| 262 | + long long muteExpiryMs = [muteDurationString longLongValue]; |
| 263 | + [self persistMutedExpiry:muteExpiryMs / 1000.0]; |
| 264 | + } else { |
| 265 | + [self persistMutedTs]; |
| 266 | + } |
248 | 267 | if (self.domainResolverDelegate && [self.domainResolverDelegate respondsToSelector:@selector(onMute)]) { |
249 | 268 | [self.domainResolverDelegate onMute]; |
250 | 269 | } |
|
0 commit comments