BlockListViewController v. group blocking

This commit is contained in:
Michael Kirk 2018-09-10 10:24:26 -05:00
parent 809b3766c1
commit 8aba5725cf
3 changed files with 61 additions and 33 deletions

View File

@ -14,6 +14,7 @@
#import <SignalMessaging/Environment.h>
#import <SignalMessaging/OWSContactsManager.h>
#import <SignalServiceKit/OWSBlockingManager.h>
#import <SignalServiceKit/TSGroupThread.h>
NS_ASSUME_NONNULL_BEGIN
@ -57,7 +58,7 @@ NS_ASSUME_NONNULL_BEGIN
__weak BlockListViewController *weakSelf = self;
ContactsViewHelper *helper = self.contactsViewHelper;
// Add section
// "Add" section
OWSTableSection *addSection = [OWSTableSection new];
addSection.footerTitle = NSLocalizedString(
@ -73,29 +74,61 @@ NS_ASSUME_NONNULL_BEGIN
}]];
[contents addSection:addSection];
// Blocklist section
// "Blocklist" section
OWSTableSection *blocklistSection = [OWSTableSection new];
NSArray<NSString *> *blockedPhoneNumbers =
[helper.blockedPhoneNumbers sortedArrayUsingSelector:@selector(compare:)];
for (NSString *phoneNumber in blockedPhoneNumbers) {
[blocklistSection addItem:[OWSTableItem
itemWithCustomCellBlock:^{
ContactTableViewCell *cell = [ContactTableViewCell new];
[cell configureWithRecipientId:phoneNumber
contactsManager:helper.contactsManager];
return cell;
}
customRowHeight:UITableViewAutomaticDimension
actionBlock:^{
[BlockListUIUtils showUnblockPhoneNumberActionSheet:phoneNumber
fromViewController:weakSelf
blockingManager:helper.blockingManager
contactsManager:helper.contactsManager
completionBlock:nil];
}]];
if (blockedPhoneNumbers.count > 0) {
OWSTableSection *blockedContactsSection = [OWSTableSection new];
blockedContactsSection.headerTitle
= NSLocalizedString(@"BLOCK_LIST_BLOCKED_USERS_SECTION", @"Section header for users that has been blocked");
for (NSString *phoneNumber in blockedPhoneNumbers) {
[blockedContactsSection
addItem:[OWSTableItem
itemWithCustomCellBlock:^{
ContactTableViewCell *cell = [ContactTableViewCell new];
[cell configureWithRecipientId:phoneNumber contactsManager:helper.contactsManager];
return cell;
}
customRowHeight:UITableViewAutomaticDimension
actionBlock:^{
[BlockListUIUtils showUnblockPhoneNumberActionSheet:phoneNumber
fromViewController:weakSelf
blockingManager:helper.blockingManager
contactsManager:helper.contactsManager
completionBlock:nil];
}]];
}
[contents addSection:blockedContactsSection];
}
NSArray<NSData *> *blockedGroupIds = helper.blockedGroupIds;
if (blockedGroupIds.count > 0) {
OWSTableSection *blockedGroupsSection = [OWSTableSection new];
blockedGroupsSection.headerTitle = NSLocalizedString(
@"BLOCK_LIST_BLOCKED_GROUPS_SECTION", @"Section header for groups that has been blocked");
for (NSData *groupId in blockedGroupIds) {
TSGroupThread *groupThread = [TSGroupThread getOrCreateThreadWithGroupId:groupId];
[blockedGroupsSection addItem:[OWSTableItem
itemWithCustomCellBlock:^{
ContactTableViewCell *cell = [ContactTableViewCell new];
[cell configureWithThread:groupThread
contactsManager:helper.contactsManager];
return cell;
}
customRowHeight:UITableViewAutomaticDimension
actionBlock:^{
[BlockListUIUtils showUnblockThreadActionSheet:groupThread
fromViewController:weakSelf
blockingManager:helper.blockingManager
contactsManager:helper.contactsManager
completionBlock:nil];
}]];
}
[contents addSection:blockedGroupsSection];
}
[contents addSection:blocklistSection];
self.tableViewController.contents = contents;
}

View File

@ -236,6 +236,12 @@
/* A format for the 'block user' action sheet title. Embeds {{the blocked user's name or phone number}}. */
"BLOCK_LIST_BLOCK_USER_TITLE_FORMAT" = "Block %@?";
/* Section header for groups that has been blocked */
"BLOCK_LIST_BLOCKED_GROUPS_SECTION" = "Blocked Groups";
/* Section header for users that has been blocked */
"BLOCK_LIST_BLOCKED_USERS_SECTION" = "Blocked Users";
/* Button label for the 'unblock' button */
"BLOCK_LIST_UNBLOCK_BUTTON" = "Unblock";
@ -251,12 +257,6 @@
/* A label for the block button in the block list view */
"BLOCK_LIST_VIEW_BLOCK_BUTTON" = "Block";
/* The title of the 'block user failed' alert. */
"BLOCK_LIST_VIEW_BLOCK_FAILED_ALERT_MESSAGE" = "Failed to Block User.";
/* The title of the 'block user failed' alert. */
"BLOCK_LIST_VIEW_BLOCK_FAILED_ALERT_TITLE" = "Error";
/* The message format of the 'conversation blocked' alert. Embeds the {{conversation title}}. */
"BLOCK_LIST_VIEW_BLOCKED_ALERT_MESSAGE_FORMAT" = "%@ has been blocked";
@ -272,12 +272,6 @@
/* The title of the 'You can't block yourself' alert. */
"BLOCK_LIST_VIEW_CANT_BLOCK_SELF_ALERT_TITLE" = "Error";
/* The title of the 'unblock user failed' alert. */
"BLOCK_LIST_VIEW_UNBLOCK_FAILED_ALERT_MESSAGE" = "Failed to Unblock User.";
/* The title of the 'unblock user failed' alert. */
"BLOCK_LIST_VIEW_UNBLOCK_FAILED_ALERT_TITLE" = "Error";
/* Alert body after unblocking a group or 1:1 chat. Embeds the conversation title. */
"BLOCK_LIST_VIEW_UNBLOCKED_ALERT_MESSAGE_FORMAT" = "%@ has been unblocked.";
@ -1950,7 +1944,7 @@
"SETTINGS_BACKUP_STATUS_SUCCEEDED" = "Backup Successful";
/* A label for the 'add phone number' button in the block list table. */
"SETTINGS_BLOCK_LIST_ADD_BUTTON" = "Add";
"SETTINGS_BLOCK_LIST_ADD_BUTTON" = "Add Blocked User";
/* A label that indicates the user has no Signal contacts. */
"SETTINGS_BLOCK_LIST_NO_CONTACTS" = "You have no contacts on Signal.";

View File

@ -48,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
// MJK TODO Can we remove? Do we need blockedGroupList?
@property (nonatomic, readonly) NSArray<NSString *> *blockedPhoneNumbers;
@property (nonatomic, readonly) NSArray<NSData *> *blockedGroupIds;
// Suitable when the user tries to perform an action which is not possible due to the user having
// previously denied contact access.