From 3aa90451f11095c43f323bf958ef783a76b81129 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 6 Sep 2017 14:30:06 -0400 Subject: [PATCH 1/2] Restore pull-to-refresh in the "new contact thread" view. // FREEBIE --- .../NewContactThreadViewController.m | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Signal/src/ViewControllers/NewContactThreadViewController.m b/Signal/src/ViewControllers/NewContactThreadViewController.m index f0e480581..a31a6ec6f 100644 --- a/Signal/src/ViewControllers/NewContactThreadViewController.m +++ b/Signal/src/ViewControllers/NewContactThreadViewController.m @@ -113,9 +113,25 @@ NS_ASSUME_NONNULL_BEGIN [self.noSignalContactsView autoPinEdgeToSuperviewEdge:ALEdgeTop]; [self.noSignalContactsView autoPinToBottomLayoutGuideOfViewController:self withInset:0]; + UIRefreshControl *pullToRefreshView = [UIRefreshControl new]; + pullToRefreshView.tintColor = [UIColor grayColor]; + [pullToRefreshView addTarget:self + action:@selector(pullToRefreshPerformed:) + forControlEvents:UIControlEventValueChanged]; + [self.tableViewController.tableView insertSubview:pullToRefreshView atIndex:0]; + [self updateTableContents]; } +- (void)pullToRefreshPerformed:(UIRefreshControl *)refreshControl +{ + OWSAssert([NSThread isMainThread]); + + [self.contactsViewHelper.contactsManager requestSystemContactsOnce]; + + [refreshControl endRefreshing]; +} + - (void)showContactsPermissionReminder:(BOOL)isVisible { _hideContactsPermissionReminderViewConstraint.active = !isVisible; @@ -789,6 +805,18 @@ NS_ASSUME_NONNULL_BEGIN } } +#pragma mark - Logging + ++ (NSString *)tag +{ + return [NSString stringWithFormat:@"[%@]", self.class]; +} + +- (NSString *)tag +{ + return self.class.tag; +} + @end NS_ASSUME_NONNULL_END From 563753a4cb735ad0818402fb6f1d6b84078b2fdc Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 11 Sep 2017 10:53:28 -0400 Subject: [PATCH 2/2] Force contacts intersection in pull-to-refresh from new thread view. // FREEBIE --- .../src/ViewControllers/NewContactThreadViewController.m | 2 +- Signal/src/contact/OWSContactsManager.h | 1 + Signal/src/contact/OWSContactsManager.m | 7 ++++++- Signal/src/contact/SystemContactsFetcher.swift | 9 ++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Signal/src/ViewControllers/NewContactThreadViewController.m b/Signal/src/ViewControllers/NewContactThreadViewController.m index a31a6ec6f..f3cbcbfcb 100644 --- a/Signal/src/ViewControllers/NewContactThreadViewController.m +++ b/Signal/src/ViewControllers/NewContactThreadViewController.m @@ -127,7 +127,7 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert([NSThread isMainThread]); - [self.contactsViewHelper.contactsManager requestSystemContactsOnce]; + [self.contactsViewHelper.contactsManager fetchSystemContactsIfAlreadyAuthorizedAndIgnoreDebounce]; [refreshControl endRefreshing]; } diff --git a/Signal/src/contact/OWSContactsManager.h b/Signal/src/contact/OWSContactsManager.h index 8d8e09a7c..505fa70fb 100644 --- a/Signal/src/contact/OWSContactsManager.h +++ b/Signal/src/contact/OWSContactsManager.h @@ -55,6 +55,7 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification; // Ensure's the app has the latest contacts, but won't prompt the user for contact // access if they haven't granted it. - (void)fetchSystemContactsIfAlreadyAuthorized; +- (void)fetchSystemContactsIfAlreadyAuthorizedAndIgnoreDebounce; #pragma mark - Util diff --git a/Signal/src/contact/OWSContactsManager.m b/Signal/src/contact/OWSContactsManager.m index 53669efd0..398b17b3c 100644 --- a/Signal/src/contact/OWSContactsManager.m +++ b/Signal/src/contact/OWSContactsManager.m @@ -80,7 +80,12 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account - (void)fetchSystemContactsIfAlreadyAuthorized { - [self.systemContactsFetcher fetchIfAlreadyAuthorized]; + [self.systemContactsFetcher fetchIfAlreadyAuthorizedWithIgnoreDebounce:NO]; +} + +- (void)fetchSystemContactsIfAlreadyAuthorizedAndIgnoreDebounce +{ + [self.systemContactsFetcher fetchIfAlreadyAuthorizedWithIgnoreDebounce:YES]; } - (BOOL)isSystemContactsAuthorized diff --git a/Signal/src/contact/SystemContactsFetcher.swift b/Signal/src/contact/SystemContactsFetcher.swift index 41408e855..80aac269a 100644 --- a/Signal/src/contact/SystemContactsFetcher.swift +++ b/Signal/src/contact/SystemContactsFetcher.swift @@ -417,16 +417,16 @@ class SystemContactsFetcher: NSObject { } } - public func fetchIfAlreadyAuthorized() { + public func fetchIfAlreadyAuthorized(ignoreDebounce: Bool = false) { AssertIsOnMainThread() guard authorizationStatus == .authorized else { return } - updateContacts(completion: nil) + updateContacts(completion: nil, ignoreDebounce:ignoreDebounce) } - private func updateContacts(completion: ((Error?) -> Void)?) { + private func updateContacts(completion: ((Error?) -> Void)?, ignoreDebounce: Bool = false) { AssertIsOnMainThread() systemContactsHaveBeenRequestedAtLeastOnce = true @@ -457,6 +457,9 @@ class SystemContactsFetcher: NSObject { if self.lastContactUpdateHash != contactsHash { Logger.info("\(self.TAG) contact hash changed. new contactsHash: \(contactsHash)") shouldNotifyDelegate = true + } else if ignoreDebounce { + Logger.info("\(self.TAG) ignoring debounce.") + shouldNotifyDelegate = true } else { // If nothing has changed, only notify delegate (to perform contact intersection) every N hours