소스 검색

fix creating accounts by scanning, entering credentials or importing backups in the context of multi-account

cyberta 4 년 전
부모
커밋
0a6fa4fc48

+ 2 - 0
deltachat-ios/Controller/AccountSetupController.swift

@@ -677,8 +677,10 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
             notification in
             if let ui = notification.userInfo {
                 if ui["error"] as! Bool {
+                    self.dcAccounts.maybeStartIo()
                     self.updateProgressAlert(error: ui["errorMessage"] as? String)
                 } else if ui["done"] as! Bool {
+                    self.dcAccounts.maybeStartIo()
                     self.updateProgressAlertSuccess(completion: self.handleLoginSuccess)
                 } else {
                     self.updateProgressAlertValue(value: ui["progress"] as? Int)

+ 6 - 1
deltachat-ios/Controller/SettingsController.swift

@@ -259,7 +259,12 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         super.viewDidAppear(animated)
         addProgressAlertListener(dcAccounts: dcAccounts, progressName: dcNotificationImexProgress) { [weak self] in
             guard let self = self else { return }
-            self.progressAlert?.dismiss(animated: true, completion: nil)
+
+            self.progressAlert?.dismiss(animated: true) {
+                if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
+                    appDelegate.reloadDcContext()
+                }
+            }
         }
         connectivityChangedObserver = NotificationCenter.default.addObserver(forName: dcNotificationConnectivityChanged,
                                                                              object: nil,

+ 16 - 14
deltachat-ios/Controller/WelcomeViewController.swift

@@ -21,8 +21,7 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
             accountSetupController.onLoginSuccess = {
                 [weak self] in
                 if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
-                    appDelegate.appCoordinator.presentTabBarController()
-                    appDelegate.appCoordinator.popTabsToRootViewControllers()
+                    appDelegate.reloadDcContext()
                 }
             }
             self.navigationController?.pushViewController(accountSetupController, animated: true)
@@ -60,7 +59,7 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
             let profileInfoController = ProfileInfoViewController(context: self.dcContext)
             profileInfoController.onClose = {
                 if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
-                    appDelegate.appCoordinator.presentTabBarController()
+                    appDelegate.reloadDcContext()
                 }
             }
             self.navigationController?.setViewControllers([profileInfoController], animated: true)
@@ -126,18 +125,21 @@ class WelcomeViewController: UIViewController, ProgressAlertHandler {
     // MARK: - actions
 
     private func createAccountFromQRCode(qrCode: String) {
-        let success = dcContext.setConfigFromQR(qrCode: qrCode)
-        if success {
-            addProgressAlertListener(dcAccounts: dcAccounts, progressName: dcNotificationConfigureProgress, onSuccess: handleLoginSuccess)
-            showProgressAlert(title: String.localized("login_header"), dcContext: dcContext)
-            dcAccounts.stopIo()
-            let accountId = dcAccounts.add()
-            if accountId != 0 {
-                self.dcContext = dcAccounts.get(id: accountId)
+        // ensure we're configuring on an empty new account
+        let accountId = dcAccounts.getSelected().isConfigured() ?
+            dcAccounts.add() : dcAccounts.getSelected().id
+
+        if accountId != 0 {
+            self.dcContext = dcAccounts.get(id: accountId)
+            let success = dcContext.setConfigFromQR(qrCode: qrCode)
+            if success {
+                addProgressAlertListener(dcAccounts: dcAccounts, progressName: dcNotificationConfigureProgress, onSuccess: handleLoginSuccess)
+                showProgressAlert(title: String.localized("login_header"), dcContext: dcContext)
+                dcAccounts.stopIo()
+                dcContext.configure()
+            } else {
+                accountCreationErrorAlert()
             }
-            dcContext.configure()
-        } else {
-            accountCreationErrorAlert()
         }
     }