Modify views to observe changes when active, not just foreground.
This commit is contained in:
parent
d62725d3b7
commit
812210a63c
@ -233,7 +233,6 @@ typedef enum : NSUInteger {
|
||||
|
||||
@property (nonatomic) BOOL isViewCompletelyAppeared;
|
||||
@property (nonatomic) BOOL isViewVisible;
|
||||
@property (nonatomic) BOOL isAppInBackground;
|
||||
@property (nonatomic) BOOL shouldObserveDBModifications;
|
||||
@property (nonatomic) BOOL viewHasEverAppeared;
|
||||
@property (nonatomic) BOOL hasUnreadMessages;
|
||||
@ -594,12 +593,12 @@ typedef enum : NSUInteger {
|
||||
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
||||
{
|
||||
[self startReadTimer];
|
||||
self.isAppInBackground = NO;
|
||||
[self updateCellsVisible];
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(NSNotification *)notification
|
||||
{
|
||||
self.isAppInBackground = YES;
|
||||
[self updateCellsVisible];
|
||||
if (self.hasClearedUnreadMessagesIndicator) {
|
||||
self.hasClearedUnreadMessagesIndicator = NO;
|
||||
[self.dynamicInteractions clearUnreadIndicatorState];
|
||||
@ -609,6 +608,7 @@ typedef enum : NSUInteger {
|
||||
|
||||
- (void)applicationWillResignActive:(NSNotification *)notification
|
||||
{
|
||||
[self updateShouldObserveDBModifications];
|
||||
[self cancelVoiceMemo];
|
||||
self.isUserScrolling = NO;
|
||||
[self saveDraft];
|
||||
@ -620,6 +620,7 @@ typedef enum : NSUInteger {
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)notification
|
||||
{
|
||||
[self updateShouldObserveDBModifications];
|
||||
[self startReadTimer];
|
||||
}
|
||||
|
||||
@ -1530,7 +1531,8 @@ typedef enum : NSUInteger {
|
||||
|
||||
- (void)autoLoadMoreIfNecessary
|
||||
{
|
||||
if (self.isUserScrolling || !self.isViewVisible || self.isAppInBackground) {
|
||||
BOOL isAppInBackground = CurrentAppContext().isInBackground;
|
||||
if (self.isUserScrolling || !self.isViewVisible || isAppInBackground) {
|
||||
return;
|
||||
}
|
||||
if (!self.showLoadMoreHeader) {
|
||||
@ -4428,17 +4430,10 @@ typedef enum : NSUInteger {
|
||||
[self updateCellsVisible];
|
||||
}
|
||||
|
||||
- (void)setIsAppInBackground:(BOOL)isAppInBackground
|
||||
{
|
||||
_isAppInBackground = isAppInBackground;
|
||||
|
||||
[self updateShouldObserveDBModifications];
|
||||
[self updateCellsVisible];
|
||||
}
|
||||
|
||||
- (void)updateCellsVisible
|
||||
{
|
||||
BOOL isCellVisible = self.isViewVisible && !self.isAppInBackground;
|
||||
BOOL isAppInBackground = CurrentAppContext().isInBackground;
|
||||
BOOL isCellVisible = self.isViewVisible && !isAppInBackground;
|
||||
for (ConversationViewCell *cell in self.collectionView.visibleCells) {
|
||||
cell.isCellVisible = isCellVisible;
|
||||
}
|
||||
@ -4446,7 +4441,8 @@ typedef enum : NSUInteger {
|
||||
|
||||
- (void)updateShouldObserveDBModifications
|
||||
{
|
||||
self.shouldObserveDBModifications = self.isViewVisible && !self.isAppInBackground;
|
||||
BOOL isAppForegroundAndActive = CurrentAppContext().reportedApplicationState == UIApplicationStateActive;
|
||||
self.shouldObserveDBModifications = self.isViewVisible && isAppForegroundAndActive;
|
||||
}
|
||||
|
||||
- (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications
|
||||
|
||||
@ -51,7 +51,6 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
|
||||
@property (nonatomic) NSSet<NSString *> *blockedPhoneNumberSet;
|
||||
@property (nonatomic, readonly) NSCache<NSString *, ThreadViewModel *> *threadViewModelCache;
|
||||
@property (nonatomic) BOOL isViewVisible;
|
||||
@property (nonatomic) BOOL isAppInBackground;
|
||||
@property (nonatomic) BOOL shouldObserveDBModifications;
|
||||
@property (nonatomic) BOOL hasBeenPresented;
|
||||
|
||||
@ -131,14 +130,14 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
|
||||
selector:@selector(applicationWillEnterForeground:)
|
||||
name:OWSApplicationWillEnterForegroundNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationDidEnterBackground:)
|
||||
name:OWSApplicationDidEnterBackgroundNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationDidBecomeActive:)
|
||||
name:OWSApplicationDidBecomeActiveNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationWillResignActive:)
|
||||
name:OWSApplicationWillResignActiveNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(yapDatabaseModified:)
|
||||
name:YapDatabaseModifiedNotification
|
||||
@ -484,16 +483,10 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
|
||||
[self updateShouldObserveDBModifications];
|
||||
}
|
||||
|
||||
- (void)setIsAppInBackground:(BOOL)isAppInBackground
|
||||
{
|
||||
_isAppInBackground = isAppInBackground;
|
||||
|
||||
[self updateShouldObserveDBModifications];
|
||||
}
|
||||
|
||||
- (void)updateShouldObserveDBModifications
|
||||
{
|
||||
self.shouldObserveDBModifications = self.isViewVisible && !self.isAppInBackground;
|
||||
BOOL isAppForegroundAndActive = CurrentAppContext().reportedApplicationState == UIApplicationStateActive;
|
||||
self.shouldObserveDBModifications = self.isViewVisible && isAppForegroundAndActive;
|
||||
}
|
||||
|
||||
- (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications
|
||||
@ -550,15 +543,9 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
|
||||
|
||||
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
||||
{
|
||||
self.isAppInBackground = NO;
|
||||
[self checkIfEmptyView];
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(NSNotification *)notification
|
||||
{
|
||||
self.isAppInBackground = YES;
|
||||
}
|
||||
|
||||
- (BOOL)hasAnyMessagesWithTransaction:(YapDatabaseReadTransaction *)transaction
|
||||
{
|
||||
return [TSThread numberOfKeysInCollectionWithTransaction:transaction] > 0;
|
||||
@ -566,6 +553,8 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)notification
|
||||
{
|
||||
[self updateShouldObserveDBModifications];
|
||||
|
||||
// It's possible a thread was created while we where in the background. But since we don't honor contact
|
||||
// requests unless the app is in the foregrond, we must check again here upon becoming active.
|
||||
__block BOOL hasAnyMessages;
|
||||
@ -582,6 +571,11 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(NSNotification *)notification
|
||||
{
|
||||
[self updateShouldObserveDBModifications];
|
||||
}
|
||||
|
||||
#pragma mark - startup
|
||||
|
||||
- (NSArray<ExperienceUpgrade *> *)unseenUpgradeExperiences
|
||||
|
||||
@ -56,25 +56,31 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
[self.uiDatabaseConnection beginLongLivedReadTransaction];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationWillEnterForeground:)
|
||||
name:OWSApplicationWillEnterForegroundNotification
|
||||
selector:@selector(applicationDidBecomeActive:)
|
||||
name:OWSApplicationDidBecomeActiveNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationDidEnterBackground:)
|
||||
name:OWSApplicationDidEnterBackgroundNotification
|
||||
selector:@selector(applicationWillResignActive:)
|
||||
name:OWSApplicationWillResignActiveNotification
|
||||
object:nil];
|
||||
|
||||
self.shouldObserveDBModifications = !CurrentAppContext().isInBackground;
|
||||
[self updateShouldObserveDBModifications];
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)notification
|
||||
{
|
||||
self.shouldObserveDBModifications = YES;
|
||||
[self updateShouldObserveDBModifications];
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(NSNotification *)notification
|
||||
- (void)applicationWillResignActive:(NSNotification *)notification
|
||||
{
|
||||
self.shouldObserveDBModifications = NO;
|
||||
[self updateShouldObserveDBModifications];
|
||||
}
|
||||
|
||||
- (void)updateShouldObserveDBModifications
|
||||
{
|
||||
BOOL isAppForegroundAndActive = CurrentAppContext().reportedApplicationState == UIApplicationStateActive;
|
||||
self.shouldObserveDBModifications = isAppForegroundAndActive;
|
||||
}
|
||||
|
||||
// Don't observe database change notifications when the app is in the background.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user