session-ios/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m
2017-07-28 11:15:09 -04:00

91 lines
2.9 KiB
Objective-C

//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "DebugUIMisc.h"
#import "Environment.h"
#import "OWSCountryMetadata.h"
#import "OWSTableViewController.h"
#import "SecurityUtils.h"
#import "Signal-Swift.h"
#import "ThreadUtil.h"
#import <AFNetworking/AFNetworking.h>
#import <AxolotlKit/PreKeyBundle.h>
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
#import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
#import <SignalServiceKit/TSCall.h>
#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SignalServiceKit/TSStorageManager+SessionStore.h>
#import <SignalServiceKit/TSThread.h>
NS_ASSUME_NONNULL_BEGIN
@implementation DebugUIMisc
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
#pragma mark - Factory Methods
- (NSString *)name
{
return @"Misc.";
}
- (nullable OWSTableSection *)sectionForThread:(nullable TSThread *)thread
{
OWSAssert(thread);
NSMutableArray<OWSTableItem *> *items = [NSMutableArray new];
[items addObject:[OWSTableItem itemWithTitle:@"Enable Manual Censorship Circumvention"
actionBlock:^{
[DebugUIMisc setManualCensorshipCircumventionEnabled:YES];
}]];
[items addObject:[OWSTableItem itemWithTitle:@"Disable Manual Censorship Circumvention"
actionBlock:^{
[DebugUIMisc setManualCensorshipCircumventionEnabled:NO];
}]];
return [OWSTableSection sectionWithTitle:self.name items:items];
}
+ (void)setManualCensorshipCircumventionEnabled:(BOOL)isEnabled
{
OWSCountryMetadata *countryMetadata = nil;
NSString *countryCode = OWSSignalService.sharedInstance.manualCensorshipCircumventionCountryCode;
if (countryCode) {
countryMetadata = [OWSCountryMetadata countryMetadataForCountryCode:countryCode];
}
if (!countryMetadata) {
countryCode = [NSLocale.currentLocale objectForKey:NSLocaleCountryCode];
if (countryCode) {
countryMetadata = [OWSCountryMetadata countryMetadataForCountryCode:countryCode];
}
}
if (!countryMetadata) {
countryCode = @"US";
countryMetadata = [OWSCountryMetadata countryMetadataForCountryCode:countryCode];
}
OWSAssert(countryMetadata);
OWSSignalService.sharedInstance.manualCensorshipCircumventionCountryCode = countryCode;
OWSSignalService.sharedInstance.manualCensorshipCircumventionDomain = countryMetadata.googleDomain;
OWSSignalService.sharedInstance.isCensorshipCircumventionManuallyActivated = isEnabled;
}
@end
NS_ASSUME_NONNULL_END