|
|
|
@ -7,234 +7,136 @@
|
|
|
|
|
#import "Environment.h"
|
|
|
|
|
#import "PropertyListPreferences.h"
|
|
|
|
|
#import "Signal-Swift.h"
|
|
|
|
|
#import "UIUtil.h"
|
|
|
|
|
#import <25519/Curve25519.h>
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
typedef NS_ENUM(NSInteger, PrivacySettingsTableViewControllerSectionIndex) {
|
|
|
|
|
PrivacySettingsTableViewControllerSectionIndexBlockList,
|
|
|
|
|
PrivacySettingsTableViewControllerSectionIndexScreenSecurity,
|
|
|
|
|
PrivacySettingsTableViewControllerSectionIndexCalling,
|
|
|
|
|
PrivacySettingsTableViewControllerSectionIndexCallKit,
|
|
|
|
|
PrivacySettingsTableViewControllerSectionIndexHistoryLog,
|
|
|
|
|
PrivacySettingsTableViewControllerSectionIndex_Count // meta section to track how many sections
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@interface PrivacySettingsTableViewController ()
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) UITableViewCell *blocklistCell;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) UITableViewCell *enableCallKitCell;
|
|
|
|
|
@property (nonatomic) UISwitch *enableCallKitSwitch;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) UITableViewCell *enableCallKitPrivacyCell;
|
|
|
|
|
@property (nonatomic) UISwitch *enableCallKitPrivacySwitch;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, strong) UITableViewCell *enableScreenSecurityCell;
|
|
|
|
|
@property (nonatomic, strong) UISwitch *enableScreenSecuritySwitch;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) UITableViewCell *callsHideIPAddressCell;
|
|
|
|
|
@property (nonatomic) UISwitch *callsHideIPAddressSwitch;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, strong) UITableViewCell *clearHistoryLogCell;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation PrivacySettingsTableViewController
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
|
|
|
|
|
|
|
|
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)init {
|
|
|
|
|
return [super initWithStyle:UITableViewStyleGrouped];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)loadView {
|
|
|
|
|
[super loadView];
|
|
|
|
|
|
|
|
|
|
self.title = NSLocalizedString(@"SETTINGS_PRIVACY_TITLE", @"");
|
|
|
|
|
|
|
|
|
|
// Block List
|
|
|
|
|
self.blocklistCell = [UITableViewCell new];
|
|
|
|
|
self.blocklistCell.textLabel.text
|
|
|
|
|
= NSLocalizedString(@"SETTINGS_BLOCK_LIST_TITLE", @"Label for the block list section of the settings view");
|
|
|
|
|
self.blocklistCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
|
|
|
|
|
|
|
|
// CallKit opt-out
|
|
|
|
|
self.enableCallKitCell = [UITableViewCell new];
|
|
|
|
|
self.enableCallKitCell.textLabel.text = NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_TITLE", @"Short table cell label");
|
|
|
|
|
self.enableCallKitSwitch = [UISwitch new];
|
|
|
|
|
[self.enableCallKitSwitch setOn:[[Environment getCurrent].preferences isCallKitEnabled]];
|
|
|
|
|
[self.enableCallKitSwitch addTarget:self
|
|
|
|
|
action:@selector(didToggleEnableCallKitSwitch:)
|
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
|
|
|
|
self.enableCallKitCell.accessoryView = self.enableCallKitSwitch;
|
|
|
|
|
|
|
|
|
|
// CallKit privacy
|
|
|
|
|
self.enableCallKitPrivacyCell = [UITableViewCell new];
|
|
|
|
|
self.enableCallKitPrivacyCell.textLabel.text = NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_PRIVACY_TITLE", @"Label for 'CallKit privacy' preference");
|
|
|
|
|
self.enableCallKitPrivacySwitch = [UISwitch new];
|
|
|
|
|
[self.enableCallKitPrivacySwitch setOn:![[Environment getCurrent].preferences isCallKitPrivacyEnabled]];
|
|
|
|
|
[self.enableCallKitPrivacySwitch addTarget:self
|
|
|
|
|
action:@selector(didToggleEnableCallKitPrivacySwitch:)
|
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
|
|
|
|
self.enableCallKitPrivacyCell.accessoryView = self.enableCallKitPrivacySwitch;
|
|
|
|
|
|
|
|
|
|
// Enable Screen Security Cell
|
|
|
|
|
self.enableScreenSecurityCell = [[UITableViewCell alloc] init];
|
|
|
|
|
self.enableScreenSecurityCell.textLabel.text = NSLocalizedString(@"SETTINGS_SCREEN_SECURITY", @"");
|
|
|
|
|
self.enableScreenSecuritySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
|
|
|
|
|
self.enableScreenSecurityCell.accessoryView = self.enableScreenSecuritySwitch;
|
|
|
|
|
self.enableScreenSecurityCell.userInteractionEnabled = YES;
|
|
|
|
|
[self.enableScreenSecuritySwitch setOn:[Environment.preferences screenSecurityIsEnabled]];
|
|
|
|
|
[self.enableScreenSecuritySwitch addTarget:self
|
|
|
|
|
action:@selector(didToggleScreenSecuritySwitch:)
|
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
|
|
|
|
|
|
|
|
|
// Allow calls to connect directly vs. using TURN exclusively
|
|
|
|
|
self.callsHideIPAddressCell = [UITableViewCell new];
|
|
|
|
|
self.callsHideIPAddressCell.textLabel.text
|
|
|
|
|
= NSLocalizedString(@"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE", @"Table cell label");
|
|
|
|
|
self.callsHideIPAddressSwitch = [UISwitch new];
|
|
|
|
|
self.callsHideIPAddressCell.accessoryView = self.callsHideIPAddressSwitch;
|
|
|
|
|
[self.callsHideIPAddressSwitch setOn:[Environment.preferences doCallsHideIPAddress]];
|
|
|
|
|
[self.callsHideIPAddressSwitch addTarget:self
|
|
|
|
|
action:@selector(didToggleCallsHideIPAddressSwitch:)
|
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
|
|
|
|
|
|
|
|
|
// Clear History Log Cell
|
|
|
|
|
self.clearHistoryLogCell = [[UITableViewCell alloc] init];
|
|
|
|
|
self.clearHistoryLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_CLEAR_HISTORY", @"");
|
|
|
|
|
self.clearHistoryLogCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
|
|
|
[self updateTableContents];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
|
|
|
return PrivacySettingsTableViewControllerSectionIndex_Count;
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
|
{
|
|
|
|
|
[self updateTableContents];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
|
switch (section) {
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexBlockList:
|
|
|
|
|
return 1;
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity:
|
|
|
|
|
return 1;
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexCalling:
|
|
|
|
|
return 1;
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexCallKit:
|
|
|
|
|
if (![UIDevice currentDevice].supportsCallKit) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return [Environment getCurrent].preferences.isCallKitEnabled ? 2 : 1;
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexHistoryLog:
|
|
|
|
|
return 1;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#pragma mark - Table Contents
|
|
|
|
|
|
|
|
|
|
- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
|
|
|
|
|
- (void)updateTableContents
|
|
|
|
|
{
|
|
|
|
|
switch (section) {
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity:
|
|
|
|
|
return NSLocalizedString(@"SETTINGS_SCREEN_SECURITY_DETAIL", nil);
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexCalling:
|
|
|
|
|
return NSLocalizedString(@"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE_DETAIL",
|
|
|
|
|
@"User settings section footer, a detailed explanation");
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexCallKit:
|
|
|
|
|
return ([UIDevice currentDevice].supportsCallKit
|
|
|
|
|
? NSLocalizedString(@"SETTINGS_SECTION_CALL_KIT_DESCRIPTION", @"Settings table section footer.")
|
|
|
|
|
: nil);
|
|
|
|
|
default:
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
OWSTableContents *contents = [OWSTableContents new];
|
|
|
|
|
|
|
|
|
|
__weak PrivacySettingsTableViewController *weakSelf = self;
|
|
|
|
|
|
|
|
|
|
[contents
|
|
|
|
|
addSection:[OWSTableSection
|
|
|
|
|
sectionWithTitle:nil
|
|
|
|
|
items:@[
|
|
|
|
|
[OWSTableItem disclosureItemWithText:
|
|
|
|
|
NSLocalizedString(@"SETTINGS_BLOCK_LIST_TITLE",
|
|
|
|
|
@"Label for the block list section of the settings view")
|
|
|
|
|
actionBlock:^{
|
|
|
|
|
[weakSelf showBlocklist];
|
|
|
|
|
}],
|
|
|
|
|
]]];
|
|
|
|
|
|
|
|
|
|
OWSTableSection *screenSecuritySection = [OWSTableSection new];
|
|
|
|
|
screenSecuritySection.headerTitle = NSLocalizedString(@"SETTINGS_SECURITY_TITLE", @"Section header");
|
|
|
|
|
screenSecuritySection.footerTitle = NSLocalizedString(@"SETTINGS_SCREEN_SECURITY_DETAIL", nil);
|
|
|
|
|
// TODO: Apply switchItemWithText.
|
|
|
|
|
[screenSecuritySection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_SCREEN_SECURITY", @"")
|
|
|
|
|
isOn:[Environment.preferences screenSecurityIsEnabled]
|
|
|
|
|
target:weakSelf
|
|
|
|
|
selector:@selector(didToggleScreenSecuritySwitch:)]];
|
|
|
|
|
[contents addSection:screenSecuritySection];
|
|
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
switch (indexPath.section) {
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexBlockList:
|
|
|
|
|
return self.blocklistCell;
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity:
|
|
|
|
|
return self.enableScreenSecurityCell;
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexCalling:
|
|
|
|
|
return self.callsHideIPAddressCell;
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexCallKit:
|
|
|
|
|
switch (indexPath.row) {
|
|
|
|
|
case 0:
|
|
|
|
|
return self.enableCallKitCell;
|
|
|
|
|
case 1:
|
|
|
|
|
return self.enableCallKitPrivacyCell;
|
|
|
|
|
}
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexHistoryLog:
|
|
|
|
|
return self.clearHistoryLogCell;
|
|
|
|
|
default: {
|
|
|
|
|
DDLogError(@"%@ Requested unknown table view cell for row at indexPath: %@", self.tag, indexPath);
|
|
|
|
|
return [UITableViewCell new];
|
|
|
|
|
// Allow calls to connect directly vs. using TURN exclusively
|
|
|
|
|
OWSTableSection *callingSection = [OWSTableSection new];
|
|
|
|
|
callingSection.headerTitle
|
|
|
|
|
= NSLocalizedString(@"SETTINGS_SECTION_TITLE_CALLING", @"settings topic header for table section");
|
|
|
|
|
callingSection.footerTitle = NSLocalizedString(@"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE_DETAIL",
|
|
|
|
|
@"User settings section footer, a detailed explanation");
|
|
|
|
|
[callingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(
|
|
|
|
|
@"SETTINGS_CALLING_HIDES_IP_ADDRESS_PREFERENCE_TITLE",
|
|
|
|
|
@"Table cell label")
|
|
|
|
|
isOn:[Environment.preferences doCallsHideIPAddress]
|
|
|
|
|
target:weakSelf
|
|
|
|
|
selector:@selector(didToggleCallsHideIPAddressSwitch:)]];
|
|
|
|
|
[contents addSection:callingSection];
|
|
|
|
|
|
|
|
|
|
if ([UIDevice currentDevice].supportsCallKit) {
|
|
|
|
|
OWSTableSection *callKitSection = [OWSTableSection new];
|
|
|
|
|
callKitSection.footerTitle
|
|
|
|
|
= NSLocalizedString(@"SETTINGS_SECTION_CALL_KIT_DESCRIPTION", @"Settings table section footer.");
|
|
|
|
|
[callKitSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_TITLE",
|
|
|
|
|
@"Short table cell label")
|
|
|
|
|
isOn:[Environment.preferences isCallKitEnabled]
|
|
|
|
|
target:weakSelf
|
|
|
|
|
selector:@selector(didToggleEnableCallKitSwitch:)]];
|
|
|
|
|
if (Environment.preferences.isCallKitEnabled) {
|
|
|
|
|
[callKitSection
|
|
|
|
|
addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_PRIVACY_CALLKIT_PRIVACY_TITLE",
|
|
|
|
|
@"Label for 'CallKit privacy' preference")
|
|
|
|
|
isOn:[Environment.preferences isCallKitPrivacyEnabled]
|
|
|
|
|
target:weakSelf
|
|
|
|
|
selector:@selector(didToggleEnableCallKitPrivacySwitch:)]];
|
|
|
|
|
}
|
|
|
|
|
[contents addSection:callKitSection];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OWSTableSection *historyLogsSection = [OWSTableSection new];
|
|
|
|
|
historyLogsSection.headerTitle = NSLocalizedString(@"SETTINGS_HISTORYLOG_TITLE", @"Section header");
|
|
|
|
|
[historyLogsSection addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"SETTINGS_CLEAR_HISTORY", @"")
|
|
|
|
|
actionBlock:^{
|
|
|
|
|
[weakSelf clearHistoryLogs];
|
|
|
|
|
}]];
|
|
|
|
|
[contents addSection:historyLogsSection];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.contents = contents;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
|
|
|
|
#pragma mark - Events
|
|
|
|
|
|
|
|
|
|
- (void)showBlocklist
|
|
|
|
|
{
|
|
|
|
|
switch (section) {
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexScreenSecurity:
|
|
|
|
|
return NSLocalizedString(@"SETTINGS_SECURITY_TITLE", @"Section header");
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexCalling:
|
|
|
|
|
return NSLocalizedString(@"SETTINGS_SECTION_TITLE_CALLING", @"settings topic header for table section");
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexHistoryLog:
|
|
|
|
|
return NSLocalizedString(@"SETTINGS_HISTORYLOG_TITLE", @"Section header");
|
|
|
|
|
default:
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
BlockListViewController *vc = [BlockListViewController new];
|
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
|
|
|
|
|
|
|
|
switch (indexPath.section) {
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexBlockList: {
|
|
|
|
|
BlockListViewController *vc = [[BlockListViewController alloc] init];
|
|
|
|
|
NSAssert(self.navigationController != nil, @"Navigation controller must not be nil");
|
|
|
|
|
NSAssert(vc != nil, @"About View Controller must not be nil");
|
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case PrivacySettingsTableViewControllerSectionIndexHistoryLog: {
|
|
|
|
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
|
|
|
|
|
message:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION", @"Alert message before user confirms clearing history")
|
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
|
|
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"")
|
|
|
|
|
style:UIAlertActionStyleCancel
|
|
|
|
|
handler:nil];
|
|
|
|
|
[alertController addAction:dismissAction];
|
|
|
|
|
|
|
|
|
|
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION_BUTTON", @"")
|
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
|
handler:^(UIAlertAction * _Nonnull action) {
|
|
|
|
|
[[TSStorageManager sharedManager] deleteThreadsAndMessages];
|
|
|
|
|
}];
|
|
|
|
|
[alertController addAction:deleteAction];
|
|
|
|
|
|
|
|
|
|
[self presentViewController:alertController animated:true completion:nil];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
- (void)clearHistoryLogs
|
|
|
|
|
{
|
|
|
|
|
UIAlertController *alertController =
|
|
|
|
|
[UIAlertController alertControllerWithTitle:nil
|
|
|
|
|
message:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION",
|
|
|
|
|
@"Alert message before user confirms clearing history")
|
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
|
|
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"")
|
|
|
|
|
style:UIAlertActionStyleCancel
|
|
|
|
|
handler:nil];
|
|
|
|
|
[alertController addAction:dismissAction];
|
|
|
|
|
|
|
|
|
|
UIAlertAction *deleteAction =
|
|
|
|
|
[UIAlertAction actionWithTitle:NSLocalizedString(@"SETTINGS_DELETE_HISTORYLOG_CONFIRMATION_BUTTON", @"")
|
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
|
|
|
|
[[TSStorageManager sharedManager] deleteThreadsAndMessages];
|
|
|
|
|
}];
|
|
|
|
|
[alertController addAction:deleteAction];
|
|
|
|
|
|
|
|
|
|
[self presentViewController:alertController animated:true completion:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Toggle
|
|
|
|
|
|
|
|
|
|
- (void)didToggleScreenSecuritySwitch:(UISwitch *)sender
|
|
|
|
|
{
|
|
|
|
|
BOOL enabled = self.enableScreenSecuritySwitch.isOn;
|
|
|
|
|
BOOL enabled = sender.isOn;
|
|
|
|
|
DDLogInfo(@"%@ toggled screen security: %@", self.tag, enabled ? @"ON" : @"OFF");
|
|
|
|
|
[Environment.preferences setScreenSecurity:enabled];
|
|
|
|
|
}
|
|
|
|
@ -251,7 +153,7 @@ typedef NS_ENUM(NSInteger, PrivacySettingsTableViewControllerSectionIndex) {
|
|
|
|
|
[[Environment getCurrent].preferences setIsCallKitEnabled:sender.isOn];
|
|
|
|
|
// rebuild callUIAdapter since CallKit vs not changed.
|
|
|
|
|
[[Environment getCurrent].callService createCallUIAdapter];
|
|
|
|
|
[self.tableView reloadData];
|
|
|
|
|
[self updateTableContents];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)didToggleEnableCallKitPrivacySwitch:(UISwitch *)sender {
|
|
|
|
|