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)