mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
105 lines
3.4 KiB
Swift
105 lines
3.4 KiB
Swift
//
|
|
// 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)
|
|
}
|
|
}
|