From d80f470c2c64ab44f93d28c9d20c1a5bc836fd72 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 26 Jul 2017 12:39:43 -0400 Subject: [PATCH] Respond to CR. // FREEBIE --- .../ConversationView/MessagesViewController.m | 13 ++++++++----- .../src/ViewControllers/SignalsViewController.m | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index 3ad5cc0d1..31391808b 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -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) { diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index a0dba6096..8758a42ed 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -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];