From 6ab48cec9715f9f99fea7fe5fb1027e9edeecea7 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 26 Apr 2018 15:41:31 -0400 Subject: [PATCH] Only show archived threads UI if there are archived threads. --- .../HomeView/HomeViewController.m | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index 7d579a5d9..8aa664b2d 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -630,7 +630,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSInteger result = (NSInteger)[self.threadMappings numberOfItemsInSection:(NSUInteger)section]; - if (self.homeViewMode == HomeViewMode_Inbox) { + if (self.homeViewMode == HomeViewMode_Inbox && self.numberOfArchivedThreads > 0) { // Add the "archived conversations" row. result++; } @@ -1173,17 +1173,32 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations [self.tableView endUpdates]; } -- (void)checkIfEmptyView +- (NSUInteger)numberOfThreadsInGroup:(NSString *)group { // We need to consult the db view, not the mapping since the mapping only knows about // the current group. - __block NSUInteger inboxCount; - __block NSUInteger archiveCount; + __block NSUInteger result; [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { YapDatabaseViewTransaction *viewTransaction = [transaction ext:TSThreadDatabaseViewExtensionName]; - inboxCount = [viewTransaction numberOfItemsInGroup:TSInboxGroup]; - archiveCount = [viewTransaction numberOfItemsInGroup:TSArchiveGroup]; + result = [viewTransaction numberOfItemsInGroup:group]; }]; + return result; +} + +- (NSUInteger)numberOfInboxThreads +{ + return [self numberOfThreadsInGroup:TSInboxGroup]; +} + +- (NSUInteger)numberOfArchivedThreads +{ + return [self numberOfThreadsInGroup:TSArchiveGroup]; +} + +- (void)checkIfEmptyView +{ + NSUInteger inboxCount = self.numberOfInboxThreads; + NSUInteger archiveCount = self.numberOfArchivedThreads; if (self.homeViewMode == HomeViewMode_Inbox && inboxCount == 0 && archiveCount == 0) { [self updateEmptyBoxText];