Respond to CR.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-07-26 12:39:43 -04:00
parent 2e7fe5cfd5
commit d80f470c2c
2 changed files with 20 additions and 10 deletions

View File

@ -367,6 +367,8 @@ typedef enum : NSUInteger {
[self.uiDatabaseConnection beginLongLivedReadTransaction];
self.messageMappings =
[[YapDatabaseViewMappings alloc] initWithGroups:@[ thread.uniqueId ] view:TSMessageDatabaseViewExtensionName];
// We need to impose the range restrictions on the mappings immediately to avoid
// doing a great deal of unnecessary work and causing a perf hotspot.
[self updateMessageMappingRangeOptions];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.messageMappings updateWithTransaction:transaction];
@ -2237,9 +2239,7 @@ typedef enum : NSUInteger {
self.page = MIN(self.page + 1, (NSUInteger)kYapDatabaseMaxPageCount - 1);
self.shouldObserveDBModifications = NO;
[self updateShouldObserveDBModifications];
[self resetMappings];
[self.collectionView layoutSubviews];
@ -4176,10 +4176,13 @@ typedef enum : NSUInteger {
_shouldObserveDBModifications = shouldObserveDBModifications;
if (!self.shouldObserveDBModifications) {
return;
if (self.shouldObserveDBModifications) {
[self resetMappings];
}
}
- (void)resetMappings
{
// If we're entering "active" mode (e.g. view is visible and app is in foreground),
// reset all state updated by yapDatabaseModified:.
if (self.messageMappings != nil) {

View File

@ -434,10 +434,13 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
_shouldObserveDBModifications = shouldObserveDBModifications;
if (!self.shouldObserveDBModifications) {
return;
if (self.shouldObserveDBModifications) {
[self resetMappings];
}
}
- (void)resetMappings
{
// If we're entering "active" mode (e.g. view is visible and app is in foreground),
// reset all state updated by yapDatabaseModified:.
if (self.threadMappings != nil) {
@ -455,6 +458,12 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
[[self tableView] reloadData];
[self checkIfEmptyView];
[self updateInboxCountLabel];
// If the user hasn't already granted contact access
// we don't want to request until they receive a message.
if ([TSThread numberOfKeysInCollection] > 0) {
[self.contactsManager requestSystemContactsOnce];
}
}
- (void)applicationWillEnterForeground:(NSNotification *)notification
@ -836,13 +845,11 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
{
OWSAssert([NSThread isMainThread]);
self.shouldObserveDBModifications = NO;
self.threadMappings = [[YapDatabaseViewMappings alloc] initWithGroups:@[ self.currentGrouping ]
view:TSThreadDatabaseViewExtensionName];
[self.threadMappings setIsReversed:YES forGroup:self.currentGrouping];
[self updateShouldObserveDBModifications];
[self resetMappings];
[[self tableView] reloadData];
[self checkIfEmptyView];