diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index b9338905f..53e69d529 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -4441,7 +4441,7 @@ typedef enum : NSUInteger { - (void)updateShouldObserveDBModifications { - BOOL isAppForegroundAndActive = CurrentAppContext().reportedApplicationState == UIApplicationStateActive; + BOOL isAppForegroundAndActive = CurrentAppContext().isAppForegroundAndActive; self.shouldObserveDBModifications = self.isViewVisible && isAppForegroundAndActive; } diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index b48375ba1..d47030869 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -485,7 +485,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations - (void)updateShouldObserveDBModifications { - BOOL isAppForegroundAndActive = CurrentAppContext().reportedApplicationState == UIApplicationStateActive; + BOOL isAppForegroundAndActive = CurrentAppContext().isAppForegroundAndActive; self.shouldObserveDBModifications = self.isViewVisible && isAppForegroundAndActive; } diff --git a/Signal/src/util/MainAppContext.m b/Signal/src/util/MainAppContext.m index 4937ee4e0..7fed2dc6b 100644 --- a/Signal/src/util/MainAppContext.m +++ b/Signal/src/util/MainAppContext.m @@ -156,6 +156,11 @@ NS_ASSUME_NONNULL_BEGIN return self.reportedApplicationState == UIApplicationStateBackground; } +- (BOOL)isAppForegroundAndActive +{ + return self.reportedApplicationState == UIApplicationStateActive; +} + - (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler: (BackgroundTaskExpirationHandler)expirationHandler { diff --git a/SignalMessaging/Views/ThreadViewHelper.m b/SignalMessaging/Views/ThreadViewHelper.m index 881ad4ae5..e05169a39 100644 --- a/SignalMessaging/Views/ThreadViewHelper.m +++ b/SignalMessaging/Views/ThreadViewHelper.m @@ -79,8 +79,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)updateShouldObserveDBModifications { - BOOL isAppForegroundAndActive = CurrentAppContext().reportedApplicationState == UIApplicationStateActive; - self.shouldObserveDBModifications = isAppForegroundAndActive; + self.shouldObserveDBModifications = CurrentAppContext().isAppForegroundAndActive; } // Don't observe database change notifications when the app is in the background. diff --git a/SignalServiceKit/src/Util/AppContext.h b/SignalServiceKit/src/Util/AppContext.h index 8c10362c7..c6c665d95 100755 --- a/SignalServiceKit/src/Util/AppContext.h +++ b/SignalServiceKit/src/Util/AppContext.h @@ -55,6 +55,11 @@ NSString *NSStringForUIApplicationState(UIApplicationState value); // This method is thread-safe. - (BOOL)isInBackground; +// A convenience accessor for reportedApplicationState. +// +// This method is thread-safe. +- (BOOL)isAppForegroundAndActive; + // Should start a background task if isMainApp is YES. // Should just return UIBackgroundTaskInvalid if isMainApp is NO. - (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler: diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index 140fd914a..b7baa134d 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -151,6 +151,11 @@ NS_ASSUME_NONNULL_BEGIN return self.reportedApplicationState == UIApplicationStateBackground; } +- (BOOL)isAppForegroundAndActive +{ + return self.reportedApplicationState == UIApplicationStateActive; +} + - (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler: (BackgroundTaskExpirationHandler)expirationHandler {