Wait until authorized context is there

This commit is contained in:
Ali 2019-11-05 22:20:55 +04:00
parent 791569951f
commit 4bf57d60fd
3 changed files with 87 additions and 61 deletions

View File

@ -1147,8 +1147,21 @@ final class SharedApplicationContext {
if let authContextValue = self.authContextValue {
authContextValue.account.shouldBeServiceTaskMaster.set(.single(.never))
authContextValue.rootController.view.endEditing(true)
authContextValue.rootController.dismiss()
if authContextValue.authorizationCompleted {
let accountId = authContextValue.account.id
let _ = (self.context.get()
|> filter { context in
return context?.context.account.id == accountId
}
|> take(1)
|> timeout(4.0, queue: .mainQueue(), alternate: .complete())
|> deliverOnMainQueue).start(completed: { authContextValue.rootController.view.endEditing(true)
authContextValue.rootController.dismiss()
})
} else {
authContextValue.rootController.view.endEditing(true)
authContextValue.rootController.dismiss()
}
}
self.authContextValue = context
if let context = context {

View File

@ -31,12 +31,23 @@ final class UnauthorizedApplicationContext {
let isReady = Promise<Bool>()
var authorizationCompleted: Bool = false
init(apiId: Int32, apiHash: String, sharedContext: SharedAccountContextImpl, account: UnauthorizedAccount, otherAccountPhoneNumbers: ((String, AccountRecordId, Bool)?, [(String, AccountRecordId, Bool)])) {
self.sharedContext = sharedContext
self.account = account
let presentationData = sharedContext.currentPresentationData.with { $0 }
self.rootController = AuthorizationSequenceController(sharedContext: sharedContext, account: account, otherAccountPhoneNumbers: otherAccountPhoneNumbers, strings: presentationData.strings, theme: presentationData.theme, openUrl: sharedContext.applicationBindings.openUrl, apiId: apiId, apiHash: apiHash)
var authorizationCompleted: (() -> Void)?
self.rootController = AuthorizationSequenceController(sharedContext: sharedContext, account: account, otherAccountPhoneNumbers: otherAccountPhoneNumbers, strings: presentationData.strings, theme: presentationData.theme, openUrl: sharedContext.applicationBindings.openUrl, apiId: apiId, apiHash: apiHash, authorizationCompleted: {
authorizationCompleted?()
})
authorizationCompleted = { [weak self] in
self?.authorizationCompleted = true
}
self.isReady.set(self.rootController.ready.get())
account.shouldBeServiceTaskMaster.set(sharedContext.applicationBindings.applicationInForeground |> map { value -> AccountServiceTaskMasterMode in

View File

@ -38,6 +38,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
private var strings: PresentationStrings
public let theme: PresentationTheme
private let openUrl: (String) -> Void
private let authorizationCompleted: () -> Void
private var stateDisposable: Disposable?
private let actionDisposable = MetaDisposable()
@ -50,7 +51,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
}
private var didSetReady = false
public init(sharedContext: SharedAccountContext, account: UnauthorizedAccount, otherAccountPhoneNumbers: ((String, AccountRecordId, Bool)?, [(String, AccountRecordId, Bool)]), strings: PresentationStrings, theme: PresentationTheme, openUrl: @escaping (String) -> Void, apiId: Int32, apiHash: String) {
public init(sharedContext: SharedAccountContext, account: UnauthorizedAccount, otherAccountPhoneNumbers: ((String, AccountRecordId, Bool)?, [(String, AccountRecordId, Bool)]), strings: PresentationStrings, theme: PresentationTheme, openUrl: @escaping (String) -> Void, apiId: Int32, apiHash: String, authorizationCompleted: @escaping () -> Void) {
self.sharedContext = sharedContext
self.account = account
self.otherAccountPhoneNumbers = otherAccountPhoneNumbers
@ -59,6 +60,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
self.strings = strings
self.theme = theme
self.openUrl = openUrl
self.authorizationCompleted = authorizationCompleted
let navigationStatusBar: NavigationStatusBarStyle
switch theme.rootController.statusBarStyle {
@ -719,68 +721,68 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
private func updateState(state: InnerState) {
switch state {
case .authorized:
break
case let .state(state):
switch state {
case .empty:
if let _ = self.viewControllers.last as? AuthorizationSequenceSplashController {
} else {
var controllers: [ViewController] = []
if self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
} else {
controllers.append(self.phoneEntryController(countryCode: defaultCountryCode(), number: ""))
}
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
}
case let .phoneEntry(countryCode, number):
case .authorized:
self.authorizationCompleted()
case let .state(state):
switch state {
case .empty:
if let _ = self.viewControllers.last as? AuthorizationSequenceSplashController {
} else {
var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.phoneEntryController(countryCode: countryCode, number: number))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .confirmationCodeEntry(number, type, _, timeout, nextType, _):
var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.phoneEntryController(countryCode: defaultCountryCode(), number: ""))
controllers.append(self.codeEntryController(number: number, type: type, nextType: nextType, timeout: timeout, termsOfService: nil))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .passwordEntry(hint, _, _, suggestReset, syncContacts):
var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.passwordEntryController(hint: hint, suggestReset: suggestReset, syncContacts: syncContacts))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .passwordRecovery(_, _, _, emailPattern, syncContacts):
var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.passwordRecoveryController(emailPattern: emailPattern, syncContacts: syncContacts))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .awaitingAccountReset(protectedUntil, number, _):
var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.awaitingAccountResetController(protectedUntil: protectedUntil, number: number))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .signUp(_, _, firstName, lastName, termsOfService, _):
var controllers: [ViewController] = []
var displayCancel = false
if !self.otherAccountPhoneNumbers.1.isEmpty {
if self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
} else {
displayCancel = true
controllers.append(self.phoneEntryController(countryCode: defaultCountryCode(), number: ""))
}
controllers.append(self.signUpController(firstName: firstName, lastName: lastName, termsOfService: termsOfService, displayCancel: displayCancel))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
}
}
case let .phoneEntry(countryCode, number):
var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.phoneEntryController(countryCode: countryCode, number: number))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .confirmationCodeEntry(number, type, _, timeout, nextType, _):
var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.phoneEntryController(countryCode: defaultCountryCode(), number: ""))
controllers.append(self.codeEntryController(number: number, type: type, nextType: nextType, timeout: timeout, termsOfService: nil))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .passwordEntry(hint, _, _, suggestReset, syncContacts):
var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.passwordEntryController(hint: hint, suggestReset: suggestReset, syncContacts: syncContacts))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .passwordRecovery(_, _, _, emailPattern, syncContacts):
var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.passwordRecoveryController(emailPattern: emailPattern, syncContacts: syncContacts))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .awaitingAccountReset(protectedUntil, number, _):
var controllers: [ViewController] = []
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
}
controllers.append(self.awaitingAccountResetController(protectedUntil: protectedUntil, number: number))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
case let .signUp(_, _, firstName, lastName, termsOfService, _):
var controllers: [ViewController] = []
var displayCancel = false
if !self.otherAccountPhoneNumbers.1.isEmpty {
controllers.append(self.splashController())
} else {
displayCancel = true
}
controllers.append(self.signUpController(firstName: firstName, lastName: lastName, termsOfService: termsOfService, displayCancel: displayCancel))
self.setViewControllers(controllers, animated: !self.viewControllers.isEmpty)
}
}
}