2017-03-31 04:32:56 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "BlockListViewController.h"
|
2017-03-31 05:05:26 +02:00
|
|
|
#import "AddToBlockListViewController.h"
|
2017-04-03 16:29:11 +02:00
|
|
|
#import "BlockListUIUtils.h"
|
2017-05-02 19:18:00 +02:00
|
|
|
#import "ContactTableViewCell.h"
|
2017-05-01 18:51:59 +02:00
|
|
|
#import "ContactsViewHelper.h"
|
2017-03-31 23:56:39 +02:00
|
|
|
#import "Environment.h"
|
|
|
|
#import "OWSContactsManager.h"
|
2017-05-01 18:51:59 +02:00
|
|
|
#import "OWSTableViewController.h"
|
2017-03-31 23:56:39 +02:00
|
|
|
#import "PhoneNumber.h"
|
|
|
|
#import "UIFont+OWS.h"
|
2017-05-01 18:51:59 +02:00
|
|
|
#import "UIView+OWS.h"
|
2017-04-03 20:57:17 +02:00
|
|
|
#import <SignalServiceKit/OWSBlockingManager.h>
|
2017-03-31 04:32:56 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
@interface BlockListViewController () <ContactsViewHelperDelegate>
|
2017-03-31 04:32:56 +02:00
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
|
2017-03-31 04:32:56 +02:00
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
@property (nonatomic, readonly) OWSTableViewController *tableViewController;
|
2017-03-31 23:56:39 +02:00
|
|
|
|
2017-03-31 04:32:56 +02:00
|
|
|
@end
|
|
|
|
|
2017-03-31 05:05:26 +02:00
|
|
|
#pragma mark -
|
|
|
|
|
2017-03-31 04:32:56 +02:00
|
|
|
@implementation BlockListViewController
|
|
|
|
|
|
|
|
- (void)loadView
|
|
|
|
{
|
|
|
|
[super loadView];
|
2017-05-01 18:51:59 +02:00
|
|
|
|
2017-05-12 17:09:25 +02:00
|
|
|
_contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self];
|
2017-03-31 05:05:26 +02:00
|
|
|
|
2017-04-03 23:12:29 +02:00
|
|
|
self.title
|
|
|
|
= NSLocalizedString(@"SETTINGS_BLOCK_LIST_TITLE", @"Label for the block list section of the settings view");
|
2017-03-31 04:32:56 +02:00
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
_tableViewController = [OWSTableViewController new];
|
|
|
|
[self.view addSubview:self.tableViewController.view];
|
|
|
|
[_tableViewController.view autoPinWidthToSuperview];
|
|
|
|
[_tableViewController.view autoPinToTopLayoutGuideOfViewController:self withInset:0];
|
|
|
|
[_tableViewController.view autoPinToBottomLayoutGuideOfViewController:self withInset:0];
|
2017-03-31 05:05:26 +02:00
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
[self updateTableContents];
|
2017-03-31 05:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
2017-03-31 04:32:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
- (void)updateTableContents
|
2017-03-31 04:32:56 +02:00
|
|
|
{
|
2017-05-01 18:51:59 +02:00
|
|
|
OWSTableContents *contents = [OWSTableContents new];
|
2017-03-31 04:32:56 +02:00
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
__weak BlockListViewController *weakSelf = self;
|
|
|
|
ContactsViewHelper *helper = self.contactsViewHelper;
|
2017-03-31 04:32:56 +02:00
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
// Add section
|
2017-03-31 04:32:56 +02:00
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
OWSTableSection *addSection = [OWSTableSection new];
|
|
|
|
addSection.footerTitle = NSLocalizedString(
|
|
|
|
@"BLOCK_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking another user.");
|
|
|
|
|
|
|
|
[addSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
|
|
|
UITableViewCell *cell = [UITableViewCell new];
|
|
|
|
cell.textLabel.text = NSLocalizedString(
|
|
|
|
@"SETTINGS_BLOCK_LIST_ADD_BUTTON", @"A label for the 'add phone number' button in the block list table.");
|
|
|
|
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
|
|
|
|
cell.textLabel.textColor = [UIColor blackColor];
|
|
|
|
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
actionBlock:^{
|
|
|
|
AddToBlockListViewController *vc = [[AddToBlockListViewController alloc] init];
|
|
|
|
NSAssert(self.navigationController != nil, @"Navigation controller must not be nil");
|
|
|
|
NSAssert(vc != nil, @"Privacy Settings View Controller must not be nil");
|
|
|
|
[weakSelf.navigationController pushViewController:vc animated:YES];
|
|
|
|
}]];
|
|
|
|
[contents addSection:addSection];
|
|
|
|
|
|
|
|
// Blocklist section
|
|
|
|
|
|
|
|
OWSTableSection *blocklistSection = [OWSTableSection new];
|
|
|
|
NSArray<NSString *> *blockedPhoneNumbers =
|
|
|
|
[helper.blockedPhoneNumbers sortedArrayUsingSelector:@selector(compare:)];
|
|
|
|
for (NSString *phoneNumber in blockedPhoneNumbers) {
|
|
|
|
[blocklistSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
2017-05-02 19:18:00 +02:00
|
|
|
ContactTableViewCell *cell = [ContactTableViewCell new];
|
|
|
|
SignalAccount *signalAccount = [helper signalAccountForRecipientId:phoneNumber];
|
|
|
|
if (signalAccount) {
|
|
|
|
[cell configureWithSignalAccount:signalAccount contactsManager:helper.contactsManager];
|
|
|
|
} else {
|
|
|
|
[cell configureWithRecipientId:phoneNumber contactsManager:helper.contactsManager];
|
|
|
|
}
|
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
return cell;
|
2017-03-31 05:05:26 +02:00
|
|
|
}
|
2017-05-02 19:18:00 +02:00
|
|
|
customRowHeight:[ContactTableViewCell rowHeight]
|
2017-05-01 18:51:59 +02:00
|
|
|
actionBlock:^{
|
|
|
|
[BlockListUIUtils showUnblockPhoneNumberActionSheet:phoneNumber
|
|
|
|
fromViewController:weakSelf
|
|
|
|
blockingManager:helper.blockingManager
|
|
|
|
contactsManager:helper.contactsManager
|
|
|
|
completionBlock:nil];
|
|
|
|
}]];
|
2017-03-31 04:32:56 +02:00
|
|
|
}
|
2017-05-01 18:51:59 +02:00
|
|
|
[contents addSection:blocklistSection];
|
2017-03-31 04:32:56 +02:00
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
self.tableViewController.contents = contents;
|
2017-03-31 23:56:39 +02:00
|
|
|
}
|
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
#pragma mark - ContactsViewHelperDelegate
|
2017-03-31 04:32:56 +02:00
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
- (void)contactsViewHelperDidUpdateContacts
|
2017-03-31 23:56:39 +02:00
|
|
|
{
|
2017-05-01 18:51:59 +02:00
|
|
|
[self updateTableContents];
|
2017-03-31 23:56:39 +02:00
|
|
|
}
|
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
- (BOOL)shouldHideLocalNumber
|
2017-03-31 23:56:39 +02:00
|
|
|
{
|
2017-05-01 18:51:59 +02:00
|
|
|
return YES;
|
2017-03-31 23:56:39 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 04:32:56 +02:00
|
|
|
#pragma mark - Logging
|
|
|
|
|
|
|
|
+ (NSString *)tag
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"[%@]", self.class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)tag
|
|
|
|
{
|
|
|
|
return self.class.tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|