diff --git a/Signal/src/util/MainAppContext.m b/Signal/src/util/MainAppContext.m index dffe0aa76..a5bba11f1 100644 --- a/Signal/src/util/MainAppContext.m +++ b/Signal/src/util/MainAppContext.m @@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN self.reportedApplicationState = UIApplicationStateInactive; + _appLaunchTime = [NSDate new]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification diff --git a/SignalServiceKit/src/Messages/OWSIncompleteCallsJob.m b/SignalServiceKit/src/Messages/OWSIncompleteCallsJob.m index 5592bf8d1..718f7da5a 100644 --- a/SignalServiceKit/src/Messages/OWSIncompleteCallsJob.m +++ b/SignalServiceKit/src/Messages/OWSIncompleteCallsJob.m @@ -3,6 +3,7 @@ // #import "OWSIncompleteCallsJob.h" +#import "AppContent.h" #import "OWSPrimaryStorage.h" #import "TSCall.h" #import @@ -78,9 +79,17 @@ static NSString *const OWSIncompleteCallsJobCallTypeIndex = @"index_calls_on_cal { __block uint count = 0; + OWSAssert(CurrentAppContext().appLaunchTime); + uint64_t cutoffTimestamp = [NSDate ows_millisecondsSince1970ForDate:CurrentAppContext().appLaunchTime]; + [[self.primaryStorage newDatabaseConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self enumerateIncompleteCallsWithBlock:^(TSCall *call) { + if (call.timestamp <= cutoffTimestamp) { + inc DDLogInfo(@"%@ ignoring new call: %@", self.logTag, call.uniqueId); + return; + } + if (call.callType == RPRecentCallTypeOutgoingIncomplete) { DDLogDebug(@"%@ marking call as missed: %@", self.logTag, call.uniqueId); [call updateCallType:RPRecentCallTypeOutgoingMissed transaction:transaction]; @@ -99,7 +108,7 @@ static NSString *const OWSIncompleteCallsJobCallTypeIndex = @"index_calls_on_cal transaction:transaction]; }]; - DDLogDebug(@"%@ Marked %u calls as missed", self.logTag, count); + DDLogInfo(@"%@ Marked %u calls as missed", self.logTag, count); } #pragma mark - YapDatabaseExtension diff --git a/SignalServiceKit/src/Util/AppContext.h b/SignalServiceKit/src/Util/AppContext.h index 8b2801491..bcdc1bab7 100755 --- a/SignalServiceKit/src/Util/AppContext.h +++ b/SignalServiceKit/src/Util/AppContext.h @@ -91,6 +91,8 @@ NSString *NSStringForUIApplicationState(UIApplicationState value); // Should be a NOOP if isMainApp is NO. - (void)setNetworkActivityIndicatorVisible:(BOOL)value; +@property (atomic, readonly) NSDate *appLaunchTime; + @end id CurrentAppContext(void); diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index 99d286204..3d48c911d 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -36,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN self.reportedApplicationState = UIApplicationStateActive; + _appLaunchTime = [NSDate new]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(extensionHostDidBecomeActive:) name:NSExtensionHostDidBecomeActiveNotification