From 49196f8013c3a01f779caad3c5936ca97135de60 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 15 Dec 2017 16:31:26 -0500 Subject: [PATCH] Spin activity indicator until contacts are fetched // FREEBIE --- .../ViewControllers/NewContactThreadViewController.m | 10 +++++++--- Signal/src/contact/OWSContactsManager.h | 4 +++- Signal/src/contact/OWSContactsManager.m | 5 +++-- Signal/src/contact/SystemContactsFetcher.swift | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Signal/src/ViewControllers/NewContactThreadViewController.m b/Signal/src/ViewControllers/NewContactThreadViewController.m index 8f0f759c0..137228bcf 100644 --- a/Signal/src/ViewControllers/NewContactThreadViewController.m +++ b/Signal/src/ViewControllers/NewContactThreadViewController.m @@ -147,9 +147,13 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert([NSThread isMainThread]); - [self.contactsViewHelper.contactsManager fetchSystemContactsIfAlreadyAuthorizedAndAlwaysNotify]; - - [refreshControl endRefreshing]; + [self.contactsViewHelper.contactsManager + fetchSystemContactsIfAlreadyAuthorizedAndAlwaysNotifyWithCompletion:^(NSError *_Nullable error) { + if (error) { + DDLogError(@"%@ refreshing contacts failed with error: %@", self.logTag, error); + } + [refreshControl endRefreshing]; + }]; } - (void)showContactsPermissionReminder:(BOOL)isVisible diff --git a/Signal/src/contact/OWSContactsManager.h b/Signal/src/contact/OWSContactsManager.h index e26cf05a4..01d56dc35 100644 --- a/Signal/src/contact/OWSContactsManager.h +++ b/Signal/src/contact/OWSContactsManager.h @@ -52,9 +52,11 @@ 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)fetchSystemContactsOnceIfAlreadyAuthorized; + // This variant will fetch system contacts if contact access has already been granted, // but not prompt for contact access. Also, it will always fire a notification. -- (void)fetchSystemContactsIfAlreadyAuthorizedAndAlwaysNotify; +- (void)fetchSystemContactsIfAlreadyAuthorizedAndAlwaysNotifyWithCompletion: + (void (^)(NSError *_Nullable error))completionHandler; #pragma mark - Util diff --git a/Signal/src/contact/OWSContactsManager.m b/Signal/src/contact/OWSContactsManager.m index 2a5dffbd0..ac3c27a7a 100644 --- a/Signal/src/contact/OWSContactsManager.m +++ b/Signal/src/contact/OWSContactsManager.m @@ -95,9 +95,10 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification [self.systemContactsFetcher fetchOnceIfAlreadyAuthorized]; } -- (void)fetchSystemContactsIfAlreadyAuthorizedAndAlwaysNotify +- (void)fetchSystemContactsIfAlreadyAuthorizedAndAlwaysNotifyWithCompletion: + (void (^)(NSError *_Nullable error))completionHandler { - [self.systemContactsFetcher fetchIfAlreadyAuthorizedAndAlwaysNotify]; + [self.systemContactsFetcher fetchIfAlreadyAuthorizedAndAlwaysNotifyWithCompletion:completionHandler]; } - (BOOL)isSystemContactsAuthorized diff --git a/Signal/src/contact/SystemContactsFetcher.swift b/Signal/src/contact/SystemContactsFetcher.swift index 75ab49e14..b1621c57f 100644 --- a/Signal/src/contact/SystemContactsFetcher.swift +++ b/Signal/src/contact/SystemContactsFetcher.swift @@ -434,13 +434,13 @@ class SystemContactsFetcher: NSObject { updateContacts(completion: nil, alwaysNotify: false) } - public func fetchIfAlreadyAuthorizedAndAlwaysNotify() { + public func fetchIfAlreadyAuthorizedAndAlwaysNotify(completion: ((Error?) -> Void)?) { AssertIsOnMainThread() guard authorizationStatus == .authorized else { return } - updateContacts(completion: nil, alwaysNotify: true) + updateContacts(completion: completion, alwaysNotify: true) } private func updateContacts(completion completionParam: ((Error?) -> Void)?, alwaysNotify: Bool = false) {