Merge branch 'charlesmchen/backupRestoreFlow'

pull/1/head
Matthew Chen 7 years ago
commit 8868e0a555

@ -129,6 +129,7 @@
346941A3215D2EE400B5BFAD /* Theme.m in Sources */ = {isa = PBXBuildFile; fileRef = 3469419F215D2EE400B5BFAD /* Theme.m */; }; 346941A3215D2EE400B5BFAD /* Theme.m in Sources */ = {isa = PBXBuildFile; fileRef = 3469419F215D2EE400B5BFAD /* Theme.m */; };
346941A4215D2EE400B5BFAD /* OWSConversationColor.h in Headers */ = {isa = PBXBuildFile; fileRef = 346941A0215D2EE400B5BFAD /* OWSConversationColor.h */; settings = {ATTRIBUTES = (Public, ); }; }; 346941A4215D2EE400B5BFAD /* OWSConversationColor.h in Headers */ = {isa = PBXBuildFile; fileRef = 346941A0215D2EE400B5BFAD /* OWSConversationColor.h */; settings = {ATTRIBUTES = (Public, ); }; };
346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */; }; 346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */; };
346E9D5421B040B700562252 /* RegistrationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346E9D5321B040B600562252 /* RegistrationController.swift */; };
347850311FD7494A007B8332 /* dripicons-v2.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5B1E787A9800DF2FB9 /* dripicons-v2.ttf */; }; 347850311FD7494A007B8332 /* dripicons-v2.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5B1E787A9800DF2FB9 /* dripicons-v2.ttf */; };
347850321FD7494A007B8332 /* ElegantIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5D1E787BD800DF2FB9 /* ElegantIcons.ttf */; }; 347850321FD7494A007B8332 /* ElegantIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5D1E787BD800DF2FB9 /* ElegantIcons.ttf */; };
347850331FD7494A007B8332 /* fontawesome-webfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A591E7875FB00DF2FB9 /* fontawesome-webfont.ttf */; }; 347850331FD7494A007B8332 /* fontawesome-webfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A591E7875FB00DF2FB9 /* fontawesome-webfont.ttf */; };
@ -781,6 +782,7 @@
3469419F215D2EE400B5BFAD /* Theme.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Theme.m; sourceTree = "<group>"; }; 3469419F215D2EE400B5BFAD /* Theme.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Theme.m; sourceTree = "<group>"; };
346941A0215D2EE400B5BFAD /* OWSConversationColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSConversationColor.h; sourceTree = "<group>"; }; 346941A0215D2EE400B5BFAD /* OWSConversationColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSConversationColor.h; sourceTree = "<group>"; };
346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CropScaleImageViewController.swift; sourceTree = "<group>"; }; 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CropScaleImageViewController.swift; sourceTree = "<group>"; };
346E9D5321B040B600562252 /* RegistrationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegistrationController.swift; sourceTree = "<group>"; };
347850561FD86544007B8332 /* SAEFailedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SAEFailedViewController.swift; sourceTree = "<group>"; }; 347850561FD86544007B8332 /* SAEFailedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SAEFailedViewController.swift; sourceTree = "<group>"; };
3478505A1FD999D5007B8332 /* et */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = et; path = translations/et.lproj/Localizable.strings; sourceTree = "<group>"; }; 3478505A1FD999D5007B8332 /* et */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = et; path = translations/et.lproj/Localizable.strings; sourceTree = "<group>"; };
3478505C1FD99A1F007B8332 /* zh_TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = zh_TW; path = translations/zh_TW.lproj/Localizable.strings; sourceTree = "<group>"; }; 3478505C1FD99A1F007B8332 /* zh_TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = zh_TW; path = translations/zh_TW.lproj/Localizable.strings; sourceTree = "<group>"; };
@ -1427,6 +1429,7 @@
3441FD9E21A3604F00BB9542 /* BackupRestoreViewController.swift */, 3441FD9E21A3604F00BB9542 /* BackupRestoreViewController.swift */,
340FC879204DAC8C007AEB0F /* CodeVerificationViewController.h */, 340FC879204DAC8C007AEB0F /* CodeVerificationViewController.h */,
340FC877204DAC8C007AEB0F /* CodeVerificationViewController.m */, 340FC877204DAC8C007AEB0F /* CodeVerificationViewController.m */,
346E9D5321B040B600562252 /* RegistrationController.swift */,
340FC878204DAC8C007AEB0F /* RegistrationViewController.h */, 340FC878204DAC8C007AEB0F /* RegistrationViewController.h */,
340FC876204DAC8C007AEB0F /* RegistrationViewController.m */, 340FC876204DAC8C007AEB0F /* RegistrationViewController.m */,
); );
@ -3425,6 +3428,7 @@
451166C01FD86B98000739BA /* AccountManager.swift in Sources */, 451166C01FD86B98000739BA /* AccountManager.swift in Sources */,
3430FE181F7751D4000EC51B /* GiphyAPI.swift in Sources */, 3430FE181F7751D4000EC51B /* GiphyAPI.swift in Sources */,
4C2F454F214C00E1004871FF /* AvatarTableViewCell.swift in Sources */, 4C2F454F214C00E1004871FF /* AvatarTableViewCell.swift in Sources */,
346E9D5421B040B700562252 /* RegistrationController.swift in Sources */,
34A55F3720485465002CC6DE /* OWS2FARegistrationViewController.m in Sources */, 34A55F3720485465002CC6DE /* OWS2FARegistrationViewController.m in Sources */,
340FC8AD204DAC8D007AEB0F /* OWSLinkedDevicesTableViewController.m in Sources */, 340FC8AD204DAC8D007AEB0F /* OWSLinkedDevicesTableViewController.m in Sources */,
340FC8AA204DAC8D007AEB0F /* NotificationSettingsViewController.m in Sources */, 340FC8AA204DAC8D007AEB0F /* NotificationSettingsViewController.m in Sources */,

@ -41,9 +41,9 @@ public class AccountManager: NSObject {
// MARK: registration // MARK: registration
@objc func register(verificationCode: String, @objc func registerObjc(verificationCode: String,
pin: String?) -> AnyPromise { pin: String?) -> AnyPromise {
return AnyPromise(register(verificationCode: verificationCode, pin: pin) as Promise<Void>) return AnyPromise(register(verificationCode: verificationCode, pin: pin))
} }
func register(verificationCode: String, func register(verificationCode: String,

@ -15,7 +15,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWS2FARegistrationViewController () <PinEntryViewDelegate> @interface OWS2FARegistrationViewController () <PinEntryViewDelegate>
@property (nonatomic, readonly) AccountManager *accountManager;
@property (nonatomic) PinEntryView *entryView; @property (nonatomic) PinEntryView *entryView;
@end @end
@ -24,28 +23,11 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWS2FARegistrationViewController @implementation OWS2FARegistrationViewController
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder #pragma mark - Dependencies
{
self = [super initWithCoder:aDecoder];
if (!self) {
return self;
}
_accountManager = AppEnvironment.shared.accountManager;
return self;
}
- (instancetype)init - (AccountManager *)accountManager
{ {
self = [super init]; return AppEnvironment.shared.accountManager;
if (!self) {
return self;
}
_accountManager = AppEnvironment.shared.accountManager;
return self;
} }
#pragma mark - View Lifecycle #pragma mark - View Lifecycle
@ -125,7 +107,7 @@ NS_ASSUME_NONNULL_BEGIN
canCancel:NO canCancel:NO
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) { backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
OWSProdInfo([OWSAnalyticsEvents registrationRegisteringCode]); OWSProdInfo([OWSAnalyticsEvents registrationRegisteringCode]);
[self.accountManager registerWithVerificationCode:self.verificationCode pin:pinCode] [self.accountManager registerObjcWithVerificationCode:self.verificationCode pin:pinCode]
.then(^{ .then(^{
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
OWSProdInfo([OWSAnalyticsEvents registrationRegisteringSubmittedCode]); OWSProdInfo([OWSAnalyticsEvents registrationRegisteringSubmittedCode]);
@ -163,7 +145,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)verificationWasCompleted - (void)verificationWasCompleted
{ {
[ProfileViewController presentForRegistration:self.navigationController]; [RegistrationController verificationWasCompletedFromView:self];
} }
@end @end

@ -432,10 +432,6 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
break; break;
case ProfileViewMode_Registration: case ProfileViewMode_Registration:
if (![TSAccountManager sharedInstance].isReregistering) {
[self checkCanImportBackup];
return;
}
[self showHomeView]; [self showHomeView];
break; break;
case ProfileViewMode_UpgradeOrNag: case ProfileViewMode_UpgradeOrNag:
@ -452,68 +448,6 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
[SignalApp.sharedApp showHomeView]; [SignalApp.sharedApp showHomeView];
} }
- (void)showBackupRestoreView
{
OWSAssertIsOnMainThread();
OWSLogVerbose(@"");
BackupRestoreViewController *restoreView = [BackupRestoreViewController new];
[self.navigationController setViewControllers:@[
restoreView,
]
animated:YES];
}
- (void)checkCanImportBackup
{
OWSLogVerbose(@"");
__weak ProfileViewController *weakSelf = self;
[OWSBackup.sharedManager
checkCanImportBackup:^(BOOL value) {
OWSAssertIsOnMainThread();
OWSLogInfo(@"has backup available for import? %d", value);
if (value) {
[OWSBackup.sharedManager setHasPendingRestoreDecision:YES];
[weakSelf showBackupRestoreView];
} else {
[weakSelf showHomeView];
}
}
failure:^(NSError *error) {
[weakSelf showBackupCheckFailedAlert];
}];
}
- (void)showBackupCheckFailedAlert
{
OWSLogVerbose(@"");
__weak ProfileViewController *weakSelf = self;
UIAlertController *controller = [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_FAILED_TITLE",
@"Title for alert shown when the app failed to check for an existing backup.")
message:NSLocalizedString(@"CHECK_FOR_BACKUP_FAILED_MESSAGE",
@"Message for alert shown when the app failed to check for an existing "
@"backup.")
preferredStyle:UIAlertControllerStyleAlert];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"REGISTER_FAILED_TRY_AGAIN", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[weakSelf checkCanImportBackup];
}]];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_DO_NOT_RESTORE",
@"The label for the 'do not restore backup' button.")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
[weakSelf showHomeView];
}]];
[self presentViewController:controller animated:YES completion:nil];
}
#pragma mark - UITextFieldDelegate #pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField - (BOOL)textField:(UITextField *)textField

@ -9,10 +9,14 @@ public class BackupRestoreViewController: OWSTableViewController {
private var hasBegunImport = false private var hasBegunImport = false
// MARK: - Dependencies
private var backup: OWSBackup { private var backup: OWSBackup {
return AppEnvironment.shared.backup return AppEnvironment.shared.backup
} }
// MARK: -
override public func loadView() { override public func loadView() {
super.loadView() super.loadView()

@ -16,8 +16,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface CodeVerificationViewController () <UITextFieldDelegate> @interface CodeVerificationViewController () <UITextFieldDelegate>
@property (nonatomic, readonly) AccountManager *accountManager;
// Where the user enters the verification code they wish to document // Where the user enters the verification code they wish to document
@property (nonatomic) UITextField *challengeTextField; @property (nonatomic) UITextField *challengeTextField;
@ -47,30 +45,9 @@ NS_ASSUME_NONNULL_BEGIN
return SSKEnvironment.shared.tsAccountManager; return SSKEnvironment.shared.tsAccountManager;
} }
#pragma mark - - (AccountManager *)accountManager
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (!self) {
return self;
}
_accountManager = AppEnvironment.shared.accountManager;
return self;
}
- (instancetype)init
{ {
self = [super init]; return AppEnvironment.shared.accountManager;
if (!self) {
return self;
}
_accountManager = AppEnvironment.shared.accountManager;
return self;
} }
#pragma mark - View Lifecycle #pragma mark - View Lifecycle
@ -292,7 +269,7 @@ NS_ASSUME_NONNULL_BEGIN
[self startActivityIndicator]; [self startActivityIndicator];
OWSProdInfo([OWSAnalyticsEvents registrationRegisteringCode]); OWSProdInfo([OWSAnalyticsEvents registrationRegisteringCode]);
__weak CodeVerificationViewController *weakSelf = self; __weak CodeVerificationViewController *weakSelf = self;
[[self.accountManager registerWithVerificationCode:[self validationCodeFromTextField] pin:nil] [[self.accountManager registerObjcWithVerificationCode:[self validationCodeFromTextField] pin:nil]
.then(^{ .then(^{
OWSProdInfo([OWSAnalyticsEvents registrationRegisteringSubmittedCode]); OWSProdInfo([OWSAnalyticsEvents registrationRegisteringSubmittedCode]);
@ -329,7 +306,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)verificationWasCompleted - (void)verificationWasCompleted
{ {
[ProfileViewController presentForRegistration:self.navigationController]; [RegistrationController verificationWasCompletedFromView:self];
} }
- (void)presentAlertWithVerificationError:(NSError *)error - (void)presentAlertWithVerificationError:(NSError *)error

@ -0,0 +1,104 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import UIKit
@objc
public class RegistrationController: NSObject {
// MARK: - Dependencies
private static var tsAccountManager: TSAccountManager {
return TSAccountManager.sharedInstance()
}
private static var backup: OWSBackup {
return AppEnvironment.shared.backup
}
// MARK: -
private override init() {}
// MARK: -
@objc
public class func verificationWasCompleted(fromView view: UIViewController) {
AssertIsOnMainThread()
if tsAccountManager.isReregistering() {
showProfileView(fromView: view)
} else {
checkCanImportBackup(fromView: view)
}
}
private class func showProfileView(fromView view: UIViewController) {
AssertIsOnMainThread()
Logger.info("")
guard let navigationController = view.navigationController else {
owsFailDebug("Missing navigationController")
return
}
ProfileViewController.present(forRegistration: navigationController)
}
private class func showBackupRestoreView(fromView view: UIViewController) {
AssertIsOnMainThread()
Logger.info("")
guard let navigationController = view.navigationController else {
owsFailDebug("Missing navigationController")
return
}
let restoreView = BackupRestoreViewController()
navigationController.setViewControllers([restoreView], animated: true)
}
private class func checkCanImportBackup(fromView view: UIViewController) {
AssertIsOnMainThread()
Logger.info("")
self.backup.checkCanImport({ (canImport) in
Logger.info("canImport: \(canImport)")
if (canImport) {
self.backup.setHasPendingRestoreDecision(true)
self.showBackupRestoreView(fromView: view)
} else {
self.showProfileView(fromView: view)
}
}) { (_) in
self.showBackupCheckFailedAlert(fromView: view)
}
}
private class func showBackupCheckFailedAlert(fromView view: UIViewController) {
AssertIsOnMainThread()
Logger.info("")
let alert = UIAlertController(title: NSLocalizedString("CHECK_FOR_BACKUP_FAILED_TITLE",
comment: "Title for alert shown when the app failed to check for an existing backup."),
message: NSLocalizedString("CHECK_FOR_BACKUP_FAILED_MESSAGE",
comment: "Message for alert shown when the app failed to check for an existing backup."),
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("REGISTER_FAILED_TRY_AGAIN", comment: ""),
style: .default) { (_) in
self.checkCanImportBackup(fromView: view)
})
alert.addAction(UIAlertAction(title: NSLocalizedString("CHECK_FOR_BACKUP_DO_NOT_RESTORE", comment: "The label for the 'do not restore backup' button."),
style: .destructive) { (_) in
self.showProfileView(fromView: view)
})
view.present(alert, animated: true)
}
}
Loading…
Cancel
Save