From 646073c92d43ae1af6de0c10d8ea96124d954c2e Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 6 Jun 2018 13:21:52 -0600 Subject: [PATCH] Check contacts access when notified of contacts changes. --- .../contacts/SystemContactsFetcher.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/SignalMessaging/contacts/SystemContactsFetcher.swift b/SignalMessaging/contacts/SystemContactsFetcher.swift index b85abc582..bf81a13a2 100644 --- a/SignalMessaging/contacts/SystemContactsFetcher.swift +++ b/SignalMessaging/contacts/SystemContactsFetcher.swift @@ -175,7 +175,7 @@ public class SystemContactsFetcher: NSObject { hasSetupObservation = true self.contactStoreAdapter.startObservingChanges { [weak self] in DispatchQueue.main.async { - self?.updateContacts(completion: nil, isUserRequested: false) + self?.refreshAfterContactsChange() } } } @@ -256,6 +256,7 @@ public class SystemContactsFetcher: NSObject { @objc public func userRequestedRefresh(completion: @escaping (Error?) -> Void) { SwiftAssertIsOnMainThread(#function) + guard authorizationStatus == .authorized else { owsFail("should have already requested contact access") self.delegate?.systemContactsFetcher(self, hasAuthorizationStatus: authorizationStatus) @@ -266,6 +267,19 @@ public class SystemContactsFetcher: NSObject { updateContacts(completion: completion, isUserRequested: true) } + @objc + public func refreshAfterContactsChange() { + SwiftAssertIsOnMainThread(#function) + + guard authorizationStatus == .authorized else { + Logger.info("\(logTag) ignoring contacts change; no access.") + self.delegate?.systemContactsFetcher(self, hasAuthorizationStatus: authorizationStatus) + return + } + + updateContacts(completion: nil, isUserRequested: false) + } + private func updateContacts(completion completionParam: ((Error?) -> Void)?, isUserRequested: Bool = false) { SwiftAssertIsOnMainThread(#function)