diff --git a/Signal/src/ViewControllers/HomeView/Chat List/ChatListViewController.m b/Signal/src/ViewControllers/HomeView/Chat List/ChatListViewController.m index ab41b9b652..b0be362f81 100644 --- a/Signal/src/ViewControllers/HomeView/Chat List/ChatListViewController.m +++ b/Signal/src/ViewControllers/HomeView/Chat List/ChatListViewController.m @@ -189,13 +189,7 @@ NSString *const kArchiveButtonPseudoGroup = @"kArchiveButtonPseudoGroup"; self.firstConversationCueView.accessibilityIdentifier = @"ChatListViewController.firstConversationCueView"; self.firstConversationLabel.accessibilityIdentifier = @"ChatListViewController.firstConversationLabel"; - UIRefreshControl *pullToRefreshView = [UIRefreshControl new]; - pullToRefreshView.tintColor = [UIColor grayColor]; - [pullToRefreshView addTarget:self - action:@selector(pullToRefreshPerformed:) - forControlEvents:UIControlEventValueChanged]; - self.tableView.refreshControl = pullToRefreshView; - pullToRefreshView.accessibilityIdentifier = @"ChatListViewController.pullToRefreshView"; + [self addPullToRefreshIfNeeded]; } - (UIView *)createEmptyInboxView @@ -711,27 +705,6 @@ NSString *const kArchiveButtonPseudoGroup = @"kArchiveButtonPseudoGroup"; [self ensureSelectedThread:thread animated:animated]; } -#pragma mark - - -- (void)pullToRefreshPerformed:(UIRefreshControl *)refreshControl -{ - OWSAssertIsOnMainThread(); - OWSLogInfo(@"beginning refreshing."); - - [self.messageFetcherJob runObjc] - .then(^(id value) { - if (TSAccountManager.shared.isRegisteredPrimaryDevice) { - return [AnyPromise promiseWithValue:@1]; - } - - return [SSKEnvironment.shared.syncManager sendAllSyncRequestMessagesWithTimeout:20]; - }) - .ensure(^{ - OWSLogInfo(@"ending refreshing."); - [refreshControl endRefreshing]; - }); -} - #pragma mark - UISearchBarDelegate - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar diff --git a/Signal/src/ViewControllers/HomeView/Chat List/ChatListViewController.swift b/Signal/src/ViewControllers/HomeView/Chat List/ChatListViewController.swift index d35428fe9c..cb505085a9 100644 --- a/Signal/src/ViewControllers/HomeView/Chat List/ChatListViewController.swift +++ b/Signal/src/ViewControllers/HomeView/Chat List/ChatListViewController.swift @@ -80,6 +80,29 @@ public extension ChatListViewController { // MARK: - + func addPullToRefreshIfNeeded() { + if tsAccountManager.isPrimaryDevice { + return + } + + let pullToRefreshView = UIRefreshControl() + pullToRefreshView.tintColor = .gray + pullToRefreshView.addTarget(self, action: #selector(pullToRefreshPerformed), for: .valueChanged) + pullToRefreshView.accessibilityIdentifier = "ChatListViewController.pullToRefreshView" + self.tableView.refreshControl = pullToRefreshView + } + + private func pullToRefreshPerformed(_ refreshControl: UIRefreshControl) { + AssertIsOnMainThread() + owsAssert(!tsAccountManager.isPrimaryDevice) + + syncManager.sendAllSyncRequestMessages(timeout: 20).ensure { + refreshControl.endRefreshing() + }.cauterize() + } + + // MARK: - + func showBadgeExpirationSheetIfNeeded() { Logger.info("[Donations] Checking whether we should show badge expiration sheet...")