Adding to existing contact requires contact access

Previously we'd show an empty "list" of existing contacts.

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 5552649553
commit 5c66e5584c

@ -46,6 +46,10 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSArray<NSString *> *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<ContactsViewHelperDelegate>)delegate;

@ -297,31 +297,8 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Editing
- (void)presentContactViewControllerForRecipientId:(NSString *)recipientId
fromViewController:(UIViewController<ContactEditingDelegate> *)fromViewController
editImmediately:(BOOL)shouldEditImmediately
{
[self presentContactViewControllerForRecipientId:recipientId
fromViewController:fromViewController
editImmediately:shouldEditImmediately
addToExistingCnContact:nil];
}
- (void)presentContactViewControllerForRecipientId:(NSString *)recipientId
fromViewController:(UIViewController<ContactEditingDelegate> *)fromViewController
editImmediately:(BOOL)shouldEditImmediately
addToExistingCnContact:(CNContact *_Nullable)addToExistingCnContact
- (UIAlertController *)missingContactAccessAlertController
{
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
: @"Alert title for when the user has just tried to edit a "
@ -346,7 +323,35 @@ NS_ASSUME_NONNULL_BEGIN
[[UIApplication sharedApplication] openSystemSettings];
}]];
[fromViewController presentViewController:alertController animated:YES completion:nil];
return alertController;
}
- (void)presentContactViewControllerForRecipientId:(NSString *)recipientId
fromViewController:(UIViewController<ContactEditingDelegate> *)fromViewController
editImmediately:(BOOL)shouldEditImmediately
{
[self presentContactViewControllerForRecipientId:recipientId
fromViewController:fromViewController
editImmediately:shouldEditImmediately
addToExistingCnContact:nil];
}
- (void)presentContactViewControllerForRecipientId:(NSString *)recipientId
fromViewController:(UIViewController<ContactEditingDelegate> *)fromViewController
editImmediately:(BOOL)shouldEditImmediately
addToExistingCnContact:(CNContact *_Nullable)addToExistingCnContact
{
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) {
[fromViewController presentViewController:self.missingContactAccessAlertController animated:YES completion:nil];
return;
}

@ -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];

Loading…
Cancel
Save