From 0ff3e5e6a368f4e7e1eb7e9e6f41eecd83f02f02 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 11 May 2017 16:44:24 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20add=20blocked=20users=20to=20ne?= =?UTF-8?q?w=20groups=20and=20handle=20block=20alert=20results=20correctly?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- .../AddToGroupViewController.m | 4 +- .../ViewControllers/NewGroupViewController.m | 90 +++++++++++++------ .../NewNonContactConversationViewController.m | 4 +- 3 files changed, 65 insertions(+), 33 deletions(-) diff --git a/Signal/src/ViewControllers/AddToGroupViewController.m b/Signal/src/ViewControllers/AddToGroupViewController.m index 3a7fa413e2..abd9b45edd 100644 --- a/Signal/src/ViewControllers/AddToGroupViewController.m +++ b/Signal/src/ViewControllers/AddToGroupViewController.m @@ -57,7 +57,7 @@ NS_ASSUME_NONNULL_BEGIN blockingManager:helper.blockingManager contactsManager:helper.contactsManager completionBlock:^(BOOL isBlocked) { - if (isBlocked) { + if (!isBlocked) { [weakSelf addToGroup:phoneNumber]; } }]; @@ -89,7 +89,7 @@ NS_ASSUME_NONNULL_BEGIN blockingManager:helper.blockingManager contactsManager:helper.contactsManager completionBlock:^(BOOL isBlocked) { - if (isBlocked) { + if (!isBlocked) { [weakSelf addToGroup:signalAccount.recipientId]; } }]; diff --git a/Signal/src/ViewControllers/NewGroupViewController.m b/Signal/src/ViewControllers/NewGroupViewController.m index 1aa11dacd8..8dea3d40cd 100644 --- a/Signal/src/ViewControllers/NewGroupViewController.m +++ b/Signal/src/ViewControllers/NewGroupViewController.m @@ -4,6 +4,7 @@ #import "NewGroupViewController.h" #import "AddToGroupViewController.h" +#import "BlockListUIUtils.h" #import "ContactTableViewCell.h" #import "ContactsViewHelper.h" #import "Environment.h" @@ -205,37 +206,56 @@ NS_ASSUME_NONNULL_BEGIN for (NSString *recipientId in [nonContactMemberRecipientIds.allObjects sortedArrayUsingSelector:@selector(compare:)]) { - [nonContactsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ - NewGroupViewController *strongSelf = weakSelf; - OWSAssert(strongSelf); + [nonContactsSection + addItem:[OWSTableItem itemWithCustomCellBlock:^{ + NewGroupViewController *strongSelf = weakSelf; + OWSAssert(strongSelf); - ContactTableViewCell *cell = [ContactTableViewCell new]; - SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId]; - BOOL isCurrentMember = [strongSelf.memberRecipientIds containsObject:recipientId]; - BOOL isBlocked = [contactsViewHelper isRecipientIdBlocked:recipientId]; - if (isCurrentMember) { - // In the "contacts" section, we label members as such when editing an existing group. - cell.accessoryMessage = NSLocalizedString( - @"NEW_GROUP_MEMBER_LABEL", @"An indicator that a user is a member of the new group."); - } else if (isBlocked) { - cell.accessoryMessage = NSLocalizedString( - @"CONTACT_CELL_IS_BLOCKED", @"An indicator that a contact has been blocked."); - } else { - OWSAssert(cell.accessoryMessage == nil); + ContactTableViewCell *cell = [ContactTableViewCell new]; + SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId]; + BOOL isCurrentMember = [strongSelf.memberRecipientIds containsObject:recipientId]; + BOOL isBlocked = [contactsViewHelper isRecipientIdBlocked:recipientId]; + if (isCurrentMember) { + // In the "contacts" section, we label members as such when editing an existing group. + cell.accessoryMessage = NSLocalizedString( + @"NEW_GROUP_MEMBER_LABEL", @"An indicator that a user is a member of the new group."); + } else if (isBlocked) { + cell.accessoryMessage = NSLocalizedString( + @"CONTACT_CELL_IS_BLOCKED", @"An indicator that a contact has been blocked."); + } else { + OWSAssert(cell.accessoryMessage == nil); + } + + if (signalAccount) { + [cell configureWithSignalAccount:signalAccount + contactsManager:contactsViewHelper.contactsManager]; + } else { + [cell configureWithRecipientId:recipientId contactsManager:contactsViewHelper.contactsManager]; + } + + return cell; } - - if (signalAccount) { - [cell configureWithSignalAccount:signalAccount contactsManager:contactsViewHelper.contactsManager]; - } else { - [cell configureWithRecipientId:recipientId contactsManager:contactsViewHelper.contactsManager]; - } - - return cell; - } - customRowHeight:[ContactTableViewCell rowHeight] - actionBlock:^{ - [weakSelf removeRecipientId:recipientId]; - }]]; + customRowHeight:[ContactTableViewCell rowHeight] + actionBlock:^{ + BOOL isCurrentMember = [weakSelf.memberRecipientIds containsObject:recipientId]; + BOOL isBlocked = [contactsViewHelper isRecipientIdBlocked:recipientId]; + if (isCurrentMember) { + [weakSelf removeRecipientId:recipientId]; + } else if (isBlocked) { + [BlockListUIUtils + showUnblockPhoneNumberActionSheet:recipientId + fromViewController:weakSelf + blockingManager:contactsViewHelper.blockingManager + contactsManager:contactsViewHelper.contactsManager + completionBlock:^(BOOL isStillBlocked) { + if (!isStillBlocked) { + [weakSelf addRecipientId:recipientId]; + } + }]; + } else { + [weakSelf addRecipientId:recipientId]; + } + }]]; } [contents addSection:nonContactsSection]; } @@ -287,8 +307,20 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ NSString *recipientId = signalAccount.recipientId; BOOL isCurrentMember = [weakSelf.memberRecipientIds containsObject:recipientId]; + BOOL isBlocked = [contactsViewHelper isRecipientIdBlocked:recipientId]; if (isCurrentMember) { [weakSelf removeRecipientId:recipientId]; + } else if (isBlocked) { + [BlockListUIUtils + showUnblockSignalAccountActionSheet:signalAccount + fromViewController:weakSelf + blockingManager:contactsViewHelper.blockingManager + contactsManager:contactsViewHelper.contactsManager + completionBlock:^(BOOL isStillBlocked) { + if (!isStillBlocked) { + [weakSelf addRecipientId:recipientId]; + } + }]; } else { [weakSelf addRecipientId:recipientId]; } diff --git a/Signal/src/ViewControllers/NewNonContactConversationViewController.m b/Signal/src/ViewControllers/NewNonContactConversationViewController.m index c33faff5f6..118f5fdcde 100644 --- a/Signal/src/ViewControllers/NewNonContactConversationViewController.m +++ b/Signal/src/ViewControllers/NewNonContactConversationViewController.m @@ -58,7 +58,7 @@ NS_ASSUME_NONNULL_BEGIN blockingManager:helper.blockingManager contactsManager:helper.contactsManager completionBlock:^(BOOL isBlocked) { - if (isBlocked) { + if (!isBlocked) { [weakSelf selectRecipient:phoneNumber]; } }]; @@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN blockingManager:helper.blockingManager contactsManager:helper.contactsManager completionBlock:^(BOOL isBlocked) { - if (isBlocked) { + if (!isBlocked) { [weakSelf selectRecipient:signalAccount.recipientId]; } }];