Merge branch 'mkirk/add-to-existing-requires-contacts'

pull/1/head
Michael Kirk 8 years ago
commit 7adf5e81f7

@ -46,6 +46,10 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSArray<NSString *> *blockedPhoneNumbers; @property (nonatomic, readonly) NSArray<NSString *> *blockedPhoneNumbers;
// Suitable when the user tries to perform an action which is not possible due to the user having
// previously denied contact access.
- (void)presentMissingContactAccessAlertControllerFromViewController:(UIViewController *)viewController;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithDelegate:(id<ContactsViewHelperDelegate>)delegate; - (instancetype)initWithDelegate:(id<ContactsViewHelperDelegate>)delegate;

@ -297,31 +297,8 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Editing #pragma mark - Editing
- (void)presentContactViewControllerForRecipientId:(NSString *)recipientId - (void)presentMissingContactAccessAlertControllerFromViewController:(UIViewController *)viewController
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) {
UIAlertController *alertController = [UIAlertController UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_TITLE", comment alertControllerWithTitle:NSLocalizedString(@"EDIT_CONTACT_WITHOUT_CONTACTS_PERMISSION_ALERT_TITLE", comment
: @"Alert title for when the user has just tried to edit a " : @"Alert title for when the user has just tried to edit a "
@ -346,7 +323,35 @@ NS_ASSUME_NONNULL_BEGIN
[[UIApplication sharedApplication] openSystemSettings]; [[UIApplication sharedApplication] openSystemSettings];
}]]; }]];
[fromViewController presentViewController:alertController animated:YES completion:nil]; [viewController presentViewController:alertController animated:YES completion:nil];
}
- (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) {
[self presentMissingContactAccessAlertControllerFromViewController:fromViewController];
return; return;
} }

@ -275,9 +275,7 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{ actionBlock:^{
TSContactThread *contactThread = (TSContactThread *)self.thread; TSContactThread *contactThread = (TSContactThread *)self.thread;
NSString *recipientId = contactThread.contactIdentifier; NSString *recipientId = contactThread.contactIdentifier;
OWSAddToContactViewController *view = [OWSAddToContactViewController new]; [weakSelf presentAddToContactViewControllerWithRecipientId:recipientId];
[view configureWithRecipientId:recipientId];
[weakSelf.navigationController pushViewController:view animated:YES];
}]]; }]];
} }
@ -763,6 +761,24 @@ NS_ASSUME_NONNULL_BEGIN
editImmediately:YES]; 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.contactsViewHelper presentMissingContactAccessAlertControllerFromViewController:self];
return;
}
OWSAddToContactViewController *viewController = [OWSAddToContactViewController new];
[viewController configureWithRecipientId:recipientId];
[self.navigationController pushViewController:viewController animated:YES];
}
- (void)didTapEditButton - (void)didTapEditButton
{ {
[self presentContactViewController]; [self presentContactViewController];

Loading…
Cancel
Save