From a4b40dd216c4dfb389ae093274a755bf634a9164 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 2 Jul 2021 16:35:53 +0400 Subject: [PATCH] Update API --- submodules/TelegramApi/Sources/Api0.swift | 8 +- submodules/TelegramApi/Sources/Api2.swift | 36 +++++ submodules/TelegramApi/Sources/Api4.swift | 134 ++++++++++++++++-- submodules/TelegramCore/Sources/Account.swift | 3 +- .../TelegramCore/Sources/Authorization.swift | 38 +---- .../Sources/TwoStepVerification.swift | 8 +- .../AuthorizationSequenceController.swift | 26 +--- 7 files changed, 175 insertions(+), 78 deletions(-) diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index 3c9df65cf7..57f1f4c9d9 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -281,6 +281,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[2146218476] = { return Api.Update.parse_updateChannelParticipant($0) } dict[133777546] = { return Api.Update.parse_updateBotStopped($0) } dict[192428418] = { return Api.Update.parse_updateGroupCallConnection($0) } + dict[-813823885] = { return Api.Update.parse_updateBotCommands($0) } dict[136574537] = { return Api.messages.VotesList.parse_votesList($0) } dict[1558266229] = { return Api.PopularContact.parse_popularContact($0) } dict[-592373577] = { return Api.GroupCallParticipantVideoSourceGroup.parse_groupCallParticipantVideoSourceGroup($0) } @@ -557,6 +558,9 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[182649427] = { return Api.MessageRange.parse_messageRange($0) } dict[946083368] = { return Api.messages.StickerSetInstallResult.parse_stickerSetInstallResultSuccess($0) } dict[904138920] = { return Api.messages.StickerSetInstallResult.parse_stickerSetInstallResultArchive($0) } + dict[-478701471] = { return Api.account.ResetPasswordResult.parse_resetPasswordFailedWait($0) } + dict[-370148227] = { return Api.account.ResetPasswordResult.parse_resetPasswordRequestedWait($0) } + dict[-383330754] = { return Api.account.ResetPasswordResult.parse_resetPasswordOk($0) } dict[856375399] = { return Api.Config.parse_config($0) } dict[-75283823] = { return Api.TopPeerCategoryPeers.parse_topPeerCategoryPeers($0) } dict[-1107729093] = { return Api.Game.parse_game($0) } @@ -795,7 +799,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1908627474] = { return Api.SecureValueType.parse_secureValueTypeEmail($0) } dict[-732254058] = { return Api.PasswordKdfAlgo.parse_passwordKdfAlgoUnknown($0) } dict[982592842] = { return Api.PasswordKdfAlgo.parse_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow($0) } - dict[-1390001672] = { return Api.account.Password.parse_password($0) } + dict[408623183] = { return Api.account.Password.parse_password($0) } dict[-2000710887] = { return Api.InputBotInlineResult.parse_inputBotInlineResult($0) } dict[-1462213465] = { return Api.InputBotInlineResult.parse_inputBotInlineResultPhoto($0) } dict[-459324] = { return Api.InputBotInlineResult.parse_inputBotInlineResultDocument($0) } @@ -1313,6 +1317,8 @@ public struct Api { _1.serialize(buffer, boxed) case let _1 as Api.messages.StickerSetInstallResult: _1.serialize(buffer, boxed) + case let _1 as Api.account.ResetPasswordResult: + _1.serialize(buffer, boxed) case let _1 as Api.Config: _1.serialize(buffer, boxed) case let _1 as Api.TopPeerCategoryPeers: diff --git a/submodules/TelegramApi/Sources/Api2.swift b/submodules/TelegramApi/Sources/Api2.swift index 6c382b818b..597f5d0fe5 100644 --- a/submodules/TelegramApi/Sources/Api2.swift +++ b/submodules/TelegramApi/Sources/Api2.swift @@ -4690,6 +4690,7 @@ public extension Api { case updateChannelParticipant(flags: Int32, channelId: Int32, date: Int32, actorId: Int32, userId: Int32, prevParticipant: Api.ChannelParticipant?, newParticipant: Api.ChannelParticipant?, invite: Api.ExportedChatInvite?, qts: Int32) case updateBotStopped(userId: Int32, date: Int32, stopped: Api.Bool, qts: Int32) case updateGroupCallConnection(flags: Int32, params: Api.DataJSON) + case updateBotCommands(peer: Api.Peer, botId: Int32, commands: [Api.BotCommand]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -5492,6 +5493,18 @@ public extension Api { serializeInt32(flags, buffer: buffer, boxed: false) params.serialize(buffer, true) break + case .updateBotCommands(let peer, let botId, let commands): + if boxed { + buffer.appendInt32(-813823885) + } + peer.serialize(buffer, true) + serializeInt32(botId, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(commands.count)) + for item in commands { + item.serialize(buffer, true) + } + break } } @@ -5681,6 +5694,8 @@ public extension Api { return ("updateBotStopped", [("userId", userId), ("date", date), ("stopped", stopped), ("qts", qts)]) case .updateGroupCallConnection(let flags, let params): return ("updateGroupCallConnection", [("flags", flags), ("params", params)]) + case .updateBotCommands(let peer, let botId, let commands): + return ("updateBotCommands", [("peer", peer), ("botId", botId), ("commands", commands)]) } } @@ -7319,6 +7334,27 @@ public extension Api { return nil } } + public static func parse_updateBotCommands(_ reader: BufferReader) -> Update? { + var _1: Api.Peer? + if let signature = reader.readInt32() { + _1 = Api.parse(reader, signature: signature) as? Api.Peer + } + var _2: Int32? + _2 = reader.readInt32() + var _3: [Api.BotCommand]? + if let _ = reader.readInt32() { + _3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.BotCommand.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + if _c1 && _c2 && _c3 { + return Api.Update.updateBotCommands(peer: _1!, botId: _2!, commands: _3!) + } + else { + return nil + } + } } public enum PopularContact: TypeConstructorDescription { diff --git a/submodules/TelegramApi/Sources/Api4.swift b/submodules/TelegramApi/Sources/Api4.swift index 3e7bdcfd25..fbbd0ce0df 100644 --- a/submodules/TelegramApi/Sources/Api4.swift +++ b/submodules/TelegramApi/Sources/Api4.swift @@ -1171,6 +1171,72 @@ public struct account { } } + } + public enum ResetPasswordResult: TypeConstructorDescription { + case resetPasswordFailedWait(retryDate: Int32) + case resetPasswordRequestedWait(untilDate: Int32) + case resetPasswordOk + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .resetPasswordFailedWait(let retryDate): + if boxed { + buffer.appendInt32(-478701471) + } + serializeInt32(retryDate, buffer: buffer, boxed: false) + break + case .resetPasswordRequestedWait(let untilDate): + if boxed { + buffer.appendInt32(-370148227) + } + serializeInt32(untilDate, buffer: buffer, boxed: false) + break + case .resetPasswordOk: + if boxed { + buffer.appendInt32(-383330754) + } + + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .resetPasswordFailedWait(let retryDate): + return ("resetPasswordFailedWait", [("retryDate", retryDate)]) + case .resetPasswordRequestedWait(let untilDate): + return ("resetPasswordRequestedWait", [("untilDate", untilDate)]) + case .resetPasswordOk: + return ("resetPasswordOk", []) + } + } + + public static func parse_resetPasswordFailedWait(_ reader: BufferReader) -> ResetPasswordResult? { + var _1: Int32? + _1 = reader.readInt32() + let _c1 = _1 != nil + if _c1 { + return Api.account.ResetPasswordResult.resetPasswordFailedWait(retryDate: _1!) + } + else { + return nil + } + } + public static func parse_resetPasswordRequestedWait(_ reader: BufferReader) -> ResetPasswordResult? { + var _1: Int32? + _1 = reader.readInt32() + let _c1 = _1 != nil + if _c1 { + return Api.account.ResetPasswordResult.resetPasswordRequestedWait(untilDate: _1!) + } + else { + return nil + } + } + public static func parse_resetPasswordOk(_ reader: BufferReader) -> ResetPasswordResult? { + return Api.account.ResetPasswordResult.resetPasswordOk + } + } public enum ContentSettings: TypeConstructorDescription { case contentSettings(flags: Int32) @@ -1325,13 +1391,13 @@ public struct account { } public enum Password: TypeConstructorDescription { - case password(flags: Int32, currentAlgo: Api.PasswordKdfAlgo?, srpB: Buffer?, srpId: Int64?, hint: String?, emailUnconfirmedPattern: String?, newAlgo: Api.PasswordKdfAlgo, newSecureAlgo: Api.SecurePasswordKdfAlgo, secureRandom: Buffer) + case password(flags: Int32, currentAlgo: Api.PasswordKdfAlgo?, srpB: Buffer?, srpId: Int64?, hint: String?, emailUnconfirmedPattern: String?, newAlgo: Api.PasswordKdfAlgo, newSecureAlgo: Api.SecurePasswordKdfAlgo, secureRandom: Buffer, pendingResetDate: Int32?) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .password(let flags, let currentAlgo, let srpB, let srpId, let hint, let emailUnconfirmedPattern, let newAlgo, let newSecureAlgo, let secureRandom): + case .password(let flags, let currentAlgo, let srpB, let srpId, let hint, let emailUnconfirmedPattern, let newAlgo, let newSecureAlgo, let secureRandom, let pendingResetDate): if boxed { - buffer.appendInt32(-1390001672) + buffer.appendInt32(408623183) } serializeInt32(flags, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 2) != 0 {currentAlgo!.serialize(buffer, true)} @@ -1342,14 +1408,15 @@ public struct account { newAlgo.serialize(buffer, true) newSecureAlgo.serialize(buffer, true) serializeBytes(secureRandom, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 5) != 0 {serializeInt32(pendingResetDate!, buffer: buffer, boxed: false)} break } } public func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .password(let flags, let currentAlgo, let srpB, let srpId, let hint, let emailUnconfirmedPattern, let newAlgo, let newSecureAlgo, let secureRandom): - return ("password", [("flags", flags), ("currentAlgo", currentAlgo), ("srpB", srpB), ("srpId", srpId), ("hint", hint), ("emailUnconfirmedPattern", emailUnconfirmedPattern), ("newAlgo", newAlgo), ("newSecureAlgo", newSecureAlgo), ("secureRandom", secureRandom)]) + case .password(let flags, let currentAlgo, let srpB, let srpId, let hint, let emailUnconfirmedPattern, let newAlgo, let newSecureAlgo, let secureRandom, let pendingResetDate): + return ("password", [("flags", flags), ("currentAlgo", currentAlgo), ("srpB", srpB), ("srpId", srpId), ("hint", hint), ("emailUnconfirmedPattern", emailUnconfirmedPattern), ("newAlgo", newAlgo), ("newSecureAlgo", newSecureAlgo), ("secureRandom", secureRandom), ("pendingResetDate", pendingResetDate)]) } } @@ -1378,6 +1445,8 @@ public struct account { } var _9: Buffer? _9 = parseBytes(reader) + var _10: Int32? + if Int(_1!) & Int(1 << 5) != 0 {_10 = reader.readInt32() } let _c1 = _1 != nil let _c2 = (Int(_1!) & Int(1 << 2) == 0) || _2 != nil let _c3 = (Int(_1!) & Int(1 << 2) == 0) || _3 != nil @@ -1387,8 +1456,9 @@ public struct account { let _c7 = _7 != nil let _c8 = _8 != nil let _c9 = _9 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 { - return Api.account.Password.password(flags: _1!, currentAlgo: _2, srpB: _3, srpId: _4, hint: _5, emailUnconfirmedPattern: _6, newAlgo: _7!, newSecureAlgo: _8!, secureRandom: _9!) + let _c10 = (Int(_1!) & Int(1 << 5) == 0) || _10 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 { + return Api.account.Password.password(flags: _1!, currentAlgo: _2, srpB: _3, srpId: _4, hint: _5, emailUnconfirmedPattern: _6, newAlgo: _7!, newSecureAlgo: _8!, secureRandom: _9!, pendingResetDate: _10) } else { return nil @@ -5250,11 +5320,13 @@ public extension Api { }) } - public static func recoverPassword(code: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func recoverPassword(flags: Int32, code: String, newSettings: Api.account.PasswordInputSettings?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(1319464594) + buffer.appendInt32(923364464) + serializeInt32(flags, buffer: buffer, boxed: false) serializeString(code, buffer: buffer, boxed: false) - return (FunctionDescription(name: "auth.recoverPassword", parameters: [("code", code)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.auth.Authorization? in + if Int(flags) & Int(1 << 0) != 0 {newSettings!.serialize(buffer, true)} + return (FunctionDescription(name: "auth.recoverPassword", parameters: [("flags", flags), ("code", code), ("newSettings", newSettings)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.auth.Authorization? in let reader = BufferReader(buffer) var result: Api.auth.Authorization? if let signature = reader.readInt32() { @@ -5359,6 +5431,20 @@ public extension Api { return result }) } + + public static func checkRecoveryPassword(code: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(221691769) + serializeString(code, buffer: buffer, boxed: false) + return (FunctionDescription(name: "auth.checkRecoveryPassword", parameters: [("code", code)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in + let reader = BufferReader(buffer) + var result: Api.Bool? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.Bool + } + return result + }) + } } public struct bots { public static func sendCustomRequest(customMethod: String, params: Api.DataJSON) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { @@ -7502,6 +7588,34 @@ public extension Api { return result }) } + + public static func resetPassword() -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(-1828139493) + + return (FunctionDescription(name: "account.resetPassword", parameters: []), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.account.ResetPasswordResult? in + let reader = BufferReader(buffer) + var result: Api.account.ResetPasswordResult? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.account.ResetPasswordResult + } + return result + }) + } + + public static func declinePasswordReset() -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(1284770294) + + return (FunctionDescription(name: "account.declinePasswordReset", parameters: []), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in + let reader = BufferReader(buffer) + var result: Api.Bool? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.Bool + } + return result + }) + } } public struct langpack { public static func getLangPack(langPack: String, langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { diff --git a/submodules/TelegramCore/Sources/Account.swift b/submodules/TelegramCore/Sources/Account.swift index 2782aec531..808361feb3 100644 --- a/submodules/TelegramCore/Sources/Account.swift +++ b/submodules/TelegramCore/Sources/Account.swift @@ -377,8 +377,7 @@ public func twoStepAuthData(_ network: Network) -> Signal map { config -> TwoStepAuthData in switch config { - case let .password(flags, currentAlgo, srpB, srpId, hint, emailUnconfirmedPattern, newAlgo, newSecureAlgo, secureRandom/*, pendingResetDate*/): - let pendingResetDate: Int32? = nil + case let .password(flags, currentAlgo, srpB, srpId, hint, emailUnconfirmedPattern, newAlgo, newSecureAlgo, secureRandom, pendingResetDate): let hasRecovery = (flags & (1 << 0)) != 0 let hasSecureValues = (flags & (1 << 1)) != 0 diff --git a/submodules/TelegramCore/Sources/Authorization.swift b/submodules/TelegramCore/Sources/Authorization.swift index 834810a6f1..ccc03759c8 100644 --- a/submodules/TelegramCore/Sources/Authorization.swift +++ b/submodules/TelegramCore/Sources/Authorization.swift @@ -373,41 +373,7 @@ public enum PasswordRecoveryError { case generic } -public func performPasswordRecovery(accountManager: AccountManager, account: UnauthorizedAccount, code: String, syncContacts: Bool) -> Signal { - return account.network.request(Api.functions.auth.recoverPassword(code: code)) - |> mapError { error -> PasswordRecoveryError in - if error.errorDescription.hasPrefix("FLOOD_WAIT") { - return .limitExceeded - } else if error.errorDescription.hasPrefix("PASSWORD_RECOVERY_EXPIRED") { - return .expired - } else { - return .invalidCode - } - } - |> mapToSignal { result -> Signal in - return account.postbox.transaction { transaction -> Signal in - switch result { - case let .authorization(_, _, user): - let user = TelegramUser(user: user) - let state = AuthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, peerId: user.id, state: nil) - /*transaction.updatePeersInternal([user], update: { current, peer -> Peer? in - return peer - })*/ - initializedAppSettingsAfterLogin(transaction: transaction, appVersion: account.networkArguments.appVersion, syncContacts: syncContacts) - transaction.setState(state) - return accountManager.transaction { transaction -> Void in - switchToAuthorizedAccount(transaction: transaction, account: account) - } - case .authorizationSignUpRequired: - return .complete() - } - } - |> switchToLatest - |> mapError { _ -> PasswordRecoveryError in } - } -} - -/*public func checkPasswordRecoveryCode(network: Network, code: String) -> Signal { +public func checkPasswordRecoveryCode(network: Network, code: String) -> Signal { return network.request(Api.functions.auth.checkRecoveryPassword(code: code), automaticFloodWait: false) |> mapError { error -> PasswordRecoveryError in if error.errorDescription.hasPrefix("FLOOD_WAIT") { @@ -480,7 +446,7 @@ public func performPasswordRecovery(accountManager: AccountManager, account: Una |> mapError { _ -> PasswordRecoveryError in } } } -}*/ +} public enum AccountResetError { case generic diff --git a/submodules/TelegramCore/Sources/TwoStepVerification.swift b/submodules/TelegramCore/Sources/TwoStepVerification.swift index 9348a21714..08bcc49353 100644 --- a/submodules/TelegramCore/Sources/TwoStepVerification.swift +++ b/submodules/TelegramCore/Sources/TwoStepVerification.swift @@ -18,7 +18,7 @@ public func twoStepVerificationConfiguration(account: Account) -> Signal mapError { error -> RecoverTwoStepVerificationPasswordError in if error.errorDescription.hasPrefix("FLOOD_WAIT_") { return .limitExceeded @@ -426,7 +426,7 @@ public enum RequestTwoStepPasswordResetResult { case error(reason: ErrorReason) } -/*public func requestTwoStepPasswordReset(network: Network) -> Signal { +public func requestTwoStepPasswordReset(network: Network) -> Signal { return network.request(Api.functions.account.resetPassword(), automaticFloodWait: false) |> map { _ -> RequestTwoStepPasswordResetResult in return .done @@ -462,4 +462,4 @@ public func declineTwoStepPasswordReset(network: Network) -> Signal ignoreValues -}*/ +} diff --git a/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift b/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift index a68038b33a..30c410b7dd 100644 --- a/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift +++ b/submodules/TelegramUI/Sources/AuthorizationSequenceController.swift @@ -571,30 +571,6 @@ public final class AuthorizationSequenceController: NavigationController, MFMail controller?.inProgress = true - strongSelf.actionDisposable.set((performPasswordRecovery(accountManager: strongSelf.sharedContext.accountManager, account: strongSelf.account, code: code, syncContacts: syncContacts) |> deliverOnMainQueue).start(error: { error in - Queue.mainQueue().async { - if let strongSelf = self, let controller = controller { - controller.inProgress = false - - let text: String - switch error { - case .limitExceeded: - text = strongSelf.presentationData.strings.LoginPassword_FloodError - case .invalidCode: - text = strongSelf.presentationData.strings.Login_InvalidCodeError - case .expired: - text = strongSelf.presentationData.strings.Login_CodeExpiredError - case .generic: - text = strongSelf.presentationData.strings.Login_UnknownError - } - - controller.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: strongSelf.presentationData), title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root)) - } - } - })) - - /*controller?.inProgress = true - strongSelf.actionDisposable.set((checkPasswordRecoveryCode(network: strongSelf.account.network, code: code) |> deliverOnMainQueue).start(error: { error in guard let strongSelf = self, let controller = controller else { @@ -627,7 +603,7 @@ public final class AuthorizationSequenceController: NavigationController, MFMail } }) strongSelf.setViewControllers(strongSelf.viewControllers + [setupController], animated: true) - }))*/ + })) } controller.noAccess = { [weak self, weak controller] in if let strongSelf = self, let controller = controller {