mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
186 lines
5.9 KiB
Mathematica
186 lines
5.9 KiB
Mathematica
|
//
|
||
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "BlockListViewController.h"
|
||
|
#import "DebugLogger.h"
|
||
|
#import "Environment.h"
|
||
|
#import "Pastelog.h"
|
||
|
#import "PropertyListPreferences.h"
|
||
|
#import "PushManager.h"
|
||
|
#import "Signal-Swift.h"
|
||
|
#import "TSAccountManager.h"
|
||
|
#import <PromiseKit/AnyPromise.h>
|
||
|
|
||
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
@interface BlockListViewController ()
|
||
|
|
||
|
@property (nonatomic) UITableViewCell *enableLogCell;
|
||
|
@property (nonatomic) UITableViewCell *submitLogCell;
|
||
|
@property (nonatomic) UITableViewCell *registerPushCell;
|
||
|
|
||
|
@property (nonatomic) UISwitch *enableLogSwitch;
|
||
|
@property (nonatomic, readonly) BOOL supportsCallKit;
|
||
|
|
||
|
@end
|
||
|
|
||
|
typedef NS_ENUM(NSInteger, BlockListViewControllerSection) {
|
||
|
BlockListViewControllerSectionLogging,
|
||
|
BlockListViewControllerSectionPushNotifications,
|
||
|
BlockListViewControllerSection_Count // meta section
|
||
|
};
|
||
|
|
||
|
@implementation BlockListViewController
|
||
|
|
||
|
- (void)viewDidLoad
|
||
|
{
|
||
|
[super viewDidLoad];
|
||
|
[self.navigationController.navigationBar setTranslucent:NO];
|
||
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
||
|
}
|
||
|
|
||
|
- (instancetype)init
|
||
|
{
|
||
|
return [super initWithStyle:UITableViewStyleGrouped];
|
||
|
}
|
||
|
|
||
|
- (void)loadView
|
||
|
{
|
||
|
[super loadView];
|
||
|
|
||
|
self.title = NSLocalizedString(@"SETTINGS_ADVANCED_TITLE", @"");
|
||
|
|
||
|
// Enable Log
|
||
|
self.enableLogCell = [[UITableViewCell alloc] init];
|
||
|
self.enableLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"");
|
||
|
self.enableLogCell.userInteractionEnabled = YES;
|
||
|
self.enableLogSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
|
||
|
[self.enableLogSwitch setOn:[PropertyListPreferences loggingIsEnabled]];
|
||
|
[self.enableLogSwitch addTarget:self
|
||
|
action:@selector(didToggleEnableLogSwitch:)
|
||
|
forControlEvents:UIControlEventValueChanged];
|
||
|
self.enableLogCell.accessoryView = self.enableLogSwitch;
|
||
|
|
||
|
// Send Log
|
||
|
self.submitLogCell = [[UITableViewCell alloc] init];
|
||
|
self.submitLogCell.textLabel.text = NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"");
|
||
|
|
||
|
self.registerPushCell = [[UITableViewCell alloc] init];
|
||
|
self.registerPushCell.textLabel.text = NSLocalizedString(@"REREGISTER_FOR_PUSH", nil);
|
||
|
}
|
||
|
|
||
|
#pragma mark - Table view data source
|
||
|
|
||
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||
|
{
|
||
|
return BlockListViewControllerSection_Count;
|
||
|
}
|
||
|
|
||
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||
|
{
|
||
|
|
||
|
BlockListViewControllerSection settingsSection = (BlockListViewControllerSection)section;
|
||
|
switch (settingsSection) {
|
||
|
case BlockListViewControllerSectionLogging:
|
||
|
return self.enableLogSwitch.isOn ? 2 : 1;
|
||
|
case BlockListViewControllerSectionPushNotifications:
|
||
|
return 1;
|
||
|
default:
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
||
|
{
|
||
|
BlockListViewControllerSection settingsSection = (BlockListViewControllerSection)section;
|
||
|
switch (settingsSection) {
|
||
|
case BlockListViewControllerSectionLogging:
|
||
|
return NSLocalizedString(@"LOGGING_SECTION", nil);
|
||
|
case BlockListViewControllerSectionPushNotifications:
|
||
|
return NSLocalizedString(
|
||
|
@"PUSH_REGISTER_TITLE", @"Used in table section header and alert view title contexts");
|
||
|
default:
|
||
|
return nil;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||
|
{
|
||
|
BlockListViewControllerSection settingsSection = (BlockListViewControllerSection)indexPath.section;
|
||
|
switch (settingsSection) {
|
||
|
case BlockListViewControllerSectionLogging:
|
||
|
switch (indexPath.row) {
|
||
|
case 0:
|
||
|
return self.enableLogCell;
|
||
|
case 1:
|
||
|
OWSAssert(self.enableLogSwitch.isOn);
|
||
|
return self.submitLogCell;
|
||
|
}
|
||
|
case BlockListViewControllerSectionPushNotifications:
|
||
|
return self.registerPushCell;
|
||
|
default:
|
||
|
// Unknown section
|
||
|
OWSAssert(NO);
|
||
|
return nil;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||
|
{
|
||
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||
|
|
||
|
if ([tableView cellForRowAtIndexPath:indexPath] == self.submitLogCell) {
|
||
|
DDLogInfo(@"%@ Submitting debug logs", self.tag);
|
||
|
[DDLog flushLog];
|
||
|
[Pastelog submitLogs];
|
||
|
} else if ([tableView cellForRowAtIndexPath:indexPath] == self.registerPushCell) {
|
||
|
OWSSyncPushTokensJob *syncJob =
|
||
|
[[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager]
|
||
|
accountManager:[Environment getCurrent].accountManager
|
||
|
preferences:[Environment preferences]];
|
||
|
syncJob.uploadOnlyIfStale = NO;
|
||
|
[syncJob run]
|
||
|
.then(^{
|
||
|
SignalAlertView(NSLocalizedString(@"PUSH_REGISTER_SUCCESS", @"Alert title"), nil);
|
||
|
})
|
||
|
.catch(^(NSError *error) {
|
||
|
SignalAlertView(NSLocalizedString(@"REGISTRATION_BODY", @"Alert title"), error.localizedDescription);
|
||
|
});
|
||
|
|
||
|
} else {
|
||
|
DDLogDebug(@"%@ Ignoring cell selection at indexPath: %@", self.tag, indexPath);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#pragma mark - Actions
|
||
|
|
||
|
- (void)didToggleEnableLogSwitch:(UISwitch *)sender
|
||
|
{
|
||
|
if (!sender.isOn) {
|
||
|
[[DebugLogger sharedLogger] wipeLogs];
|
||
|
[[DebugLogger sharedLogger] disableFileLogging];
|
||
|
} else {
|
||
|
[[DebugLogger sharedLogger] enableFileLogging];
|
||
|
}
|
||
|
|
||
|
[PropertyListPreferences setLoggingEnabled:sender.isOn];
|
||
|
[self.tableView reloadData];
|
||
|
}
|
||
|
|
||
|
#pragma mark - Logging
|
||
|
|
||
|
+ (NSString *)tag
|
||
|
{
|
||
|
return [NSString stringWithFormat:@"[%@]", self.class];
|
||
|
}
|
||
|
|
||
|
- (NSString *)tag
|
||
|
{
|
||
|
return self.class.tag;
|
||
|
}
|
||
|
|
||
|
@end
|
||
|
|
||
|
NS_ASSUME_NONNULL_END
|