mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Refactoring [skip ci]
This commit is contained in:
@@ -141,8 +141,7 @@ public enum SetupTwoStepVerificationStateUpdate {
|
||||
}
|
||||
|
||||
final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
private let sharedContext: SharedAccountContext
|
||||
private let network: Network
|
||||
private let context: AccountContext
|
||||
private var presentationData: PresentationData
|
||||
private let updateBackAction: (Bool) -> Void
|
||||
private let updateNextAction: (SetupTwoStepVerificationNextAction) -> Void
|
||||
@@ -155,15 +154,14 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
private var contentNode: SetupTwoStepVerificationContentNode?
|
||||
private let actionDisposable = MetaDisposable()
|
||||
|
||||
init(sharedContext: SharedAccountContext, network: Network, updateBackAction: @escaping (Bool) -> Void, updateNextAction: @escaping (SetupTwoStepVerificationNextAction) -> Void, stateUpdated: @escaping (SetupTwoStepVerificationStateUpdate, Bool) -> Void, present: @escaping (ViewController, Any?) -> Void, dismiss: @escaping () -> Void, initialState: SetupTwoStepVerificationInitialState) {
|
||||
self.sharedContext = sharedContext
|
||||
self.network = network
|
||||
init(context: AccountContext, updateBackAction: @escaping (Bool) -> Void, updateNextAction: @escaping (SetupTwoStepVerificationNextAction) -> Void, stateUpdated: @escaping (SetupTwoStepVerificationStateUpdate, Bool) -> Void, present: @escaping (ViewController, Any?) -> Void, dismiss: @escaping () -> Void, initialState: SetupTwoStepVerificationInitialState) {
|
||||
self.context = context
|
||||
self.updateBackAction = updateBackAction
|
||||
self.updateNextAction = updateNextAction
|
||||
self.stateUpdated = stateUpdated
|
||||
self.present = present
|
||||
self.dismiss = dismiss
|
||||
self.presentationData = self.sharedContext.currentPresentationData.with { $0 }
|
||||
self.presentationData = self.context.sharedContext.currentPresentationData.with { $0 }
|
||||
self.innerState = SetupTwoStepVerificationControllerInnerState(layout: nil, data: SetupTwoStepVerificationControllerDataState(activity: false, state: SetupTwoStepVerificationState(initialState: initialState)))
|
||||
self.activityIndicator = ActivityIndicator(type: .custom(self.presentationData.theme.list.itemAccentColor, 22.0, 2.0, false))
|
||||
|
||||
@@ -173,7 +171,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
self.processStateUpdated()
|
||||
|
||||
if self.innerState.data.state == nil {
|
||||
self.actionDisposable.set((twoStepAuthData(self.network)
|
||||
self.actionDisposable.set((self.context.engine.auth.twoStepAuthData()
|
||||
|> deliverOnMainQueue).start(next: { [weak self] data in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
@@ -342,7 +340,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
state.data.activity = true
|
||||
return state
|
||||
}, transition: .animated(duration: 0.5, curve: .spring))
|
||||
strongSelf.actionDisposable.set((updateTwoStepVerificationPassword(network: strongSelf.network, currentPassword: nil, updatedPassword: .none)
|
||||
strongSelf.actionDisposable.set((strongSelf.context.engine.auth.updateTwoStepVerificationPassword(currentPassword: nil, updatedPassword: .none)
|
||||
|> deliverOnMainQueue).start(next: { _ in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
@@ -358,7 +356,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: strongSelf.presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.context.sharedContext, title: nil, text: strongSelf.presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.updateState({ state in
|
||||
var state = state
|
||||
state.data.activity = false
|
||||
@@ -395,7 +393,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
state.data.activity = true
|
||||
return state
|
||||
}, transition: .animated(duration: 0.5, curve: .spring))
|
||||
strongSelf.actionDisposable.set((resendTwoStepRecoveryEmail(network: strongSelf.network)
|
||||
strongSelf.actionDisposable.set((strongSelf.context.engine.auth.resendTwoStepRecoveryEmail()
|
||||
|> deliverOnMainQueue).start(error: { error in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
@@ -407,7 +405,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
case .generic:
|
||||
text = strongSelf.presentationData.strings.Login_UnknownError
|
||||
}
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.context.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.updateState({ state in
|
||||
var state = state
|
||||
state.data.activity = false
|
||||
@@ -528,7 +526,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
if password == confirmation {
|
||||
state.data.state = .enterHint(mode: mode, password: password, hint: "")
|
||||
} else {
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: strongSelf.presentationData.strings.TwoStepAuth_SetupPasswordConfirmFailed, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.context.sharedContext, title: nil, text: strongSelf.presentationData.strings.TwoStepAuth_SetupPasswordConfirmFailed, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
}
|
||||
case let .enterHint(mode, password, hint):
|
||||
switch mode {
|
||||
@@ -536,7 +534,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
state.data.state = .enterEmail(state: .create(password: password, hint: hint), email: "")
|
||||
case let .update(current, hasRecoveryEmail, hasSecureValues):
|
||||
state.data.activity = true
|
||||
strongSelf.actionDisposable.set((updateTwoStepVerificationPassword(network: strongSelf.network, currentPassword: current, updatedPassword: .password(password: password, hint: hint, email: nil))
|
||||
strongSelf.actionDisposable.set((strongSelf.context.engine.auth.updateTwoStepVerificationPassword(currentPassword: current, updatedPassword: .password(password: password, hint: hint, email: nil))
|
||||
|> deliverOnMainQueue).start(next: { result in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
@@ -560,7 +558,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: strongSelf.presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.context.sharedContext, title: nil, text: strongSelf.presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.updateState({ state in
|
||||
var state = state
|
||||
state.data.activity = false
|
||||
@@ -572,7 +570,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
state.data.activity = true
|
||||
switch enterState {
|
||||
case let .create(password, hint):
|
||||
strongSelf.actionDisposable.set((updateTwoStepVerificationPassword(network: strongSelf.network, currentPassword: nil, updatedPassword: .password(password: password, hint: hint, email: email))
|
||||
strongSelf.actionDisposable.set((strongSelf.context.engine.auth.updateTwoStepVerificationPassword(currentPassword: nil, updatedPassword: .password(password: password, hint: hint, email: email))
|
||||
|> deliverOnMainQueue).start(next: { result in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
@@ -604,7 +602,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
case .generic:
|
||||
text = strongSelf.presentationData.strings.Login_UnknownError
|
||||
}
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.context.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.updateState({ state in
|
||||
var state = state
|
||||
state.data.activity = false
|
||||
@@ -620,7 +618,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
state.data.activity = true
|
||||
return state
|
||||
}, transition: .animated(duration: 0.5, curve: .spring))
|
||||
strongSelf.actionDisposable.set((updateTwoStepVerificationEmail(network: strongSelf.network, currentPassword: password, updatedEmail: email)
|
||||
strongSelf.actionDisposable.set((strongSelf.context.engine.auth.updateTwoStepVerificationEmail(currentPassword: password, updatedEmail: email)
|
||||
|> deliverOnMainQueue).start(next: { result in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
@@ -646,7 +644,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: strongSelf.presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.context.sharedContext, title: nil, text: strongSelf.presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.updateState({ state in
|
||||
var state = state
|
||||
state.data.activity = false
|
||||
@@ -656,7 +654,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
}
|
||||
case let .confirmEmail(confirmState, _, _, code):
|
||||
state.data.activity = true
|
||||
strongSelf.actionDisposable.set((confirmTwoStepRecoveryEmail(network: strongSelf.network, code: code)
|
||||
strongSelf.actionDisposable.set((strongSelf.context.engine.auth.confirmTwoStepRecoveryEmail(code: code)
|
||||
|> deliverOnMainQueue).start(error: { error in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
@@ -675,7 +673,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
case .generic:
|
||||
text = strongSelf.presentationData.strings.Login_UnknownError
|
||||
}
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
strongSelf.present(textAlertController(sharedContext: strongSelf.context.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
|
||||
|
||||
strongSelf.updateState({ state in
|
||||
var state = state
|
||||
@@ -700,7 +698,7 @@ final class SetupTwoStepVerificationControllerNode: ViewControllerTracingNode {
|
||||
}, transition: .animated(duration: 0.5, curve: .spring))
|
||||
}
|
||||
if case let .enterEmail(enterEmailState, enterEmailEmail)? = self.innerState.data.state, case .create = enterEmailState, enterEmailEmail.isEmpty {
|
||||
self.present(textAlertController(sharedContext: self.sharedContext, title: nil, text: self.presentationData.strings.TwoStepAuth_EmailSkipAlert, actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .destructiveAction, title: self.presentationData.strings.TwoStepAuth_EmailSkip, action: {
|
||||
self.present(textAlertController(sharedContext: self.context.sharedContext, title: nil, text: self.presentationData.strings.TwoStepAuth_EmailSkipAlert, actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .destructiveAction, title: self.presentationData.strings.TwoStepAuth_EmailSkip, action: {
|
||||
continueImpl()
|
||||
})]), nil)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user