From 5c66e5584cb1173eee10b3d3008e4165d855dac1 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 18 Jul 2017 15:38:06 -0400 Subject: [PATCH 1/2] Adding to existing contact requires contact access Previously we'd show an empty "list" of existing contacts. // FREEBIE --- .../src/ViewControllers/ContactsViewHelper.h | 4 ++ .../src/ViewControllers/ContactsViewHelper.m | 55 ++++++++++--------- ...SConversationSettingsTableViewController.m | 24 +++++++- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/Signal/src/ViewControllers/ContactsViewHelper.h b/Signal/src/ViewControllers/ContactsViewHelper.h index 4e49cc72d..4077b6ccb 100644 --- a/Signal/src/ViewControllers/ContactsViewHelper.h +++ b/Signal/src/ViewControllers/ContactsViewHelper.h @@ -46,6 +46,10 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSArray *blockedPhoneNumbers; +// Suitable to display when the user tries to perform an action which is not possible due to the user having +// previously denied contact access. +@property (nonatomic, readonly) UIAlertController *missingContactAccessAlertController; + - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithDelegate:(id)delegate; diff --git a/Signal/src/ViewControllers/ContactsViewHelper.m b/Signal/src/ViewControllers/ContactsViewHelper.m index 5bd8198cd..2069624e0 100644 --- a/Signal/src/ViewControllers/ContactsViewHelper.m +++ b/Signal/src/ViewControllers/ContactsViewHelper.m @@ -297,6 +297,35 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Editing +- (UIAlertController *)missingContactAccessAlertController +{ + UIAlertController *alertController = [UIAlertController + alertControllerWithTitle:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_TITLE", comment + : @"Alert title for when the user has just tried to edit a " + @"contacts after declining to give Signal contacts " + @"permissions") + message:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_BODY", comment + : @"Alert body for when the user has just tried to edit a " + @"contacts after declining to give Signal contacts " + @"permissions") + preferredStyle:UIAlertControllerStyleAlert]; + + [alertController + addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"AB_PERMISSION_MISSING_ACTION_NOT_NOW", + @"Button text to dismiss missing contacts permission alert") + style:UIAlertActionStyleCancel + handler:nil]]; + + [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OPEN_SETTINGS_BUTTON", + @"Button text which opens the settings app") + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *_Nonnull action) { + [[UIApplication sharedApplication] openSystemSettings]; + }]]; + + return alertController; +} + - (void)presentContactViewControllerForRecipientId:(NSString *)recipientId fromViewController:(UIViewController *)fromViewController editImmediately:(BOOL)shouldEditImmediately @@ -322,31 +351,7 @@ NS_ASSUME_NONNULL_BEGIN } if (!self.contactsManager.isSystemContactsAuthorized) { - UIAlertController *alertController = [UIAlertController - alertControllerWithTitle:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_TITLE", comment - : @"Alert title for when the user has just tried to edit a " - @"contacts after declining to give Signal contacts " - @"permissions") - message:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_BODY", comment - : @"Alert body for when the user has just tried to edit a " - @"contacts after declining to give Signal contacts " - @"permissions") - preferredStyle:UIAlertControllerStyleAlert]; - - [alertController - addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"AB_PERMISSION_MISSING_ACTION_NOT_NOW", - @"Button text to dismiss missing contacts permission alert") - style:UIAlertActionStyleCancel - handler:nil]]; - - [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OPEN_SETTINGS_BUTTON", - @"Button text which opens the settings app") - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *_Nonnull action) { - [[UIApplication sharedApplication] openSystemSettings]; - }]]; - - [fromViewController presentViewController:alertController animated:YES completion:nil]; + [fromViewController presentViewController:self.missingContactAccessAlertController animated:YES completion:nil]; return; } diff --git a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m index a5c100836..588d8de3c 100644 --- a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m +++ b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m @@ -275,9 +275,7 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ TSContactThread *contactThread = (TSContactThread *)self.thread; NSString *recipientId = contactThread.contactIdentifier; - OWSAddToContactViewController *view = [OWSAddToContactViewController new]; - [view configureWithRecipientId:recipientId]; - [weakSelf.navigationController pushViewController:view animated:YES]; + [weakSelf presentAddToContactViewControllerWithRecipientId:recipientId]; }]]; } @@ -763,6 +761,26 @@ NS_ASSUME_NONNULL_BEGIN editImmediately:YES]; } +- (void)presentAddToContactViewControllerWithRecipientId:(NSString *)recipientId +{ + if (!self.contactsManager.supportsContactEditing) { + // Should not expose UI that lets the user get here. + OWSFail(@"%@ Contact editing not supported.", self.tag); + return; + } + + if (!self.contactsManager.isSystemContactsAuthorized) { + [self presentViewController:self.contactsViewHelper.missingContactAccessAlertController + animated:YES + completion:nil]; + return; + } + + OWSAddToContactViewController *viewController = [OWSAddToContactViewController new]; + [viewController configureWithRecipientId:recipientId]; + [self.navigationController pushViewController:viewController animated:YES]; +} + - (void)didTapEditButton { [self presentContactViewController]; From 1c9ce5eaf307ba1c0ae2c3469c20da8d45674065 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 19 Jul 2017 09:33:17 -0400 Subject: [PATCH 2/2] CR: Don't just build, but present, alert controller // FREEBIE --- Signal/src/ViewControllers/ContactsViewHelper.h | 4 ++-- Signal/src/ViewControllers/ContactsViewHelper.m | 6 +++--- .../OWSConversationSettingsTableViewController.m | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Signal/src/ViewControllers/ContactsViewHelper.h b/Signal/src/ViewControllers/ContactsViewHelper.h index 4077b6ccb..3101659ab 100644 --- a/Signal/src/ViewControllers/ContactsViewHelper.h +++ b/Signal/src/ViewControllers/ContactsViewHelper.h @@ -46,9 +46,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSArray *blockedPhoneNumbers; -// Suitable to display when the user tries to perform an action which is not possible due to the user having +// Suitable when the user tries to perform an action which is not possible due to the user having // previously denied contact access. -@property (nonatomic, readonly) UIAlertController *missingContactAccessAlertController; +- (void)presentMissingContactAccessAlertControllerFromViewController:(UIViewController *)viewController; - (instancetype)init NS_UNAVAILABLE; diff --git a/Signal/src/ViewControllers/ContactsViewHelper.m b/Signal/src/ViewControllers/ContactsViewHelper.m index 2069624e0..58f8f9981 100644 --- a/Signal/src/ViewControllers/ContactsViewHelper.m +++ b/Signal/src/ViewControllers/ContactsViewHelper.m @@ -297,7 +297,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Editing -- (UIAlertController *)missingContactAccessAlertController +- (void)presentMissingContactAccessAlertControllerFromViewController:(UIViewController *)viewController { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_TITLE", comment @@ -323,7 +323,7 @@ NS_ASSUME_NONNULL_BEGIN [[UIApplication sharedApplication] openSystemSettings]; }]]; - return alertController; + [viewController presentViewController:alertController animated:YES completion:nil]; } - (void)presentContactViewControllerForRecipientId:(NSString *)recipientId @@ -351,7 +351,7 @@ NS_ASSUME_NONNULL_BEGIN } if (!self.contactsManager.isSystemContactsAuthorized) { - [fromViewController presentViewController:self.missingContactAccessAlertController animated:YES completion:nil]; + [self presentMissingContactAccessAlertControllerFromViewController:fromViewController]; return; } diff --git a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m index 588d8de3c..a00013269 100644 --- a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m +++ b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m @@ -770,9 +770,7 @@ NS_ASSUME_NONNULL_BEGIN } if (!self.contactsManager.isSystemContactsAuthorized) { - [self presentViewController:self.contactsViewHelper.missingContactAccessAlertController - animated:YES - completion:nil]; + [self.contactsViewHelper presentMissingContactAccessAlertControllerFromViewController:self]; return; }