mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Refactoring [skip ci]
This commit is contained in:
parent
4893e41de2
commit
ad5d4f5c75
@ -230,7 +230,7 @@ func changePhoneNumberCodeController(context: AccountContext, phoneNumber: Strin
|
||||
|> take(1)
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> in
|
||||
return Signal { subscriber in
|
||||
return requestNextChangeAccountPhoneNumberVerification(account: context.account, phoneNumber: phoneNumber, phoneCodeHash: data.hash).start(next: { next in
|
||||
return context.engine.accountData.requestNextChangeAccountPhoneNumberVerification(phoneNumber: phoneNumber, phoneCodeHash: data.hash).start(next: { next in
|
||||
currentDataPromise?.set(.single(next))
|
||||
}, error: { error in
|
||||
|
||||
@ -254,7 +254,7 @@ func changePhoneNumberCodeController(context: AccountContext, phoneNumber: Strin
|
||||
}
|
||||
}
|
||||
if let code = code {
|
||||
changePhoneDisposable.set((requestChangeAccountPhoneNumber(account: context.account, phoneNumber: phoneNumber, phoneCodeHash: codeData.hash, phoneCode: code) |> deliverOnMainQueue).start(error: { error in
|
||||
changePhoneDisposable.set((context.engine.accountData.requestChangeAccountPhoneNumber(phoneNumber: phoneNumber, phoneCodeHash: codeData.hash, phoneCode: code) |> deliverOnMainQueue).start(error: { error in
|
||||
updateState {
|
||||
return $0.withUpdatedChecking(false)
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ final class ChangePhoneNumberController: ViewController, MFMailComposeViewContro
|
||||
}
|
||||
if !number.isEmpty {
|
||||
self.inProgress = true
|
||||
self.requestDisposable.set((requestChangeAccountPhoneNumberVerification(account: self.context.account, phoneNumber: self.controllerNode.currentNumber) |> deliverOnMainQueue).start(next: { [weak self] next in
|
||||
self.requestDisposable.set((self.context.engine.accountData.requestChangeAccountPhoneNumberVerification(phoneNumber: self.controllerNode.currentNumber) |> deliverOnMainQueue).start(next: { [weak self] next in
|
||||
if let strongSelf = self {
|
||||
strongSelf.inProgress = false
|
||||
(strongSelf.navigationController as? NavigationController)?.pushViewController(changePhoneNumberCodeController(context: strongSelf.context, phoneNumber: strongSelf.controllerNode.currentNumber, codeData: next))
|
||||
|
@ -216,7 +216,7 @@ public func confirmPhoneNumberCodeController(context: AccountContext, phoneNumbe
|
||||
|> take(1)
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> in
|
||||
return Signal { subscriber in
|
||||
return requestNextCancelAccountResetOption(network: context.account.network, phoneNumber: phoneNumber, phoneCodeHash: data.hash).start(next: { next in
|
||||
return context.engine.auth.requestNextCancelAccountResetOption(phoneNumber: phoneNumber, phoneCodeHash: data.hash).start(next: { next in
|
||||
currentDataPromise?.set(.single(next))
|
||||
}, error: { error in
|
||||
|
||||
@ -242,7 +242,7 @@ public func confirmPhoneNumberCodeController(context: AccountContext, phoneNumbe
|
||||
}
|
||||
}
|
||||
if let code = code {
|
||||
confirmPhoneDisposable.set((requestCancelAccountReset(network: context.account.network, phoneCodeHash: codeData.hash, phoneCode: code)
|
||||
confirmPhoneDisposable.set((context.engine.auth.requestCancelAccountReset(phoneCodeHash: codeData.hash, phoneCode: code)
|
||||
|> deliverOnMainQueue).start(error: { error in
|
||||
updateState { state in
|
||||
var state = state
|
||||
|
@ -1545,7 +1545,7 @@ public final class VoiceChatController: ViewController {
|
||||
let controller = voiceChatTitleEditController(sharedContext: strongSelf.context.sharedContext, account: strongSelf.context.account, forceTheme: strongSelf.darkTheme, title: presentationData.strings.VoiceChat_EditBioTitle, text: presentationData.strings.VoiceChat_EditBioText, placeholder: presentationData.strings.VoiceChat_EditBioPlaceholder, doneButtonTitle: presentationData.strings.VoiceChat_EditBioSave, value: entry.about, maxLength: maxBioLength, apply: { bio in
|
||||
if let strongSelf = self, let bio = bio {
|
||||
if peer.id.namespace == Namespaces.Peer.CloudUser {
|
||||
let _ = (updateAbout(account: strongSelf.context.account, about: bio)
|
||||
let _ = (strongSelf.context.engine.accountData.updateAbout(about: bio)
|
||||
|> `catch` { _ -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}).start()
|
||||
@ -1575,7 +1575,7 @@ public final class VoiceChatController: ViewController {
|
||||
Queue.mainQueue().after(0.1) {
|
||||
let controller = voiceChatUserNameController(sharedContext: strongSelf.context.sharedContext, account: strongSelf.context.account, forceTheme: strongSelf.darkTheme, title: presentationData.strings.VoiceChat_ChangeNameTitle, firstNamePlaceholder: presentationData.strings.UserInfo_FirstNamePlaceholder, lastNamePlaceholder: presentationData.strings.UserInfo_LastNamePlaceholder, doneButtonTitle: presentationData.strings.VoiceChat_EditBioSave, firstName: peer.firstName, lastName: peer.lastName, maxLength: 128, apply: { firstAndLastName in
|
||||
if let strongSelf = self, let (firstName, lastName) = firstAndLastName {
|
||||
let _ = updateAccountPeerName(account: context.account, firstName: firstName, lastName: lastName).start()
|
||||
let _ = context.engine.accountData.updateAccountPeerName(firstName: firstName, lastName: lastName).start()
|
||||
|
||||
strongSelf.presentUndoOverlay(content: .info(text: strongSelf.presentationData.strings.VoiceChat_EditNameSuccess), action: { _ in return false })
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public enum RequestChangeAccountPhoneNumberVerificationError {
|
||||
case generic
|
||||
}
|
||||
|
||||
public func requestChangeAccountPhoneNumberVerification(account: Account, phoneNumber: String) -> Signal<ChangeAccountPhoneNumberData, RequestChangeAccountPhoneNumberVerificationError> {
|
||||
func _internal_requestChangeAccountPhoneNumberVerification(account: Account, phoneNumber: String) -> Signal<ChangeAccountPhoneNumberData, RequestChangeAccountPhoneNumberVerificationError> {
|
||||
return account.network.request(Api.functions.account.sendChangePhoneCode(phoneNumber: phoneNumber, settings: .codeSettings(flags: 0)), automaticFloodWait: false)
|
||||
|> mapError { error -> RequestChangeAccountPhoneNumberVerificationError in
|
||||
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
|
||||
@ -64,7 +64,7 @@ public func requestChangeAccountPhoneNumberVerification(account: Account, phoneN
|
||||
}
|
||||
}
|
||||
|
||||
public func requestNextChangeAccountPhoneNumberVerification(account: Account, phoneNumber: String, phoneCodeHash: String) -> Signal<ChangeAccountPhoneNumberData, RequestChangeAccountPhoneNumberVerificationError> {
|
||||
func _internal_requestNextChangeAccountPhoneNumberVerification(account: Account, phoneNumber: String, phoneCodeHash: String) -> Signal<ChangeAccountPhoneNumberData, RequestChangeAccountPhoneNumberVerificationError> {
|
||||
return account.network.request(Api.functions.auth.resendCode(phoneNumber: phoneNumber, phoneCodeHash: phoneCodeHash), automaticFloodWait: false)
|
||||
|> mapError { error -> RequestChangeAccountPhoneNumberVerificationError in
|
||||
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
|
||||
@ -96,7 +96,7 @@ public enum ChangeAccountPhoneNumberError {
|
||||
case limitExceeded
|
||||
}
|
||||
|
||||
public func requestChangeAccountPhoneNumber(account: Account, phoneNumber: String, phoneCodeHash: String, phoneCode: String) -> Signal<Void, ChangeAccountPhoneNumberError> {
|
||||
func _internal_requestChangeAccountPhoneNumber(account: Account, phoneNumber: String, phoneCodeHash: String, phoneCode: String) -> Signal<Void, ChangeAccountPhoneNumberError> {
|
||||
return account.network.request(Api.functions.account.changePhone(phoneNumber: phoneNumber, phoneCodeHash: phoneCodeHash, phoneCode: phoneCode), automaticFloodWait: false)
|
||||
|> mapError { error -> ChangeAccountPhoneNumberError in
|
||||
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
|
@ -15,5 +15,25 @@ public extension TelegramEngine {
|
||||
public func resetAccountDueTermsOfService() -> Signal<Void, NoError> {
|
||||
return _internal_resetAccountDueTermsOfService(network: self.account.network)
|
||||
}
|
||||
|
||||
public func requestChangeAccountPhoneNumberVerification(phoneNumber: String) -> Signal<ChangeAccountPhoneNumberData, RequestChangeAccountPhoneNumberVerificationError> {
|
||||
return _internal_requestChangeAccountPhoneNumberVerification(account: self.account, phoneNumber: phoneNumber)
|
||||
}
|
||||
|
||||
public func requestNextChangeAccountPhoneNumberVerification(phoneNumber: String, phoneCodeHash: String) -> Signal<ChangeAccountPhoneNumberData, RequestChangeAccountPhoneNumberVerificationError> {
|
||||
return _internal_requestNextChangeAccountPhoneNumberVerification(account: self.account, phoneNumber: phoneNumber, phoneCodeHash: phoneCodeHash)
|
||||
}
|
||||
|
||||
public func requestChangeAccountPhoneNumber(phoneNumber: String, phoneCodeHash: String, phoneCode: String) -> Signal<Void, ChangeAccountPhoneNumberError> {
|
||||
return _internal_requestChangeAccountPhoneNumber(account: self.account, phoneNumber: phoneNumber, phoneCodeHash: phoneCodeHash, phoneCode: phoneCode)
|
||||
}
|
||||
|
||||
public func updateAccountPeerName(firstName: String, lastName: String) -> Signal<Void, NoError> {
|
||||
return _internal_updateAccountPeerName(account: self.account, firstName: firstName, lastName: lastName)
|
||||
}
|
||||
|
||||
public func updateAbout(about: String?) -> Signal<Void, UpdateAboutError> {
|
||||
return _internal_updateAbout(account: self.account, about: about)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import MtProtoKit
|
||||
|
||||
import SyncCore
|
||||
|
||||
public func updateAccountPeerName(account: Account, firstName: String, lastName: String) -> Signal<Void, NoError> {
|
||||
func _internal_updateAccountPeerName(account: Account, firstName: String, lastName: String) -> Signal<Void, NoError> {
|
||||
return account.network.request(Api.functions.account.updateProfile(flags: (1 << 0) | (1 << 1), firstName: firstName, lastName: lastName, about: nil))
|
||||
|> map { result -> Api.User? in
|
||||
return result
|
||||
@ -30,7 +30,7 @@ public enum UpdateAboutError {
|
||||
}
|
||||
|
||||
|
||||
public func updateAbout(account: Account, about: String?) -> Signal<Void, UpdateAboutError> {
|
||||
func _internal_updateAbout(account: Account, about: String?) -> Signal<Void, UpdateAboutError> {
|
||||
return account.network.request(Api.functions.account.updateProfile(flags: about == nil ? 0 : (1 << 2), firstName: nil, lastName: nil, about: about))
|
||||
|> mapError { _ -> UpdateAboutError in
|
||||
return .generic
|
@ -18,7 +18,7 @@ public enum RequestCancelAccountResetDataError {
|
||||
case generic
|
||||
}
|
||||
|
||||
public func requestCancelAccountResetData(network: Network, hash: String) -> Signal<CancelAccountResetData, RequestCancelAccountResetDataError> {
|
||||
func _internal_requestCancelAccountResetData(network: Network, hash: String) -> Signal<CancelAccountResetData, RequestCancelAccountResetDataError> {
|
||||
return network.request(Api.functions.account.sendConfirmPhoneCode(hash: hash, settings: .codeSettings(flags: 0)), automaticFloodWait: false)
|
||||
|> mapError { error -> RequestCancelAccountResetDataError in
|
||||
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
|
||||
@ -39,7 +39,7 @@ public func requestCancelAccountResetData(network: Network, hash: String) -> Sig
|
||||
}
|
||||
}
|
||||
|
||||
public func requestNextCancelAccountResetOption(network: Network, phoneNumber: String, phoneCodeHash: String) -> Signal<CancelAccountResetData, RequestCancelAccountResetDataError> {
|
||||
func _internal_requestNextCancelAccountResetOption(network: Network, phoneNumber: String, phoneCodeHash: String) -> Signal<CancelAccountResetData, RequestCancelAccountResetDataError> {
|
||||
return network.request(Api.functions.auth.resendCode(phoneNumber: phoneNumber, phoneCodeHash: phoneCodeHash), automaticFloodWait: false)
|
||||
|> mapError { error -> RequestCancelAccountResetDataError in
|
||||
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
|
||||
@ -67,7 +67,7 @@ public enum CancelAccountResetError {
|
||||
case limitExceeded
|
||||
}
|
||||
|
||||
public func requestCancelAccountReset(network: Network, phoneCodeHash: String, phoneCode: String) -> Signal<Never, CancelAccountResetError> {
|
||||
func _internal_requestCancelAccountReset(network: Network, phoneCodeHash: String, phoneCode: String) -> Signal<Never, CancelAccountResetError> {
|
||||
return network.request(Api.functions.account.confirmPhone(phoneCodeHash: phoneCodeHash, phoneCode: phoneCode))
|
||||
|> mapError { error -> CancelAccountResetError in
|
||||
if error.errorDescription.hasPrefix("FLOOD_WAIT") {
|
@ -113,6 +113,18 @@ public extension TelegramEngine {
|
||||
public func declineTwoStepPasswordReset() -> Signal<Never, NoError> {
|
||||
return _internal_declineTwoStepPasswordReset(network: self.account.network)
|
||||
}
|
||||
|
||||
public func requestCancelAccountResetData(hash: String) -> Signal<CancelAccountResetData, RequestCancelAccountResetDataError> {
|
||||
return _internal_requestCancelAccountResetData(network: self.account.network, hash: hash)
|
||||
}
|
||||
|
||||
public func requestNextCancelAccountResetOption(phoneNumber: String, phoneCodeHash: String) -> Signal<CancelAccountResetData, RequestCancelAccountResetDataError> {
|
||||
return _internal_requestNextCancelAccountResetOption(network: self.account.network, phoneNumber: phoneNumber, phoneCodeHash: phoneCodeHash)
|
||||
}
|
||||
|
||||
public func requestCancelAccountReset(phoneCodeHash: String, phoneCode: String) -> Signal<Never, CancelAccountResetError> {
|
||||
return _internal_requestCancelAccountReset(network: self.account.network, phoneCodeHash: phoneCodeHash, phoneCode: phoneCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil))
|
||||
present(controller, nil)
|
||||
let _ = (requestCancelAccountResetData(network: context.account.network, hash: hash)
|
||||
let _ = (context.engine.auth.requestCancelAccountResetData(hash: hash)
|
||||
|> deliverOnMainQueue).start(next: { [weak controller] data in
|
||||
controller?.dismiss()
|
||||
present(confirmPhoneNumberCodeController(context: context, phoneNumber: phone, codeData: data), ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
|
@ -2472,12 +2472,12 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
|
||||
var updateNameSignal: Signal<Void, NoError> = .complete()
|
||||
var hasProgress = false
|
||||
if peer.firstName != firstName || peer.lastName != lastName {
|
||||
updateNameSignal = updateAccountPeerName(account: context.account, firstName: firstName, lastName: lastName)
|
||||
updateNameSignal = context.engine.accountData.updateAccountPeerName(firstName: firstName, lastName: lastName)
|
||||
hasProgress = true
|
||||
}
|
||||
var updateBioSignal: Signal<Void, NoError> = .complete()
|
||||
if let bio = bio, bio != cachedData.about {
|
||||
updateBioSignal = updateAbout(account: context.account, about: bio)
|
||||
updateBioSignal = context.engine.accountData.updateAbout(about: bio)
|
||||
|> `catch` { _ -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user