From 4bb702fe0ddff576db4fc1e752727d8a7af31a87 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 10 May 2017 16:40:35 -0400 Subject: [PATCH] Add support for manually activating censorship circumvention. // FREEBIE --- Signal/src/Storyboard/Main.storyboard | 272 +----------- .../SettingsTableViewController.h | 30 +- .../SettingsTableViewController.m | 386 ++++++++++-------- .../SignalsNavigationController.m | 89 ++-- 4 files changed, 270 insertions(+), 507 deletions(-) diff --git a/Signal/src/Storyboard/Main.storyboard b/Signal/src/Storyboard/Main.storyboard index 164168676..f8497565d 100644 --- a/Signal/src/Storyboard/Main.storyboard +++ b/Signal/src/Storyboard/Main.storyboard @@ -524,267 +524,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - @@ -801,28 +545,28 @@ - + - + - + - + - + @@ -980,7 +724,7 @@ - + diff --git a/Signal/src/ViewControllers/SettingsTableViewController.h b/Signal/src/ViewControllers/SettingsTableViewController.h index e7bc2e0ec..c41d718b1 100644 --- a/Signal/src/ViewControllers/SettingsTableViewController.h +++ b/Signal/src/ViewControllers/SettingsTableViewController.h @@ -2,22 +2,22 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import +#import "OWSTableViewController.h" -@interface SettingsTableViewController : UITableViewController +@interface SettingsTableViewController : OWSTableViewController -@property (strong, nonatomic) IBOutlet UILabel *registeredName; -@property (strong, nonatomic) IBOutlet UILabel *registeredNumber; -@property (strong, nonatomic) IBOutlet UILabel *networkStatusLabel; -@property (strong, nonatomic) IBOutlet UILabel *networkStatusHeader; -@property (strong, nonatomic) IBOutlet UILabel *privacyLabel; -@property (strong, nonatomic) IBOutlet UILabel *notificationsLabel; -@property (strong, nonatomic) IBOutlet UILabel *linkedDevicesLabel; -@property (strong, nonatomic) IBOutlet UILabel *advancedLabel; -@property (strong, nonatomic) IBOutlet UILabel *aboutLabel; -@property (strong, nonatomic) IBOutlet UILabel *inviteLabel; -@property (strong, nonatomic) IBOutlet UIButton *destroyAccountButton; - -- (IBAction)unregisterUser:(id)sender; +//@property (strong, nonatomic) IBOutlet UILabel *registeredName; +//@property (strong, nonatomic) IBOutlet UILabel *registeredNumber; +//@property (strong, nonatomic) IBOutlet UILabel *networkStatusLabel; +//@property (strong, nonatomic) IBOutlet UILabel *networkStatusHeader; +//@property (strong, nonatomic) IBOutlet UILabel *privacyLabel; +//@property (strong, nonatomic) IBOutlet UILabel *notificationsLabel; +//@property (strong, nonatomic) IBOutlet UILabel *linkedDevicesLabel; +//@property (strong, nonatomic) IBOutlet UILabel *advancedLabel; +//@property (strong, nonatomic) IBOutlet UILabel *aboutLabel; +//@property (strong, nonatomic) IBOutlet UILabel *inviteLabel; +//@property (strong, nonatomic) IBOutlet UIButton *destroyAccountButton; +// +//- (IBAction)unregisterUser:(id)sender; @end diff --git a/Signal/src/ViewControllers/SettingsTableViewController.m b/Signal/src/ViewControllers/SettingsTableViewController.m index fe2d4bd86..c821aad02 100644 --- a/Signal/src/ViewControllers/SettingsTableViewController.m +++ b/Signal/src/ViewControllers/SettingsTableViewController.m @@ -16,35 +16,35 @@ #import "PushManager.h" #import "Signal-Swift.h" -#define kProfileCellHeight 87.0f -#define kStandardCellHeight 44.0f - -#define kNumberOfSections 4 - -#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 - -typedef enum { - kRegisteredRows = 1, - kNetworkStatusRows = 1, - kGeneralRows = 6, - kUnregisterRows = 1, -} kRowsForSection; - -typedef enum { - kRegisteredNumberSection = 0, - kNetworkStatusSection = 1, - kGeneralSection = 2, - kUnregisterSection = 3, -} kSection; +//#define kProfileCellHeight 87.0f +//#define kStandardCellHeight 44.0f +// +//#define kNumberOfSections 4 +// +//#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 +// +//typedef enum { +// kRegisteredRows = 1, +// kNetworkStatusRows = 1, +// kGeneralRows = 6, +// kUnregisterRows = 1, +//} kRowsForSection; +// +//typedef enum { +// kRegisteredNumberSection = 0, +// kNetworkStatusSection = 1, +// kGeneralSection = 2, +// kUnregisterSection = 3, +//} kSection; @interface SettingsTableViewController () @@ -52,6 +52,8 @@ typedef enum { @end +#pragma mark - + @implementation SettingsTableViewController - (instancetype)init @@ -85,143 +87,186 @@ typedef enum { [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.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]; + +// 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]; + + [self updateTableContents]; } -- (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)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]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; } -#pragma mark - Table view data source - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return kNumberOfSections; -} +#pragma mark - Table Contents -- (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; - 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 - contactsManager:self.contactsManager]; - [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; - } - - case kNetworkStatusSection: { - break; - } - - case kUnregisterSection: { - [self unregisterUser:nil]; - break; +- (void)updateTableContents +{ + OWSTableContents *contents = [OWSTableContents new]; + OWSTableSection *section = [OWSTableSection new]; + + // Find Non-Contacts by Phone Number + [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ + UITableViewCell *cell = [UITableViewCell new]; + cell.textLabel.text = NSLocalizedString( + @"NETWORK_STATUS_HEADER", @""); + cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f]; + cell.textLabel.textColor = [UIColor blackColor]; + + UILabel *accessoryLabel = [UILabel new]; + accessoryLabel.font = [UIFont ows_regularFontWithSize:18.f]; + switch ([TSSocketManager sharedManager].state) { + case SocketManagerStateClosed: + accessoryLabel.text = NSLocalizedString(@"NETWORK_STATUS_OFFLINE", @""); + accessoryLabel.textColor = [UIColor ows_redColor]; + break; + case SocketManagerStateConnecting: + accessoryLabel.text = NSLocalizedString(@"NETWORK_STATUS_CONNECTING", @""); + accessoryLabel.textColor = [UIColor ows_yellowColor]; + break; + case SocketManagerStateOpen: + accessoryLabel.text = NSLocalizedString(@"NETWORK_STATUS_CONNECTED", @""); + accessoryLabel.textColor = [UIColor ows_greenColor]; + break; } - - default: - break; + [accessoryLabel sizeToFit]; + cell.accessoryView = accessoryLabel; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + return cell; } + actionBlock:nil]]; + + [contents addSection:section]; + + self.contents = contents; } +#pragma mark - Table view data source -- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath { - switch (indexPath.section) { - case kNetworkStatusSection: { - return NO; - } - - case kUnregisterSection: { - return NO; - } - - default: - return YES; - } -} +//- (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; +// 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 +// contactsManager:self.contactsManager]; +// [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; +// } +// +// 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 { @@ -250,43 +295,26 @@ typedef enum { }]; } -- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { - if (indexPath.section == kNetworkStatusSection) { - [OWSAlerts showAlertWithTitle:NSLocalizedString(@"NETWORK_STATUS_HEADER", @"") - message:NSLocalizedString(@"NETWORK_STATUS_TEXT", @"")]; - } -} +//- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { +// if (indexPath.section == kNetworkStatusSection) { +// [OWSAlerts showAlertWithTitle:NSLocalizedString(@"NETWORK_STATUS_HEADER", @"") +// message:NSLocalizedString(@"NETWORK_STATUS_TEXT", @"")]; +// } +//} #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 + selector:@selector(socketStateDidChange) + name:kNSNotification_SocketManagerStateDidChange 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]; +- (void)socketStateDidChange { + OWSAssert([NSThread isMainThread]); + + [self updateTableContents]; } #pragma mark - Logging diff --git a/Signal/src/ViewControllers/SignalsNavigationController.m b/Signal/src/ViewControllers/SignalsNavigationController.m index 69da006eb..d82f5eabc 100644 --- a/Signal/src/ViewControllers/SignalsNavigationController.m +++ b/Signal/src/ViewControllers/SignalsNavigationController.m @@ -1,9 +1,5 @@ // -// SignalsNavigationController.m -// Signal -// -// Created by Dylan Bourgeois on 18/11/14. -// Copyright (c) 2014 Open Whisper Systems. All rights reserved. +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // #import "SignalsNavigationController.h" @@ -22,7 +18,7 @@ static double const STALLED_PROGRESS = 0.9; [super viewDidLoad]; // Do any additional setup after loading the view. [self initializeObserver]; - [TSSocketManager sendNotification]; + [self updateSocketStatusView]; } - (void)initializeSocketStatusBar { @@ -48,57 +44,52 @@ static double const STALLED_PROGRESS = 0.9; - (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 + selector:@selector(socketManagerStateDidChange) + name:kNSNotification_SocketManagerStateDidChange object:nil]; } -- (void)socketDidOpen { - dispatch_async(dispatch_get_main_queue(), ^{ - [_updateStatusTimer invalidate]; - for (UIView *view in self.navigationBar.subviews) { - if ([view isKindOfClass:[UIProgressView class]]) { - [view removeFromSuperview]; - _socketStatusView = nil; - } - } - }); +- (void)socketManagerStateDidChange { + OWSAssert([NSThread isMainThread]); + + [self updateSocketStatusView]; } -- (void)socketDidClose { - dispatch_async(dispatch_get_main_queue(), ^{ - if (_socketStatusView == nil) { - [self initializeSocketStatusBar]; - _updateStatusTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 - target:self - selector:@selector(updateSocketConnecting) - userInfo:nil - repeats:YES]; - - } else if (_socketStatusView.progress >= STALLED_PROGRESS) { +- (void)updateSocketStatusView { + OWSAssert([NSThread isMainThread]); + + switch ([TSSocketManager sharedManager].state) { + case SocketManagerStateClosed: + if (_socketStatusView == nil) { + [self initializeSocketStatusBar]; + _updateStatusTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 + target:self + selector:@selector(updateProgress) + userInfo:nil + repeats:YES]; + + } else if (_socketStatusView.progress >= STALLED_PROGRESS) { + [_updateStatusTimer invalidate]; + } + break; + case SocketManagerStateConnecting: + // Do nothing. + break; + case SocketManagerStateOpen: [_updateStatusTimer invalidate]; - } - }); -} - -- (void)updateSocketConnecting { - dispatch_async(dispatch_get_main_queue(), ^{ - double progress = _socketStatusView.progress + 0.05; - _socketStatusView.progress = (float)MIN(progress, STALLED_PROGRESS); - }); + for (UIView *view in self.navigationBar.subviews) { + if ([view isKindOfClass:[UIProgressView class]]) { + [view removeFromSuperview]; + _socketStatusView = nil; + } + } + break; + } } -- (void)socketIsConnecting { - // Nothing to see here currently +- (void)updateProgress { + double progress = _socketStatusView.progress + 0.05; + _socketStatusView.progress = (float) MIN(progress, STALLED_PROGRESS); } - @end