IOS-1542 Fix SMTPSettingsTableViewController. IOS-1542
authorDirk Zimmermann <dz@pep.security>
Thu, 18 Apr 2019 16:20:54 +0200
branchIOS-1542
changeset 8326c2594c097ff1
parent 8325 1ce60fef0b69
child 8327 8a65e73fcc04
IOS-1542 Fix SMTPSettingsTableViewController.
pEpForiOS/UI/ManualLogin/SMTPSetup/SMTPSettingsTableViewController.swift
     1.1 --- a/pEpForiOS/UI/ManualLogin/SMTPSetup/SMTPSettingsTableViewController.swift	Thu Apr 18 16:20:54 2019 +0200
     1.2 +++ b/pEpForiOS/UI/ManualLogin/SMTPSetup/SMTPSettingsTableViewController.swift	Thu Apr 18 16:20:54 2019 +0200
     1.3 @@ -22,7 +22,6 @@
     1.4      @IBOutlet weak var portTitle: UILabel!
     1.5  
     1.6      var model: VerifiableAccountProtocol!
     1.7 -    private var currentlyVerifiedAccount: Account?
     1.8      var fields = [UITextField]()
     1.9      var responder = 0
    1.10  
    1.11 @@ -77,9 +76,8 @@
    1.12      /// - Throws: AccountVerificationError
    1.13      private func verifyAccount() throws {
    1.14          isCurrentlyVerifying =  true
    1.15 -        let account = try model.account()
    1.16 -        currentlyVerifiedAccount = account
    1.17 -        VerificationService().requestVerification(account: account, delegate: self)
    1.18 +        model.verifiableAccountDelegate = self
    1.19 +        try model.verify()
    1.20      }
    1.21  
    1.22      private func informUser(about error: Error, title: String) {
    1.23 @@ -153,43 +151,6 @@
    1.24      }
    1.25  }
    1.26  
    1.27 -// MARK: - AccountVerificationServiceDelegate
    1.28 -
    1.29 -extension SMTPSettingsTableViewController: AccountVerificationServiceDelegate {
    1.30 -    func verified(account: Account, service: AccountVerificationServiceProtocol,
    1.31 -                  result: AccountVerificationResult) {
    1.32 -        if result == .ok {
    1.33 -            MessageModelUtil.performAndWait { [weak self] in
    1.34 -                guard let me = self else {
    1.35 -                    Logger.frontendLogger.lostMySelf()
    1.36 -                    return
    1.37 -                }
    1.38 -                guard let account = me.currentlyVerifiedAccount else {
    1.39 -                    Logger.backendLogger.errorAndCrash(
    1.40 -                        "We verified an non-existing account? Now what?")
    1.41 -                    return
    1.42 -                }
    1.43 -                account.save()
    1.44 -            }
    1.45 -        }
    1.46 -        GCD.onMain() {
    1.47 -            self.isCurrentlyVerifying =  false
    1.48 -            switch result {
    1.49 -            case .ok:
    1.50 -                // unwind back to INBOX or folder list on success
    1.51 -                self.performSegue(withIdentifier: .backToEmailListSegue, sender: self)
    1.52 -            case .imapError(let err):
    1.53 -                UIUtils.show(error: err, inViewController: self)
    1.54 -            case .smtpError(let err):
    1.55 -                UIUtils.show(error: err, inViewController: self)
    1.56 -            case .noImapConnectData, .noSmtpConnectData:
    1.57 -                let error = LoginViewController.LoginError.noConnectData
    1.58 -                UIUtils.show(error: error, inViewController: self)
    1.59 -            }
    1.60 -        }
    1.61 -    }
    1.62 -}
    1.63 -
    1.64  // MARK: - SegueHandlerType
    1.65  
    1.66  extension SMTPSettingsTableViewController: SegueHandlerType {
    1.67 @@ -221,3 +182,26 @@
    1.68          changedResponder(textField)
    1.69      }
    1.70  }
    1.71 +
    1.72 +extension SMTPSettingsTableViewController: VerifiableAccountDelegate {
    1.73 +    func didEndVerification(result: Result<Void, Error>) {
    1.74 +        switch result {
    1.75 +        case .success(()):
    1.76 +                MessageModelUtil.performAndWait { [weak self] in
    1.77 +                    do {
    1.78 +                        try self?.model.save()
    1.79 +                    } catch {
    1.80 +                        Logger.frontendLogger.log(error: error)
    1.81 +                        Logger.frontendLogger.errorAndCrash("Unexpected error")
    1.82 +                    }
    1.83 +                }
    1.84 +                GCD.onMain() {
    1.85 +                    self.performSegue(withIdentifier: .backToEmailListSegue, sender: self)
    1.86 +            }
    1.87 +        case .failure(let error):
    1.88 +            GCD.onMain() {
    1.89 +                UIUtils.show(error: error, inViewController: self)
    1.90 +            }
    1.91 +        }
    1.92 +    }
    1.93 +}