From f4857a6a86909e3960b5e6a8ce2cd3f3d6fa6e5f Mon Sep 17 00:00:00 2001 From: cpilaszewicz <khutbvdw> Date: Tue, 10 Mar 2020 13:18:37 +0100 Subject: [PATCH] Create an enum for authentication results --- enzevalos_iphone/AuthenticationModel.swift | 13 ++++++++++--- enzevalos_iphone/AuthenticationViewModel.swift | 13 ++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/enzevalos_iphone/AuthenticationModel.swift b/enzevalos_iphone/AuthenticationModel.swift index 6be2e8a2..d9ee43db 100644 --- a/enzevalos_iphone/AuthenticationModel.swift +++ b/enzevalos_iphone/AuthenticationModel.swift @@ -11,7 +11,7 @@ import Combine class AuthenticationModel: NSObject { - enum AuthenticationResult {case Success, Timeout, Error} + enum AuthenticationResult {case Success, Timeout, Error(value: MailServerConnectionError)} static let instance: AuthenticationModel = AuthenticationModel() @@ -50,7 +50,6 @@ class AuthenticationModel: NSObject { let result = self.dispatchGroup.wait(timeout: DispatchTime.now() + timeoutDelay) DispatchQueue.main.async { promise(.success(self.onTimeout(timeoutResult: result))) - print("promise sent") } } } @@ -120,7 +119,15 @@ class AuthenticationModel: NSObject { if imapConfigurationSuccessful && smtpConfigurationSuccessful { return AuthenticationResult.Success } else { - return AuthenticationResult.Error + var error = MailServerConnectionError.AuthenticationError + if let smtp = currentIMAP, let e = MailServerConnectionError.findPrioError(errors: smtp.errors) { + error = e + } + if let imap = currentIMAP, let e = MailServerConnectionError.findPrioError(errors: imap.errors) { + error = e + } + + return AuthenticationResult.Error(value: error) } } else { return AuthenticationResult.Timeout diff --git a/enzevalos_iphone/AuthenticationViewModel.swift b/enzevalos_iphone/AuthenticationViewModel.swift index bd8a7551..d9ec6d7c 100644 --- a/enzevalos_iphone/AuthenticationViewModel.swift +++ b/enzevalos_iphone/AuthenticationViewModel.swift @@ -31,7 +31,7 @@ class AuthenticationViewModel : ObservableObject { case AuthenticationModel.AuthenticationResult.Error : self.authenticationFailed(error: MailServerConnectionError.AuthenticationError) case AuthenticationModel.AuthenticationResult.Timeout : - self.timeoutNotification(result: promise) + self.timeoutNotification() } } } @@ -43,10 +43,10 @@ class AuthenticationViewModel : ObservableObject { switch promise { case AuthenticationModel.AuthenticationResult.Success : self.authenticationSucceed() - case AuthenticationModel.AuthenticationResult.Error : - self.authenticationFailed(error: MailServerConnectionError.AuthenticationError) + case AuthenticationModel.AuthenticationResult.Error(let value) : + self.authenticationFailed(error: value) case AuthenticationModel.AuthenticationResult.Timeout : - self.timeoutNotification(result: promise) + self.timeoutNotification() } } } @@ -72,7 +72,7 @@ class AuthenticationViewModel : ObservableObject { case AuthenticationModel.AuthenticationResult.Error : self.authenticationFailed(error: MailServerConnectionError.AuthenticationError) case AuthenticationModel.AuthenticationResult.Timeout : - self.timeoutNotification(result: promise) + self.timeoutNotification() } } }) @@ -86,8 +86,7 @@ class AuthenticationViewModel : ObservableObject { errorMessage = NSLocalizedString(error.localizedUIBodyString, comment: "") } - func timeoutNotification(result: AuthenticationModel.AuthenticationResult) { - print("promise arrived") + func timeoutNotification() { errorMessage = NSLocalizedString(MailServerConnectionError.TimeoutError.localizedUIBodyString, comment: "") } } -- GitLab