diff --git a/Signal/src/ViewControllers/ContactsViewHelper.m b/Signal/src/ViewControllers/ContactsViewHelper.m index b82027320..080e7468f 100644 --- a/Signal/src/ViewControllers/ContactsViewHelper.m +++ b/Signal/src/ViewControllers/ContactsViewHelper.m @@ -303,6 +303,13 @@ NS_ASSUME_NONNULL_BEGIN { SignalAccount *signalAccount = [self signalAccountForRecipientId:recipientId]; + if (!self.contactsManager.supportsContactEditing) { + DDLogError(@"%@ Contact editing not supported.", self.tag); + // Should not expose UI that lets the user get here. + OWSAssert(NO); + return; + } + if (!self.contactsManager.isSystemContactsAuthorized) { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_TITLE", comment @@ -384,6 +391,18 @@ NS_ASSUME_NONNULL_BEGIN [UIUtil applyDefaultSystemAppearence]; } +#pragma mark - Logging + ++ (NSString *)tag +{ + return [NSString stringWithFormat:@"[%@]", self.class]; +} + +- (NSString *)tag +{ + return self.class.tag; +} + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m index 745473da8..3c7543ba7 100644 --- a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m +++ b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m @@ -136,7 +136,7 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert(self.thread); - if ([self.thread isKindOfClass:[TSContactThread class]]) { + if ([self.thread isKindOfClass:[TSContactThread class]] && self.contactsManager.supportsContactEditing) { self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"EDIT_TXT", nil) style:UIBarButtonItemStylePlain @@ -677,6 +677,10 @@ NS_ASSUME_NONNULL_BEGIN - (void)presentContactViewController { + if (!self.contactsManager.supportsContactEditing) { + DDLogWarn(@"%@ Contact editing not supported", self.tag); + return; + } if (![self.thread isKindOfClass:[TSContactThread class]]) { DDLogError(@"%@ unexpected thread: %@ in %s", self.tag, self.thread, __PRETTY_FUNCTION__); OWSAssert(NO); diff --git a/Signal/src/ViewControllers/ShowGroupMembersViewController.m b/Signal/src/ViewControllers/ShowGroupMembersViewController.m index dd31b5017..bf1f89134 100644 --- a/Signal/src/ViewControllers/ShowGroupMembersViewController.m +++ b/Signal/src/ViewControllers/ShowGroupMembersViewController.m @@ -156,15 +156,18 @@ NS_ASSUME_NONNULL_BEGIN UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; - NSString *contactInfoTitle = signalAccount - ? NSLocalizedString(@"GROUP_MEMBERS_VIEW_CONTACT_INFO", @"Button label for the 'show contact info' button") - : NSLocalizedString( - @"GROUP_MEMBERS_ADD_CONTACT_INFO", @"Button label to add information to an unknown contact"); - [actionSheetController addAction:[UIAlertAction actionWithTitle:contactInfoTitle - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *_Nonnull action) { - [self showContactInfoViewForRecipientId:recipientId]; - }]]; + if (self.contactsViewHelper.contactsManager.supportsContactEditing) { + NSString *contactInfoTitle = signalAccount + ? NSLocalizedString(@"GROUP_MEMBERS_VIEW_CONTACT_INFO", @"Button label for the 'show contact info' button") + : NSLocalizedString( + @"GROUP_MEMBERS_ADD_CONTACT_INFO", @"Button label to add information to an unknown contact"); + [actionSheetController addAction:[UIAlertAction actionWithTitle:contactInfoTitle + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *_Nonnull action) { + [self + showContactInfoViewForRecipientId:recipientId]; + }]]; + } BOOL isBlocked; if (signalAccount) { diff --git a/Signal/src/contact/OWSContactsManager.h b/Signal/src/contact/OWSContactsManager.h index 5b6ba75f2..4e08812cd 100644 --- a/Signal/src/contact/OWSContactsManager.h +++ b/Signal/src/contact/OWSContactsManager.h @@ -36,6 +36,8 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification; // Must call `requestSystemContactsOnce` before accessing this method @property (nonatomic, readonly) BOOL isSystemContactsAuthorized; +@property (nonatomic, readonly) BOOL supportsContactEditing; + // Request systems contacts and start syncing changes. The user will see an alert // if they haven't previously. - (void)requestSystemContactsOnce; diff --git a/Signal/src/contact/OWSContactsManager.m b/Signal/src/contact/OWSContactsManager.m index 84e05a5d2..fc1edf8c0 100644 --- a/Signal/src/contact/OWSContactsManager.m +++ b/Signal/src/contact/OWSContactsManager.m @@ -73,6 +73,11 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification = return self.systemContactsFetcher.isAuthorized; } +- (BOOL)supportsContactEditing +{ + return self.systemContactsFetcher.supportsContactEditing; +} + #pragma mark SystemContactsFetcherDelegate - (void)systemContactsFetcher:(SystemContactsFetcher *)systemsContactsFetcher diff --git a/Signal/src/contact/SystemContactsFetcher.swift b/Signal/src/contact/SystemContactsFetcher.swift index f68b9e316..f0357fa96 100644 --- a/Signal/src/contact/SystemContactsFetcher.swift +++ b/Signal/src/contact/SystemContactsFetcher.swift @@ -13,6 +13,7 @@ enum Result { protocol ContactStoreAdaptee { var authorizationStatus: ContactStoreAuthorizationStatus { get } + var supportsContactEditing: Bool { get } func requestAccess(completionHandler: @escaping (Bool, Error?) -> Void) func fetchContacts() -> Result<[Contact], Error> func startObservingChanges(changeHandler: @escaping () -> Void) @@ -24,6 +25,7 @@ class ContactsFrameworkContactStoreAdaptee: ContactStoreAdaptee { private let contactStore = CNContactStore() private var changeHandler: (() -> Void)? private var initializedObserver = false + let supportsContactEditing = true private let allowedContactKeys: [CNKeyDescriptor] = [ CNContactFormatter.descriptorForRequiredKeys(for: .fullName), @@ -95,6 +97,7 @@ class AddressBookContactStoreAdaptee: ContactStoreAdaptee { private var addressBook: ABAddressBook = ABAddressBookCreateWithOptions(nil, nil).takeRetainedValue() private var changeHandler: (() -> Void)? + let supportsContactEditing = false var authorizationStatus: ContactStoreAuthorizationStatus { switch ABAddressBookGetAuthorizationStatus() { @@ -265,6 +268,7 @@ enum ContactStoreAuthorizationStatus { } class ContactStoreAdapter: ContactStoreAdaptee { + let adaptee: ContactStoreAdaptee init() { @@ -275,6 +279,10 @@ class ContactStoreAdapter: ContactStoreAdaptee { } } + var supportsContactEditing: Bool { + return self.adaptee.supportsContactEditing + } + var authorizationStatus: ContactStoreAuthorizationStatus { return self.adaptee.authorizationStatus }