Fix first reminder too early, offset bugs.
Schedule first reminder date relative to now, handle overflow // FREEBIE
This commit is contained in:
parent
90fc094d0d
commit
a885fb5dee
|
@ -116,6 +116,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
completion:nil];
|
||||
}]];
|
||||
|
||||
[items addObject:[OWSTableItem itemWithTitle:@"Reset 2FA Repetition Interval"
|
||||
actionBlock:^() {
|
||||
[OWS2FAManager.sharedManager setDefaultRepetitionInterval];
|
||||
}]];
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
[items addObject:[OWSTableItem subPageItemWithText:@"Share UIImage"
|
||||
actionBlock:^(UIViewController *viewController) {
|
||||
|
|
|
@ -33,6 +33,9 @@ typedef void (^OWS2FAFailure)(NSError *error);
|
|||
|
||||
- (void)updateRepetitionIntervalWithWasSuccessful:(BOOL)wasSuccessful;
|
||||
|
||||
// used for testing
|
||||
- (void)setDefaultRepetitionInterval;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -95,6 +95,9 @@ const NSUInteger kDaySecs = kHourSecs * 24;
|
|||
|
||||
[self.dbConnection setObject:pin forKey:kOWS2FAManager_PinCode inCollection:kOWS2FAManager_Collection];
|
||||
|
||||
// Schedule next reminder relative to now
|
||||
self.lastSuccessfulReminderDate = [NSDate new];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:NSNotificationName_2FAStateDidChange
|
||||
object:nil
|
||||
userInfo:nil];
|
||||
|
@ -232,14 +235,15 @@ const NSUInteger kDaySecs = kHourSecs * 24;
|
|||
|
||||
NSUInteger oldIndex =
|
||||
[allIntervals indexOfObjectPassingTest:^BOOL(NSNumber *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
|
||||
return oldInterval >= (NSTimeInterval)obj.doubleValue;
|
||||
return oldInterval <= (NSTimeInterval)obj.doubleValue;
|
||||
}];
|
||||
|
||||
NSUInteger newIndex;
|
||||
if (wasSuccessful) {
|
||||
newIndex = oldIndex + 1;
|
||||
} else {
|
||||
newIndex = oldIndex - 1;
|
||||
// prevent overflow
|
||||
newIndex = oldIndex <= 0 ? 0 : oldIndex - 1;
|
||||
}
|
||||
|
||||
// clamp to be valid
|
||||
|
@ -249,6 +253,13 @@ const NSUInteger kDaySecs = kHourSecs * 24;
|
|||
return newInterval;
|
||||
}
|
||||
|
||||
- (void)setDefaultRepetitionInterval
|
||||
{
|
||||
[self.dbConnection setDouble:self.defaultRepetitionInterval
|
||||
forKey:kOWS2FAManager_RepetitionInterval
|
||||
inCollection:kOWS2FAManager_Collection];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
Loading…
Reference in New Issue