2015-01-16 15:28:41 +01:00
|
|
|
//
|
2017-01-12 21:37:37 +01:00
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
2015-01-16 15:28:41 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "AdvancedSettingsTableViewController.h"
|
|
|
|
#import "DebugLogger.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
#import "Environment.h"
|
2016-10-10 22:02:09 +02:00
|
|
|
#import "PropertyListPreferences.h"
|
2015-04-28 14:41:50 +02:00
|
|
|
#import "PushManager.h"
|
2016-10-10 22:02:09 +02:00
|
|
|
#import "Signal-Swift.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
#import "TSAccountManager.h"
|
2017-03-17 22:33:42 +01:00
|
|
|
#import "Pastelog.h"
|
2016-10-10 22:02:09 +02:00
|
|
|
#import <PromiseKit/AnyPromise.h>
|
2015-01-16 15:28:41 +01:00
|
|
|
|
2016-10-10 22:02:09 +02:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
2015-01-16 15:28:41 +01:00
|
|
|
|
|
|
|
@interface AdvancedSettingsTableViewController ()
|
|
|
|
|
2017-01-12 21:37:37 +01:00
|
|
|
@property (nonatomic) UITableViewCell *enableLogCell;
|
|
|
|
@property (nonatomic) UITableViewCell *submitLogCell;
|
|
|
|
@property (nonatomic) UITableViewCell *registerPushCell;
|
2015-01-16 15:28:41 +01:00
|
|
|
|
2017-01-12 21:37:37 +01:00
|
|
|
@property (nonatomic) UISwitch *enableLogSwitch;
|
2017-02-02 18:21:48 +01:00
|
|
|
@property (nonatomic, readonly) BOOL supportsCallKit;
|
2016-10-10 22:02:09 +02:00
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
@end
|
|
|
|
|
2017-02-02 18:21:48 +01:00
|
|
|
typedef NS_ENUM(NSInteger, AdvancedSettingsTableViewControllerSection) {
|
|
|
|
AdvancedSettingsTableViewControllerSectionLogging,
|
|
|
|
AdvancedSettingsTableViewControllerSectionPushNotifications,
|
|
|
|
AdvancedSettingsTableViewControllerSection_Count // meta section
|
|
|
|
};
|
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
@implementation AdvancedSettingsTableViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
2015-04-28 14:41:50 +02:00
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
2015-12-22 12:45:09 +01:00
|
|
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
|
2017-02-02 18:21:48 +01:00
|
|
|
- (instancetype)init
|
|
|
|
{
|
2015-01-16 15:28:41 +01:00
|
|
|
return [super initWithStyle:UITableViewStyleGrouped];
|
|
|
|
}
|
|
|
|
|
2017-02-02 18:21:48 +01:00
|
|
|
- (void)loadView
|
|
|
|
{
|
2015-01-16 15:28:41 +01:00
|
|
|
[super loadView];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2015-02-18 23:21:03 +01:00
|
|
|
self.title = NSLocalizedString(@"SETTINGS_ADVANCED_TITLE", @"");
|
2017-01-12 21:37:37 +01:00
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
// Enable Log
|
|
|
|
self.enableLogCell = [[UITableViewCell alloc] init];
|
|
|
|
self.enableLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"");
|
2015-01-16 15:28:41 +01:00
|
|
|
self.enableLogCell.userInteractionEnabled = YES;
|
2015-12-22 12:45:09 +01:00
|
|
|
self.enableLogSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
|
2017-03-13 14:33:58 +01:00
|
|
|
[self.enableLogSwitch setOn:[PropertyListPreferences loggingIsEnabled]];
|
2015-12-22 12:45:09 +01:00
|
|
|
[self.enableLogSwitch addTarget:self
|
2017-01-12 21:37:37 +01:00
|
|
|
action:@selector(didToggleEnableLogSwitch:)
|
2017-03-22 20:38:00 +01:00
|
|
|
forControlEvents:UIControlEventValueChanged];
|
2015-01-16 15:28:41 +01:00
|
|
|
self.enableLogCell.accessoryView = self.enableLogSwitch;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
// Send Log
|
|
|
|
self.submitLogCell = [[UITableViewCell alloc] init];
|
2015-02-18 23:21:03 +01:00
|
|
|
self.submitLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"");
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
self.registerPushCell = [[UITableViewCell alloc] init];
|
2015-04-28 14:41:50 +02:00
|
|
|
self.registerPushCell.textLabel.text = NSLocalizedString(@"REREGISTER_FOR_PUSH", nil);
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
2017-02-02 18:21:48 +01:00
|
|
|
return AdvancedSettingsTableViewControllerSection_Count;
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
2017-02-02 18:21:48 +01:00
|
|
|
|
|
|
|
AdvancedSettingsTableViewControllerSection settingsSection = (AdvancedSettingsTableViewControllerSection)section;
|
|
|
|
switch (settingsSection) {
|
|
|
|
case AdvancedSettingsTableViewControllerSectionLogging:
|
|
|
|
return self.enableLogSwitch.isOn ? 2 : 1;
|
|
|
|
case AdvancedSettingsTableViewControllerSectionPushNotifications:
|
2015-04-28 14:41:50 +02:00
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
|
2016-10-10 22:02:09 +02:00
|
|
|
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
|
|
|
{
|
2017-02-02 18:21:48 +01:00
|
|
|
AdvancedSettingsTableViewControllerSection settingsSection = (AdvancedSettingsTableViewControllerSection)section;
|
|
|
|
switch (settingsSection) {
|
|
|
|
case AdvancedSettingsTableViewControllerSectionLogging:
|
|
|
|
return NSLocalizedString(@"LOGGING_SECTION", nil);
|
|
|
|
case AdvancedSettingsTableViewControllerSectionPushNotifications:
|
|
|
|
return NSLocalizedString(@"PUSH_REGISTER_TITLE", @"Used in table section header and alert view title contexts");
|
|
|
|
default:
|
2017-02-03 01:12:07 +01:00
|
|
|
return nil;
|
2017-02-02 18:21:48 +01:00
|
|
|
}
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
|
2017-02-02 18:21:48 +01:00
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
AdvancedSettingsTableViewControllerSection settingsSection = (AdvancedSettingsTableViewControllerSection)indexPath.section;
|
|
|
|
switch (settingsSection) {
|
|
|
|
case AdvancedSettingsTableViewControllerSectionLogging:
|
|
|
|
switch (indexPath.row) {
|
|
|
|
case 0:
|
|
|
|
return self.enableLogCell;
|
|
|
|
case 1:
|
|
|
|
OWSAssert(self.enableLogSwitch.isOn);
|
|
|
|
return self.submitLogCell;
|
|
|
|
}
|
|
|
|
case AdvancedSettingsTableViewControllerSectionPushNotifications:
|
|
|
|
return self.registerPushCell;
|
|
|
|
default:
|
|
|
|
// Unknown section
|
|
|
|
OWSAssert(NO);
|
|
|
|
return nil;
|
|
|
|
}
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
2015-01-16 15:28:41 +01:00
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
if ([tableView cellForRowAtIndexPath:indexPath] == self.submitLogCell) {
|
2017-03-27 15:12:39 +02:00
|
|
|
DDLogInfo(@"%@ Submitting debug logs", self.tag);
|
2017-02-14 16:35:24 +01:00
|
|
|
[DDLog flushLog];
|
2015-01-16 15:28:41 +01:00
|
|
|
[Pastelog submitLogs];
|
2015-04-28 14:41:50 +02:00
|
|
|
} else if ([tableView cellForRowAtIndexPath:indexPath] == self.registerPushCell) {
|
2016-11-12 18:22:29 +01:00
|
|
|
OWSSyncPushTokensJob *syncJob =
|
|
|
|
[[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager]
|
|
|
|
accountManager:[Environment getCurrent].accountManager
|
|
|
|
preferences:[Environment preferences]];
|
2016-10-10 22:02:09 +02:00
|
|
|
syncJob.uploadOnlyIfStale = NO;
|
|
|
|
[syncJob run]
|
|
|
|
.then(^{
|
2017-05-08 23:01:50 +02:00
|
|
|
DDLogDebug(@"%@ Successfully ran syncPushTokensJob.", self.tag);
|
2016-10-10 22:02:09 +02:00
|
|
|
SignalAlertView(NSLocalizedString(@"PUSH_REGISTER_SUCCESS", @"Alert title"), nil);
|
|
|
|
})
|
|
|
|
.catch(^(NSError *error) {
|
2017-05-08 23:01:50 +02:00
|
|
|
DDLogError(@"%@ Failed to run syncPushTokensJob with error: %@", self.tag, error);
|
2016-10-10 22:02:09 +02:00
|
|
|
SignalAlertView(NSLocalizedString(@"REGISTRATION_BODY", @"Alert title"), error.localizedDescription);
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
DDLogDebug(@"%@ Ignoring cell selection at indexPath: %@", self.tag, indexPath);
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Actions
|
|
|
|
|
2017-01-12 21:37:37 +01:00
|
|
|
- (void)didToggleEnableLogSwitch:(UISwitch *)sender {
|
2015-01-16 15:28:41 +01:00
|
|
|
if (!sender.isOn) {
|
2015-12-22 12:45:09 +01:00
|
|
|
[[DebugLogger sharedLogger] wipeLogs];
|
|
|
|
[[DebugLogger sharedLogger] disableFileLogging];
|
2015-01-16 15:28:41 +01:00
|
|
|
} else {
|
2015-12-22 12:45:09 +01:00
|
|
|
[[DebugLogger sharedLogger] enableFileLogging];
|
2015-01-16 15:28:41 +01:00
|
|
|
}
|
2017-01-12 21:37:37 +01:00
|
|
|
|
2017-03-13 14:33:58 +01:00
|
|
|
[PropertyListPreferences setLoggingEnabled:sender.isOn];
|
2015-01-16 15:28:41 +01:00
|
|
|
[self.tableView reloadData];
|
|
|
|
}
|
|
|
|
|
2016-10-10 22:02:09 +02:00
|
|
|
#pragma mark - Logging
|
|
|
|
|
|
|
|
+ (NSString *)tag
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"[%@]", self.class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)tag
|
|
|
|
{
|
|
|
|
return self.class.tag;
|
|
|
|
}
|
|
|
|
|
2015-01-16 15:28:41 +01:00
|
|
|
@end
|
2016-10-10 22:02:09 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|