session-ios/Signal/src/view controllers/SettingsTableViewController.m

291 lines
11 KiB
Mathematica
Raw Normal View History

2014-10-29 21:58:58 +01:00
//
// SettingsTableViewController.m
// Signal
//
// Created by Dylan Bourgeois on 03/11/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
#import "SettingsTableViewController.h"
2014-12-26 21:17:43 +01:00
#import "Environment.h"
#import "PropertyListPreferences.h"
#import "TSAccountManager.h"
#import "UIUtil.h"
2014-11-26 16:00:10 +01:00
#import "RPServerRequestsManager.h"
#import "TSSocketManager.h"
#import "AboutTableViewController.h"
#import "AdvancedSettingsTableViewController.h"
#import "NotificationSettingsViewController.h"
#import "OWSContactsManager.h"
#import "PrivacySettingsTableViewController.h"
#import "PushManager.h"
#import "Signal-Swift.h"
#define kProfileCellHeight 87.0f
#define kStandardCellHeight 44.0f
2014-10-29 21:58:58 +01:00
#define kNumberOfSections 4
2014-10-29 21:58:58 +01:00
#define kRegisteredNumberRow 0
#define kInviteRow 0
#define kPrivacyRow 1
#define kNotificationRow 2
#define kLinkedDevices 3 // we don't actually use this, instead we segue via Interface Builder
#define kAdvancedRow 4
#define kAboutRow 5
#define kNetworkRow 0
#define kUnregisterRow 0
2014-10-29 21:58:58 +01:00
typedef enum {
kRegisteredRows = 1,
kGeneralRows = 6,
kNetworkStatusRows = 1,
kUnregisterRows = 1,
2014-10-29 21:58:58 +01:00
} kRowsForSection;
typedef enum {
kRegisteredNumberSection = 0,
kNetworkStatusSection = 1,
kGeneralSection = 2,
kUnregisterSection = 3,
2014-10-29 21:58:58 +01:00
} kSection;
@interface SettingsTableViewController () <UIAlertViewDelegate>
2014-10-29 21:58:58 +01:00
@end
@implementation SettingsTableViewController
- (void)viewDidLoad
{
2014-10-29 21:58:58 +01:00
[super viewDidLoad];
iOS 9 Support - Fixing size classes rendering bugs. - Supporting native iOS San Francisco font. - Quick Reply - Settings now slide to the left as suggested in original designed opposed to modal. - Simplification of restraints on many screens. - Full-API compatiblity with iOS 9 and iOS 8 legacy support. - Customized AddressBook Permission prompt when restrictions are enabled. If user installed Signal previously and already approved access to Contacts, don't bugg him again. - Fixes crash in migration for users who installed Signal <2.1.3 but hadn't signed up yet. - Xcode 7 / iOS 9 Travis Support - Bitcode Support is disabled until it is better understood how exactly optimizations are performed. In a first time, we will split out the crypto code into a separate binary to make it easier to optimize the non-sensitive code. Blog post with more details coming. - Partial ATS support. We are running our own Certificate Authority at Open Whisper Systems. Signal is doing certificate pinning to verify that certificates were signed by our own CA. Unfortunately Apple's App Transport Security requires to hand over chain verification to their framework with no control over the trust store. We have filed a radar to get ATS features with pinned certificates. In the meanwhile, ATS is disabled on our domain. We also followed Amazon's recommendations for our S3 domain we use to upload/download attachments. (#891) - Implement a unified `AFSecurityOWSPolicy` pinning strategy accross libraries (AFNetworking RedPhone/TextSecure & SocketRocket).
2015-09-01 19:22:08 +02:00
[self.navigationItem setHidesBackButton:YES];
[self.navigationController.navigationBar setTranslucent:NO];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
self.registeredNumber.text =
[PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:[TSAccountManager localNumber]];
self.registeredName.text = NSLocalizedString(@"REGISTERED_NUMBER_TEXT", @"");
[self initializeObserver];
[TSSocketManager sendNotification];
self.title = NSLocalizedString(@"SETTINGS_NAV_BAR_TITLE", @"Title for settings activity");
self.networkStatusHeader.text = NSLocalizedString(@"NETWORK_STATUS_HEADER", @"");
self.privacyLabel.text = NSLocalizedString(@"SETTINGS_PRIVACY_TITLE", @"");
self.advancedLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_TITLE", @"");
self.aboutLabel.text = NSLocalizedString(@"SETTINGS_ABOUT", @"");
self.notificationsLabel.text = NSLocalizedString(@"SETTINGS_NOTIFICATIONS", nil);
self.linkedDevicesLabel.text
= NSLocalizedString(@"LINKED_DEVICES_TITLE", @"Menu item and navbar title for the device manager");
self.inviteLabel.text = NSLocalizedString(@"SETTINGS_INVITE_TITLE", @"Settings table view cell label");
[self.destroyAccountButton setTitle:NSLocalizedString(@"SETTINGS_DELETE_ACCOUNT_BUTTON", @"")
forState:UIControlStateNormal];
2014-10-29 21:58:58 +01:00
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// HACK to unselect rows when swiping back
// http://stackoverflow.com/questions/19379510/uitableviewcell-doesnt-get-deselected-when-swiping-back-quickly
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:animated];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:SocketOpenedNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:SocketClosedNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:SocketConnectingNotification object:nil];
2014-10-29 21:58:58 +01:00
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return kNumberOfSections;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) {
case kRegisteredNumberSection:
return kRegisteredRows;
case kGeneralSection:
return kGeneralRows;
case kNetworkStatusSection:
return kNetworkStatusRows;
case kUnregisterSection:
return kUnregisterRows;
2014-10-29 21:58:58 +01:00
default:
return 0;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
switch (indexPath.section) {
case kGeneralSection: {
switch (indexPath.row) {
case kInviteRow: {
OWSInviteFlow *inviteFlow = [[OWSInviteFlow alloc] initWithPresentingViewController:self];
[self presentViewController:inviteFlow.actionSheetController
animated:YES
completion:^{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}];
break;
}
case kPrivacyRow: {
PrivacySettingsTableViewController *vc = [[PrivacySettingsTableViewController alloc] init];
NSAssert(self.navigationController != nil, @"Navigation controller must not be nil");
NSAssert(vc != nil, @"Privacy Settings View Controller must not be nil");
[self.navigationController pushViewController:vc animated:YES];
break;
}
case kNotificationRow: {
NotificationSettingsViewController *vc = [[NotificationSettingsViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
break;
}
case kAdvancedRow: {
AdvancedSettingsTableViewController *vc = [[AdvancedSettingsTableViewController alloc] init];
NSAssert(self.navigationController != nil, @"Navigation controller must not be nil");
NSAssert(vc != nil, @"Advanced Settings View Controller must not be nil");
[self.navigationController pushViewController:vc animated:YES];
break;
}
case kAboutRow: {
AboutTableViewController *vc = [[AboutTableViewController 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;
}
default:
DDLogError(@"%@ Unhandled row selected at index path: %@", self.tag, indexPath);
break;
}
break;
2014-10-29 21:58:58 +01:00
}
case kNetworkStatusSection: {
break;
}
case kUnregisterSection: {
[self unregisterUser:nil];
break;
}
default:
break;
}
}
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case kNetworkStatusSection: {
return NO;
}
case kUnregisterSection: {
return NO;
}
default:
return YES;
}
}
- (IBAction)unregisterUser:(id)sender {
UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TITLE", @"")
message:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TEXT", @"")
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"PROCEED_BUTTON", @"")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
[self proceedToUnregistration];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", @"")
style:UIAlertActionStyleCancel
handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)proceedToUnregistration {
[TSAccountManager unregisterTextSecureWithSuccess:^{
[Environment resetAppData];
}
failure:^(NSError *error) {
SignalAlertView(NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @""), @"");
2015-01-25 23:38:52 +01:00
}];
}
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == kNetworkStatusSection) {
UIAlertView *info = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"NETWORK_STATUS_HEADER", @"")
message:NSLocalizedString(@"NETWORK_STATUS_TEXT", @"")
delegate:self
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[info show];
2014-10-29 21:58:58 +01:00
}
}
#pragma mark - Socket Status Notifications
- (void)initializeObserver {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(socketDidOpen)
name:SocketOpenedNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(socketDidClose)
name:SocketClosedNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(socketIsConnecting)
name:SocketConnectingNotification
object:nil];
}
- (void)socketDidOpen {
self.networkStatusLabel.text = NSLocalizedString(@"NETWORK_STATUS_CONNECTED", @"");
self.networkStatusLabel.textColor = [UIColor ows_greenColor];
}
- (void)socketDidClose {
self.networkStatusLabel.text = NSLocalizedString(@"NETWORK_STATUS_OFFLINE", @"");
self.networkStatusLabel.textColor = [UIColor ows_redColor];
}
- (void)socketIsConnecting {
self.networkStatusLabel.text = NSLocalizedString(@"NETWORK_STATUS_CONNECTING", @"");
self.networkStatusLabel.textColor = [UIColor ows_yellowColor];
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
2014-10-29 21:58:58 +01:00
@end