diff --git a/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift b/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift index 5cbbed6dee..0dd32295e6 100644 --- a/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift +++ b/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift @@ -230,7 +230,7 @@ func changePhoneNumberCodeController(context: AccountContext, phoneNumber: Strin |> take(1) |> mapToSignal { _ -> Signal 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) } diff --git a/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift b/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift index 830ea6110b..05aac53984 100644 --- a/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift +++ b/submodules/SettingsUI/Sources/ChangePhoneNumberController.swift @@ -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)) diff --git a/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift b/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift index ac27bd6795..e0b7c6dee5 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift @@ -216,7 +216,7 @@ public func confirmPhoneNumberCodeController(context: AccountContext, phoneNumbe |> take(1) |> mapToSignal { _ -> Signal 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 diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index 309a87b21c..46614f78d2 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -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 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 }) } diff --git a/submodules/TelegramCore/Sources/ChangeAccountPhoneNumber.swift b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/ChangeAccountPhoneNumber.swift similarity index 88% rename from submodules/TelegramCore/Sources/ChangeAccountPhoneNumber.swift rename to submodules/TelegramCore/Sources/TelegramEngine/AccountData/ChangeAccountPhoneNumber.swift index 73fb23a566..8ceec98541 100644 --- a/submodules/TelegramCore/Sources/ChangeAccountPhoneNumber.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/ChangeAccountPhoneNumber.swift @@ -37,7 +37,7 @@ public enum RequestChangeAccountPhoneNumberVerificationError { case generic } -public func requestChangeAccountPhoneNumberVerification(account: Account, phoneNumber: String) -> Signal { +func _internal_requestChangeAccountPhoneNumberVerification(account: Account, phoneNumber: String) -> Signal { 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 { +func _internal_requestNextChangeAccountPhoneNumberVerification(account: Account, phoneNumber: String, phoneCodeHash: String) -> Signal { 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 { +func _internal_requestChangeAccountPhoneNumber(account: Account, phoneNumber: String, phoneCodeHash: String, phoneCode: String) -> Signal { 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") { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift index 38aec73575..f9a025c8b2 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/TelegramEngineAccountData.swift @@ -15,5 +15,25 @@ public extension TelegramEngine { public func resetAccountDueTermsOfService() -> Signal { return _internal_resetAccountDueTermsOfService(network: self.account.network) } + + public func requestChangeAccountPhoneNumberVerification(phoneNumber: String) -> Signal { + return _internal_requestChangeAccountPhoneNumberVerification(account: self.account, phoneNumber: phoneNumber) + } + + public func requestNextChangeAccountPhoneNumberVerification(phoneNumber: String, phoneCodeHash: String) -> Signal { + return _internal_requestNextChangeAccountPhoneNumberVerification(account: self.account, phoneNumber: phoneNumber, phoneCodeHash: phoneCodeHash) + } + + public func requestChangeAccountPhoneNumber(phoneNumber: String, phoneCodeHash: String, phoneCode: String) -> Signal { + return _internal_requestChangeAccountPhoneNumber(account: self.account, phoneNumber: phoneNumber, phoneCodeHash: phoneCodeHash, phoneCode: phoneCode) + } + + public func updateAccountPeerName(firstName: String, lastName: String) -> Signal { + return _internal_updateAccountPeerName(account: self.account, firstName: firstName, lastName: lastName) + } + + public func updateAbout(about: String?) -> Signal { + return _internal_updateAbout(account: self.account, about: about) + } } } diff --git a/submodules/TelegramCore/Sources/UpdateAccountPeerName.swift b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/UpdateAccountPeerName.swift similarity index 88% rename from submodules/TelegramCore/Sources/UpdateAccountPeerName.swift rename to submodules/TelegramCore/Sources/TelegramEngine/AccountData/UpdateAccountPeerName.swift index f46bc43b89..533a240653 100644 --- a/submodules/TelegramCore/Sources/UpdateAccountPeerName.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/AccountData/UpdateAccountPeerName.swift @@ -6,7 +6,7 @@ import MtProtoKit import SyncCore -public func updateAccountPeerName(account: Account, firstName: String, lastName: String) -> Signal { +func _internal_updateAccountPeerName(account: Account, firstName: String, lastName: String) -> Signal { 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 { +func _internal_updateAbout(account: Account, about: String?) -> Signal { 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 diff --git a/submodules/TelegramCore/Sources/CancelAccountReset.swift b/submodules/TelegramCore/Sources/TelegramEngine/Auth/CancelAccountReset.swift similarity index 85% rename from submodules/TelegramCore/Sources/CancelAccountReset.swift rename to submodules/TelegramCore/Sources/TelegramEngine/Auth/CancelAccountReset.swift index ef3215c26c..60e1b8e0ca 100644 --- a/submodules/TelegramCore/Sources/CancelAccountReset.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Auth/CancelAccountReset.swift @@ -18,7 +18,7 @@ public enum RequestCancelAccountResetDataError { case generic } -public func requestCancelAccountResetData(network: Network, hash: String) -> Signal { +func _internal_requestCancelAccountResetData(network: Network, hash: String) -> Signal { 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 { +func _internal_requestNextCancelAccountResetOption(network: Network, phoneNumber: String, phoneCodeHash: String) -> Signal { 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 { +func _internal_requestCancelAccountReset(network: Network, phoneCodeHash: String, phoneCode: String) -> Signal { return network.request(Api.functions.account.confirmPhone(phoneCodeHash: phoneCodeHash, phoneCode: phoneCode)) |> mapError { error -> CancelAccountResetError in if error.errorDescription.hasPrefix("FLOOD_WAIT") { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift b/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift index a23fcd2d02..e3cd9fe4d2 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Auth/TelegramEngineAuth.swift @@ -113,6 +113,18 @@ public extension TelegramEngine { public func declineTwoStepPasswordReset() -> Signal { return _internal_declineTwoStepPasswordReset(network: self.account.network) } + + public func requestCancelAccountResetData(hash: String) -> Signal { + return _internal_requestCancelAccountResetData(network: self.account.network, hash: hash) + } + + public func requestNextCancelAccountResetOption(phoneNumber: String, phoneCodeHash: String) -> Signal { + return _internal_requestNextCancelAccountResetOption(network: self.account.network, phoneNumber: phoneNumber, phoneCodeHash: phoneCodeHash) + } + + public func requestCancelAccountReset(phoneCodeHash: String, phoneCode: String) -> Signal { + return _internal_requestCancelAccountReset(network: self.account.network, phoneCodeHash: phoneCodeHash, phoneCode: phoneCode) + } } } diff --git a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift index c191bab96e..320481e6ad 100644 --- a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift @@ -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)) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index d8d38e7f28..a2c7a0f3d0 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -2472,12 +2472,12 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD var updateNameSignal: Signal = .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 = .complete() if let bio = bio, bio != cachedData.about { - updateBioSignal = updateAbout(account: context.account, about: bio) + updateBioSignal = context.engine.accountData.updateAbout(about: bio) |> `catch` { _ -> Signal in return .complete() }