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,9 +1147,22 @@ final class SharedApplicationContext {
if let authContextValue = self.authContextValue {
authContextValue.account.shouldBeServiceTaskMaster.set(.single(.never))
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 {
let presentationData = context.sharedContext.currentPresentationData.with({ $0 })

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 {
@ -720,7 +722,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail
private func updateState(state: InnerState) {
switch state {
case .authorized:
break
self.authorizationCompleted()
case let .state(state):
switch state {
case .empty: