Revise manual censorship circumvention.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-05-16 17:38:20 -04:00
parent e746636c7c
commit c07f28565e
2 changed files with 80 additions and 24 deletions

View File

@ -10,6 +10,7 @@
#import "PushManager.h"
#import "Signal-Swift.h"
#import "TSAccountManager.h"
#import <Reachability/Reachability.h>
#import <SignalServiceKit/OWSSignalService.h>
NS_ASSUME_NONNULL_BEGIN
@ -20,6 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) UISwitch *enableCensorshipCircumventionSwitch;
@property (nonatomic) Reachability *reachability;
@end
#pragma mark -
@ -45,6 +48,8 @@ NS_ASSUME_NONNULL_BEGIN
action:@selector(didToggleEnableCensorshipCircumventionSwitch:)
forControlEvents:UIControlEventValueChanged];
self.reachability = [Reachability reachabilityForInternetConnection];
[self observeNotifications];
[self updateTableContents];
@ -56,6 +61,10 @@ NS_ASSUME_NONNULL_BEGIN
selector:@selector(socketStateDidChange)
name:kNSNotification_SocketManagerStateDidChange
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged)
name:kReachabilityChangedNotification
object:nil];
}
- (void)dealloc
@ -70,6 +79,13 @@ NS_ASSUME_NONNULL_BEGIN
[self updateTableContents];
}
- (void)reachabilityChanged
{
OWSAssert([NSThread isMainThread]);
[self updateTableContents];
}
#pragma mark - Table Contents
- (void)updateTableContents
@ -115,34 +131,65 @@ NS_ASSUME_NONNULL_BEGIN
// Censorship circumvention has certain disadvantages so it should only be
// used if necessary. Therefore:
//
// * We don't show this setting if the user has a phone number from a censored region -
// * We disable this setting if the user has a phone number from a censored region -
// censorship circumvention will be auto-activated for this user.
// * We don't show this setting if the user is already connected; they're not being
// * We disable this setting if the user is already connected; they're not being
// censored.
// * We continue to show this setting so long as it is set to allow users to disable
// it, for example when they leave a censored region.
if (!OWSSignalService.sharedInstance.hasCensoredPhoneNumber
&& (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated ||
[TSSocketManager sharedManager].state != SocketManagerStateOpen)) {
OWSTableSection *censorshipSection = [OWSTableSection new];
censorshipSection.headerTitle = NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_HEADER",
@"Table header for the 'censorship circumvention' section.");
OWSTableSection *censorshipSection = [OWSTableSection new];
censorshipSection.headerTitle = NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_HEADER",
@"Table header for the 'censorship circumvention' section.");
if (OWSSignalService.sharedInstance.hasCensoredPhoneNumber) {
censorshipSection.footerTitle
= NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_AUTO_ENABLED",
@"Table footer for the 'censorship circumvention' section shown when censorship circumvention has been "
@"auto-enabled based on local phone number.");
} else if ([TSSocketManager sharedManager].state == SocketManagerStateOpen) {
censorshipSection.footerTitle
= NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_WEBSOCKET_CONNECTED",
@"Table footer for the 'censorship circumvention' section shown when the app is connected to the "
@"Signal service.");
} else if (!self.reachability.isReachable) {
censorshipSection.footerTitle
= NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_NO_CONNECTION",
@"Table footer for the 'censorship circumvention' section shown when the app is not connected to the "
@"internet.");
} else {
censorshipSection.footerTitle = NSLocalizedString(@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER",
@"Table footer for the 'censorship circumvention' section.");
[pushNotificationsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = NSLocalizedString(
@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION", @"Label for the 'censorship circumvention' switch.");
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
cell.accessoryView = self.enableCensorshipCircumventionSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
actionBlock:nil]];
[contents addSection:censorshipSection];
@"Table footer for the 'censorship circumvention' section when censorship circumvention can be manually "
@"enabled.");
}
[censorshipSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = NSLocalizedString(
@"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION", @"Label for the 'censorship circumvention' switch.");
cell.textLabel.font = [UIFont ows_regularFontWithSize:18.f];
cell.textLabel.textColor = [UIColor blackColor];
// Do enable if :
//
// * ...Censorship circumvention is already manually enabled (to allow users to disable it).
//
// Otherwise, don't enable if:
//
// * ...Censorship circumvention is already enabled based on the local phone number.
// * ...The websocket is connected, since that demonstrates that no censorship is in effect.
// * ...The internet is not reachable, since we don't want to let users to activate
// censorship circumvention unnecessarily, e.g. if they just don't have a valid
// internet connection.
BOOL shouldEnable = (OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated
|| (!OWSSignalService.sharedInstance.hasCensoredPhoneNumber &&
[TSSocketManager sharedManager].state != SocketManagerStateOpen
&& weakSelf.reachability.isReachable));
weakSelf.enableCensorshipCircumventionSwitch.enabled = shouldEnable;
cell.accessoryView = weakSelf.enableCensorshipCircumventionSwitch;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
actionBlock:nil]];
[contents addSection:censorshipSection];
self.contents = contents;
}

View File

@ -1090,8 +1090,17 @@
/* Label for the 'censorship circumvention' switch. */
"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION" = "Censorship Circumvention";
/* Table footer for the 'censorship circumvention' section. */
"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER" = "Do not enable this feature unless you are in a location where Signal is censored.";
/* Table footer for the 'censorship circumvention' section when censorship circumvention can be manually enabled. */
"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER" = "If enabled, Signal will attempt to circumvent censorship. Do not enable this feature unless you are in a location where Signal is censored.";
/* Table footer for the 'censorship circumvention' section shown when censorship circumvention has been auto-enabled based on local phone number. */
"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_AUTO_ENABLED" = "Censorship circumvention has been activated based on your account's phone number.";
/* Table footer for the 'censorship circumvention' section shown when the app is not connected to the internet. */
"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_NO_CONNECTION" = "Censorship circumvention can only be activated when connected to the internet.";
/* Table footer for the 'censorship circumvention' section shown when the app is connected to the Signal service. */
"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_FOOTER_WEBSOCKET_CONNECTED" = "Censorship circumvention is not necessary; you are already connected to the Signal service.";
/* Table header for the 'censorship circumvention' section. */
"SETTINGS_ADVANCED_CENSORSHIP_CIRCUMVENTION_HEADER" = "Censorship Circumvention";