From 3f805cd4cd0406e6d70bf2092ef13927e681b6fd Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 14 Jul 2017 13:20:00 -0400 Subject: [PATCH 1/5] =?UTF-8?q?Add=20possible=20fixes=20for=20the=20?= =?UTF-8?q?=E2=80=98empty=20home=20view=E2=80=99=20issue.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Signal/src/ViewControllers/SignalsViewController.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index 9311f50f4..a8cf33d44 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -364,7 +364,6 @@ [self updateInboxCountLabel]; self.isViewVisible = YES; - [self checkIfEmptyView]; // When returning to home view, try to ensure that the "last" thread is still // visible. The threads often change ordering while in conversation view due @@ -384,6 +383,8 @@ animated:NO]; } } + + [self checkIfEmptyView]; } - (void)viewWillDisappear:(BOOL)animated @@ -438,6 +439,8 @@ } else { [[NSNotificationCenter defaultCenter] removeObserver:self name:YapDatabaseModifiedNotification object:nil]; } + + [self checkIfEmptyView]; } - (void)applicationWillEnterForeground:(NSNotification *)notification @@ -846,6 +849,7 @@ [self updateInboxCountLabel]; if ([sectionChanges count] == 0 && [rowChanges count] == 0) { + [self checkIfEmptyView]; return; } @@ -902,6 +906,13 @@ [self checkIfEmptyView]; } +- (void)setViewingThreadsIn:(CellState)viewingThreadsIn +{ + _viewingThreadsIn = viewingThreadsIn; + + [self checkIfEmptyView]; +} + - (void)checkIfEmptyView { [_tableView setHidden:NO]; [_emptyBoxLabel setHidden:NO]; From f52814bb705a7e4d9fc1bb747ce402a24be810f1 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 14 Jul 2017 13:34:24 -0400 Subject: [PATCH 2/5] =?UTF-8?q?Add=20possible=20fixes=20for=20the=20?= =?UTF-8?q?=E2=80=98empty=20home=20view=E2=80=99=20issue.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- .../ViewControllers/SignalsViewController.m | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index a8cf33d44..e35be38d9 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -415,29 +415,35 @@ - (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications { - if (!_shouldObserveDBModifications && shouldObserveDBModifications && self.threadMappings != nil) { - // Before we begin observing database modifications, make sure - // our mapping and table state is up-to-date. - // - // We need to `beginLongLivedReadTransaction` before we update our - // mapping in order to jump to the most recent commit. - [self.uiDatabaseConnection beginLongLivedReadTransaction]; - [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - [self.threadMappings updateWithTransaction:transaction]; - }]; + _shouldObserveDBModifications = shouldObserveDBModifications; + + [self ensureObserveDBModifications]; +} + +- (void)ensureObserveDBModifications +{ + if (self.shouldObserveDBModifications) { + if (self.threadMappings != nil) { + // Before we begin observing database modifications, make sure + // our mapping and table state is up-to-date. + // + // We need to `beginLongLivedReadTransaction` before we update our + // mapping in order to jump to the most recent commit. + [self.uiDatabaseConnection beginLongLivedReadTransaction]; + [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + [self.threadMappings updateWithTransaction:transaction]; + }]; + } [[self tableView] reloadData]; } - _shouldObserveDBModifications = shouldObserveDBModifications; - - if (shouldObserveDBModifications) { + [[NSNotificationCenter defaultCenter] removeObserver:self name:YapDatabaseModifiedNotification object:nil]; + if (self.shouldObserveDBModifications) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yapDatabaseModified:) name:YapDatabaseModifiedNotification object:nil]; - } else { - [[NSNotificationCenter defaultCenter] removeObserver:self name:YapDatabaseModifiedNotification object:nil]; } [self checkIfEmptyView]; From 90dabe1c817c91476e80f136bfe1c2a3e30684a6 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 14 Jul 2017 13:43:36 -0400 Subject: [PATCH 3/5] =?UTF-8?q?Add=20possible=20fixes=20for=20the=20?= =?UTF-8?q?=E2=80=98empty=20home=20view=E2=80=99=20issue.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- .../ViewControllers/SignalsViewController.m | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index e35be38d9..a96ea5ad0 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -125,6 +125,10 @@ selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(yapDatabaseModified:) + name:YapDatabaseModifiedNotification + object:nil]; } - (void)dealloc @@ -415,43 +419,39 @@ - (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications { - _shouldObserveDBModifications = shouldObserveDBModifications; - - [self ensureObserveDBModifications]; -} + if (_shouldObserveDBModifications == shouldObserveDBModifications) { + return; + } -- (void)ensureObserveDBModifications -{ - if (self.shouldObserveDBModifications) { - if (self.threadMappings != nil) { - // Before we begin observing database modifications, make sure - // our mapping and table state is up-to-date. - // - // We need to `beginLongLivedReadTransaction` before we update our - // mapping in order to jump to the most recent commit. - [self.uiDatabaseConnection beginLongLivedReadTransaction]; - [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - [self.threadMappings updateWithTransaction:transaction]; - }]; - } + _shouldObserveDBModifications = shouldObserveDBModifications; - [[self tableView] reloadData]; + if (!self.shouldObserveDBModifications) { + return; } - [[NSNotificationCenter defaultCenter] removeObserver:self name:YapDatabaseModifiedNotification object:nil]; - if (self.shouldObserveDBModifications) { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(yapDatabaseModified:) - name:YapDatabaseModifiedNotification - object:nil]; + // 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) { + // Before we begin observing database modifications, make sure + // our mapping and table state is up-to-date. + // + // We need to `beginLongLivedReadTransaction` before we update our + // mapping in order to jump to the most recent commit. + [self.uiDatabaseConnection beginLongLivedReadTransaction]; + [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + [self.threadMappings updateWithTransaction:transaction]; + }]; } + [[self tableView] reloadData]; [self checkIfEmptyView]; + [self updateInboxCountLabel]; } - (void)applicationWillEnterForeground:(NSNotification *)notification { self.isAppInBackground = NO; + [self checkIfEmptyView]; } - (void)applicationDidEnterBackground:(NSNotification *)notification @@ -845,6 +845,10 @@ [self.contactsManager requestSystemContactsOnce]; } + if (!self.shouldObserveDBModifications) { + return; + } + [[self.uiDatabaseConnection ext:TSThreadDatabaseViewExtensionName] getSectionChanges:§ionChanges rowChanges:&rowChanges forNotifications:notifications @@ -855,6 +859,9 @@ [self updateInboxCountLabel]; if ([sectionChanges count] == 0 && [rowChanges count] == 0) { + [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + [self.threadMappings updateWithTransaction:transaction]; + }]; [self checkIfEmptyView]; return; } From b6264383d35620980a9f7dc80e84545b0635cdc8 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 14 Jul 2017 14:06:19 -0400 Subject: [PATCH 4/5] =?UTF-8?q?Add=20possible=20fixes=20for=20the=20?= =?UTF-8?q?=E2=80=98empty=20home=20view=E2=80=99=20issue.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- .../src/ViewControllers/InboxTableViewCell.h | 2 - .../ViewControllers/SignalsViewController.m | 43 +++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Signal/src/ViewControllers/InboxTableViewCell.h b/Signal/src/ViewControllers/InboxTableViewCell.h index 7a1f5737c..c56e286bc 100644 --- a/Signal/src/ViewControllers/InboxTableViewCell.h +++ b/Signal/src/ViewControllers/InboxTableViewCell.h @@ -10,8 +10,6 @@ NS_ASSUME_NONNULL_BEGIN @class OWSContactsManager; @class AvatarImageView; -typedef enum : NSUInteger { kArchiveState = 0, kInboxState = 1 } CellState; - @interface InboxTableViewCell : UITableViewCell @property (nonatomic) IBOutlet UILabel *nameLabel; diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index a96ea5ad0..a584f3922 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -30,6 +30,8 @@ #define CELL_HEIGHT 72.0f +typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; + @interface SignalsViewController () @property (nonatomic) UITableView *tableView; @@ -175,7 +177,7 @@ @"INBOX_VIEW_ARCHIVE_MODE_REMINDER", @"Label reminding the user that they are in archive mode."); __weak SignalsViewController *weakSelf = self; archiveReminderView.tapAction = ^{ - [weakSelf selectedInbox]; + [weakSelf showInboxGrouping]; }; [self.view addSubview:archiveReminderView]; [archiveReminderView autoPinWidthToSuperview]; @@ -239,7 +241,7 @@ // Create the database connection. [self uiDatabaseConnection]; - [self selectedInbox]; + [self showInboxGrouping]; self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[ NSLocalizedString(@"WHISPER_NAV_BAR_TITLE", nil), @@ -349,9 +351,9 @@ - (void)swappedSegmentedControl { if (self.segmentedControl.selectedSegmentIndex == 0) { - [self selectedInbox]; + [self showInboxGrouping]; } else { - [self selectedArchive]; + [self showArchiveGrouping]; } } @@ -423,6 +425,11 @@ return; } + DDLogDebug(@"%@ shouldObserveDBModifications: %d -> %d", + self.tag, + _shouldObserveDBModifications, + shouldObserveDBModifications); + _shouldObserveDBModifications = shouldObserveDBModifications; if (!self.shouldObserveDBModifications) { @@ -793,18 +800,27 @@ #pragma mark - Groupings -- (void)selectedInbox +- (void)showInboxGrouping { - self.segmentedControl.selectedSegmentIndex = 0; self.viewingThreadsIn = kInboxState; - [self changeToGrouping:TSInboxGroup]; } -- (void)selectedArchive +- (void)showArchiveGrouping { - self.segmentedControl.selectedSegmentIndex = 1; self.viewingThreadsIn = kArchiveState; - [self changeToGrouping:TSArchiveGroup]; +} + +- (void)setViewingThreadsIn:(CellState)viewingThreadsIn +{ + BOOL didChange = _viewingThreadsIn != viewingThreadsIn; + _viewingThreadsIn = viewingThreadsIn; + self.segmentedControl.selectedSegmentIndex = (viewingThreadsIn == kInboxState ? 0 : 1); + if (didChange || !self.threadMappings) { + [self changeToGrouping:(viewingThreadsIn == kInboxState ? TSInboxGroup : TSArchiveGroup)]; + } else { + [self checkIfEmptyView]; + [self updateReminderViews]; + } } - (void)changeToGrouping:(NSString *)grouping { @@ -919,13 +935,6 @@ [self checkIfEmptyView]; } -- (void)setViewingThreadsIn:(CellState)viewingThreadsIn -{ - _viewingThreadsIn = viewingThreadsIn; - - [self checkIfEmptyView]; -} - - (void)checkIfEmptyView { [_tableView setHidden:NO]; [_emptyBoxLabel setHidden:NO]; From d36e60b0e984e003d447503a69267b9cbf071a76 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 14 Jul 2017 14:14:41 -0400 Subject: [PATCH 5/5] Respond to CR. // FREEBIE --- .../ConversationView/MessagesViewController.m | 4 ---- Signal/src/ViewControllers/SignalsViewController.m | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index 73a046098..bf4a25a6d 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -3319,10 +3319,6 @@ typedef enum : NSUInteger { // may need to extend the mapping's contents to reflect the current // range. [self updateMessageMappingRangeOptions]; - - [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - [self.messageMappings updateWithTransaction:transaction]; - }]; [self resetContentAndLayout]; return; diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index a584f3922..887af45f8 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -873,12 +873,9 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; // We want this regardless of if we're currently viewing the archive. // So we run it before the early return [self updateInboxCountLabel]; + [self checkIfEmptyView]; if ([sectionChanges count] == 0 && [rowChanges count] == 0) { - [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - [self.threadMappings updateWithTransaction:transaction]; - }]; - [self checkIfEmptyView]; return; } @@ -932,7 +929,6 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; } [self.tableView endUpdates]; - [self checkIfEmptyView]; } - (void)checkIfEmptyView {