From f114b5d0ef563101c61cb606e181f2bb6724f2a4 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 13 Jun 2018 15:24:04 +0300 Subject: [PATCH] no message --- TelegramCore/AccountStateReset.swift | 7 +- TelegramCore/Api0.swift | 26 ++++++- TelegramCore/Api1.swift | 78 ++++++++++++++++--- TelegramCore/Api3.swift | 72 ++++++++++++----- TelegramCore/FetchChatList.swift | 5 +- .../ManagedGlobalNotificationSettings.swift | 3 +- TelegramCore/MarkAllChatsAsRead.swift | 2 +- TelegramCore/RequestChatContextResults.swift | 2 +- TelegramCore/SaveSecureIdValue.swift | 26 ++++--- .../SecureIdPersonalDetailsValue.swift | 2 +- TelegramCore/TwoStepVerification.swift | 2 +- 11 files changed, 175 insertions(+), 50 deletions(-) diff --git a/TelegramCore/AccountStateReset.swift b/TelegramCore/AccountStateReset.swift index 10ca6e811f..b567e676f6 100644 --- a/TelegramCore/AccountStateReset.swift +++ b/TelegramCore/AccountStateReset.swift @@ -16,7 +16,7 @@ func accountStateReset(postbox: Postbox, network: Network) -> Signal retryRequest - return combineLatest(network.request(Api.functions.messages.getDialogs(flags: 0, /*feed*//*feedId: nil,*/ offsetDate: 0, offsetId: 0, offsetPeer: .inputPeerEmpty, limit: 100)) + return combineLatest(network.request(Api.functions.messages.getDialogs(flags: 0, /*feed*//*feedId: nil,*/ offsetDate: 0, offsetId: 0, offsetPeer: .inputPeerEmpty, limit: 100, hash: 0)) |> retryRequest, pinnedChats, state) |> mapToSignal { result, pinnedChats, state -> Signal in var dialogsDialogs: [Api.Dialog] = [] @@ -38,6 +38,11 @@ func accountStateReset(postbox: Postbox, network: Network) -> Signal Any?] = { dict[767652808] = { return Api.InputEncryptedFile.parse_inputEncryptedFileBigUploaded($0) } dict[1443858741] = { return Api.messages.SentEncryptedMessage.parse_sentEncryptedMessage($0) } dict[-1802240206] = { return Api.messages.SentEncryptedMessage.parse_sentEncryptedFile($0) } + dict[966688703] = { return Api.SavedContact.parse_savedPhoneContact($0) } dict[1571494644] = { return Api.ExportedMessageLink.parse_exportedMessageLink($0) } dict[-855308010] = { return Api.auth.Authorization.parse_authorization($0) } dict[-181407105] = { return Api.InputFile.parse_inputFile($0) } @@ -343,8 +344,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[777640226] = { return Api.ReportReason.parse_inputReportReasonPornography($0) } dict[-512463606] = { return Api.ReportReason.parse_inputReportReasonOther($0) } dict[-247351839] = { return Api.InputEncryptedChat.parse_inputEncryptedChat($0) } - dict[-1169445179] = { return Api.DraftMessage.parse_draftMessageEmpty($0) } dict[-40996577] = { return Api.DraftMessage.parse_draftMessage($0) } + dict[453805082] = { return Api.DraftMessage.parse_draftMessageEmpty($0) } dict[1568467877] = { return Api.ChannelAdminRights.parse_channelAdminRights($0) } dict[-2128640689] = { return Api.account.SentEmailCode.parse_sentEmailCode($0) } dict[-1038136962] = { return Api.EncryptedFile.parse_encryptedFileEmpty($0) } @@ -526,6 +527,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-530392189] = { return Api.MessagesFilter.parse_inputMessagesFilterContacts($0) } dict[364538944] = { return Api.messages.Dialogs.parse_dialogs($0) } dict[1910543603] = { return Api.messages.Dialogs.parse_dialogsSlice($0) } + dict[-253500010] = { return Api.messages.Dialogs.parse_dialogsNotModified($0) } dict[-290921362] = { return Api.upload.CdnFile.parse_cdnFileReuploadNeeded($0) } dict[-1449145777] = { return Api.upload.CdnFile.parse_cdnFile($0) } dict[415997816] = { return Api.help.InviteText.parse_inviteText($0) } @@ -771,6 +773,8 @@ struct Api { _1.serialize(buffer, boxed) case let _1 as Api.messages.SentEncryptedMessage: _1.serialize(buffer, boxed) + case let _1 as Api.SavedContact: + _1.serialize(buffer, boxed) case let _1 as Api.ExportedMessageLink: _1.serialize(buffer, boxed) case let _1 as Api.auth.Authorization: @@ -2424,6 +2428,7 @@ struct messages { enum Dialogs: TypeConstructorDescription { case dialogs(dialogs: [Api.Dialog], messages: [Api.Message], chats: [Api.Chat], users: [Api.User]) case dialogsSlice(count: Int32, dialogs: [Api.Dialog], messages: [Api.Message], chats: [Api.Chat], users: [Api.User]) + case dialogsNotModified(count: Int32) func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -2478,6 +2483,12 @@ struct messages { item.serialize(buffer, true) } break + case .dialogsNotModified(let count): + if boxed { + buffer.appendInt32(-253500010) + } + serializeInt32(count, buffer: buffer, boxed: false) + break } } @@ -2487,6 +2498,8 @@ struct messages { return ("dialogs", [("dialogs", dialogs), ("messages", messages), ("chats", chats), ("users", users)]) case .dialogsSlice(let count, let dialogs, let messages, let chats, let users): return ("dialogsSlice", [("count", count), ("dialogs", dialogs), ("messages", messages), ("chats", chats), ("users", users)]) + case .dialogsNotModified(let count): + return ("dialogsNotModified", [("count", count)]) } } @@ -2549,6 +2562,17 @@ struct messages { return nil } } + static func parse_dialogsNotModified(_ reader: BufferReader) -> Dialogs? { + var _1: Int32? + _1 = reader.readInt32() + let _c1 = _1 != nil + if _c1 { + return Api.messages.Dialogs.dialogsNotModified(count: _1!) + } + else { + return nil + } + } } enum FavedStickers: TypeConstructorDescription { diff --git a/TelegramCore/Api1.swift b/TelegramCore/Api1.swift index 2c8f38ab3f..7200476c22 100644 --- a/TelegramCore/Api1.swift +++ b/TelegramCore/Api1.swift @@ -2164,6 +2164,48 @@ extension Api { } } + } + enum SavedContact: TypeConstructorDescription { + case savedPhoneContact(phone: String, firstName: String, lastName: String) + + func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .savedPhoneContact(let phone, let firstName, let lastName): + if boxed { + buffer.appendInt32(966688703) + } + serializeString(phone, buffer: buffer, boxed: false) + serializeString(firstName, buffer: buffer, boxed: false) + serializeString(lastName, buffer: buffer, boxed: false) + break + } + } + + func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .savedPhoneContact(let phone, let firstName, let lastName): + return ("savedPhoneContact", [("phone", phone), ("firstName", firstName), ("lastName", lastName)]) + } + } + + static func parse_savedPhoneContact(_ reader: BufferReader) -> SavedContact? { + var _1: String? + _1 = parseString(reader) + var _2: String? + _2 = parseString(reader) + var _3: String? + _3 = parseString(reader) + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + if _c1 && _c2 && _c3 { + return Api.SavedContact.savedPhoneContact(phone: _1!, firstName: _2!, lastName: _3!) + } + else { + return nil + } + } + } enum ExportedMessageLink: TypeConstructorDescription { case exportedMessageLink(link: String, html: String) @@ -8166,17 +8208,11 @@ extension Api { } enum DraftMessage: TypeConstructorDescription { - case draftMessageEmpty case draftMessage(flags: Int32, replyToMsgId: Int32?, message: String, entities: [Api.MessageEntity]?, date: Int32) + case draftMessageEmpty(flags: Int32, date: Int32?) func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .draftMessageEmpty: - if boxed { - buffer.appendInt32(-1169445179) - } - - break case .draftMessage(let flags, let replyToMsgId, let message, let entities, let date): if boxed { buffer.appendInt32(-40996577) @@ -8191,21 +8227,25 @@ extension Api { }} serializeInt32(date, buffer: buffer, boxed: false) break + case .draftMessageEmpty(let flags, let date): + if boxed { + buffer.appendInt32(453805082) + } + serializeInt32(flags, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {serializeInt32(date!, buffer: buffer, boxed: false)} + break } } func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .draftMessageEmpty: - return ("draftMessageEmpty", []) case .draftMessage(let flags, let replyToMsgId, let message, let entities, let date): return ("draftMessage", [("flags", flags), ("replyToMsgId", replyToMsgId), ("message", message), ("entities", entities), ("date", date)]) + case .draftMessageEmpty(let flags, let date): + return ("draftMessageEmpty", [("flags", flags), ("date", date)]) } } - static func parse_draftMessageEmpty(_ reader: BufferReader) -> DraftMessage? { - return Api.DraftMessage.draftMessageEmpty - } static func parse_draftMessage(_ reader: BufferReader) -> DraftMessage? { var _1: Int32? _1 = reader.readInt32() @@ -8231,6 +8271,20 @@ extension Api { return nil } } + static func parse_draftMessageEmpty(_ reader: BufferReader) -> DraftMessage? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + if Int(_1!) & Int(1 << 0) != 0 {_2 = reader.readInt32() } + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil + if _c1 && _c2 { + return Api.DraftMessage.draftMessageEmpty(flags: _1!, date: _2) + } + else { + return nil + } + } } enum ChannelAdminRights: TypeConstructorDescription { diff --git a/TelegramCore/Api3.swift b/TelegramCore/Api3.swift index 63e1298ece..27dae2ac62 100644 --- a/TelegramCore/Api3.swift +++ b/TelegramCore/Api3.swift @@ -1021,24 +1021,6 @@ struct phone { extension Api { struct functions { struct messages { - static func getDialogs(flags: Int32, offsetDate: Int32, offsetId: Int32, offsetPeer: Api.InputPeer, limit: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { - let buffer = Buffer() - buffer.appendInt32(421243333) - serializeInt32(flags, buffer: buffer, boxed: false) - serializeInt32(offsetDate, buffer: buffer, boxed: false) - serializeInt32(offsetId, buffer: buffer, boxed: false) - offsetPeer.serialize(buffer, true) - serializeInt32(limit, buffer: buffer, boxed: false) - return (FunctionDescription(name: "messages.getDialogs", parameters: [("flags", flags), ("offsetDate", offsetDate), ("offsetId", offsetId), ("offsetPeer", offsetPeer), ("limit", limit)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Dialogs? in - let reader = BufferReader(buffer) - var result: Api.messages.Dialogs? - if let signature = reader.readInt32() { - result = Api.parse(reader, signature: signature) as? Api.messages.Dialogs - } - return result - }) - } - static func getHistory(peer: Api.InputPeer, offsetId: Int32, offsetDate: Int32, addOffset: Int32, limit: Int32, maxId: Int32, minId: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() buffer.appendInt32(-591691168) @@ -2675,11 +2657,11 @@ extension Api { }) } - static func getUnreadDialogs() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.DialogPeer]>) { + static func getDialogUnreadMarks() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.DialogPeer]>) { let buffer = Buffer() - buffer.appendInt32(1530766490) + buffer.appendInt32(585256482) - return (FunctionDescription(name: "messages.getUnreadDialogs", parameters: []), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> [Api.DialogPeer]? in + return (FunctionDescription(name: "messages.getDialogUnreadMarks", parameters: []), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> [Api.DialogPeer]? in let reader = BufferReader(buffer) var result: [Api.DialogPeer]? if let _ = reader.readInt32() { @@ -2688,6 +2670,25 @@ extension Api { return result }) } + + static func getDialogs(flags: Int32, offsetDate: Int32, offsetId: Int32, offsetPeer: Api.InputPeer, limit: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(-1332171034) + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(offsetDate, buffer: buffer, boxed: false) + serializeInt32(offsetId, buffer: buffer, boxed: false) + offsetPeer.serialize(buffer, true) + serializeInt32(limit, buffer: buffer, boxed: false) + serializeInt32(hash, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getDialogs", parameters: [("flags", flags), ("offsetDate", offsetDate), ("offsetId", offsetId), ("offsetPeer", offsetPeer), ("limit", limit), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Dialogs? in + let reader = BufferReader(buffer) + var result: Api.messages.Dialogs? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.messages.Dialogs + } + return result + }) + } } struct channels { static func readHistory(channel: Api.InputChannel, maxId: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { @@ -3891,6 +3892,20 @@ extension Api { return result }) } + + static func getSaved() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.SavedContact]>) { + let buffer = Buffer() + buffer.appendInt32(-2098076769) + + return (FunctionDescription(name: "contacts.getSaved", parameters: []), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> [Api.SavedContact]? in + let reader = BufferReader(buffer) + var result: [Api.SavedContact]? + if let _ = reader.readInt32() { + result = Api.parseVector(reader, elementSignature: 0, elementType: Api.SavedContact.self) + } + return result + }) + } } struct help { static func getConfig() -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { @@ -4903,6 +4918,21 @@ extension Api { return result }) } + + static func initTakeoutSession(flags: Int32, fileMaxSize: Int32?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(-74035733) + serializeInt32(flags, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 5) != 0 {serializeInt32(fileMaxSize!, buffer: buffer, boxed: false)} + return (FunctionDescription(name: "account.initTakeoutSession", parameters: [("flags", flags), ("fileMaxSize", fileMaxSize)]), 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 + }) + } } struct langpack { static func getLangPack(langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { diff --git a/TelegramCore/FetchChatList.swift b/TelegramCore/FetchChatList.swift index ecda683143..5b5242f7a1 100644 --- a/TelegramCore/FetchChatList.swift +++ b/TelegramCore/FetchChatList.swift @@ -36,6 +36,9 @@ private func extractDialogsData(dialogs: Api.messages.Dialogs) -> (apiDialogs: [ return (dialogs, messages, chats, users, true) case let .dialogsSlice(_, dialogs, messages, chats, users): return (dialogs, messages, chats, users, false) + case .dialogsNotModified: + assertionFailure() + return ([], [], [], [], true) } } @@ -220,7 +223,7 @@ func fetchChatList(postbox: Postbox, network: Network, location: FetchChatListLo flags |= 1 << 1*/ break } - let requestChats = network.request(Api.functions.messages.getDialogs(flags: flags/*feed*//*, feedId: requestFeedId*/, offsetDate: timestamp, offsetId: id, offsetPeer: peer, limit: 100)) + let requestChats = network.request(Api.functions.messages.getDialogs(flags: flags/*feed*//*, feedId: requestFeedId*/, offsetDate: timestamp, offsetId: id, offsetPeer: peer, limit: 100, hash: 0)) |> retryRequest return combineLatest(requestChats, additionalPinnedChats) diff --git a/TelegramCore/ManagedGlobalNotificationSettings.swift b/TelegramCore/ManagedGlobalNotificationSettings.swift index 1f44b7eb7f..02b9a7e6b9 100644 --- a/TelegramCore/ManagedGlobalNotificationSettings.swift +++ b/TelegramCore/ManagedGlobalNotificationSettings.swift @@ -165,13 +165,14 @@ private func apiInputPeerNotifySettings(_ settings: MessageNotificationSettings) } let sound: String? = settings.sound.apiSound var flags: Int32 = 0 + flags |= (1 << 0) if muteUntil != nil { flags |= (1 << 2) } if sound != nil { flags |= (1 << 3) } - return .inputPeerNotifySettings(flags: flags, showPreviews: nil, silent: nil, muteUntil: muteUntil, sound: sound) + return .inputPeerNotifySettings(flags: flags, showPreviews: settings.displayPreviews ? .boolTrue : .boolFalse, silent: nil, muteUntil: muteUntil, sound: sound) } private func pushedNotificationSettings(network: Network, settings: GlobalNotificationSettingsSet) -> Signal { diff --git a/TelegramCore/MarkAllChatsAsRead.swift b/TelegramCore/MarkAllChatsAsRead.swift index ee196bba51..c99bfb5405 100644 --- a/TelegramCore/MarkAllChatsAsRead.swift +++ b/TelegramCore/MarkAllChatsAsRead.swift @@ -10,7 +10,7 @@ import MtProtoKitDynamic #endif public func markAllChatsAsRead(postbox: Postbox, network: Network, stateManager: AccountStateManager) -> Signal { - return network.request(Api.functions.messages.getUnreadDialogs()) + return network.request(Api.functions.messages.getDialogUnreadMarks()) |> map(Optional.init) |> `catch` { _ -> Signal<[Api.DialogPeer]?, NoError> in return .single(nil) diff --git a/TelegramCore/RequestChatContextResults.swift b/TelegramCore/RequestChatContextResults.swift index 488bb12524..5701c7d56a 100644 --- a/TelegramCore/RequestChatContextResults.swift +++ b/TelegramCore/RequestChatContextResults.swift @@ -27,7 +27,7 @@ public func requestChatContextResults(account: Account, botId: PeerId, peerId: P } if let (latitude, longitude) = location { flags |= (1 << 0) - geoPoint = Api.InputGeoPoint.inputGeoPoint(lat: longitude, long: latitude) + geoPoint = Api.InputGeoPoint.inputGeoPoint(lat: latitude, long: longitude) } return account.network.request(Api.functions.messages.getInlineBotResults(flags: flags, bot: inputBot, peer: inputPeer, geoPoint: geoPoint, query: query, offset: offset)) |> map { result -> ChatContextResultCollection? in diff --git a/TelegramCore/SaveSecureIdValue.swift b/TelegramCore/SaveSecureIdValue.swift index 6ca1671a8c..aee07d4704 100644 --- a/TelegramCore/SaveSecureIdValue.swift +++ b/TelegramCore/SaveSecureIdValue.swift @@ -299,18 +299,26 @@ public enum GetAllSecureIdValuesError { case generic } -public func getAllSecureIdValues(network: Network, context: SecureIdAccessContext) -> Signal<[SecureIdValueWithContext], GetAllSecureIdValuesError> { +public struct EncryptedAllSecureIdValues { + fileprivate let values: [Api.SecureValue] +} + +public func getAllSecureIdValues(network: Network) -> Signal { return network.request(Api.functions.account.getAllSecureValues()) |> mapError { _ -> GetAllSecureIdValuesError in return .generic } - |> map { result -> [SecureIdValueWithContext] in - var values: [SecureIdValueWithContext] = [] - for value in result { - if let parsedValue = parseSecureValue(context: context, value: value, errors: []) { - values.append(parsedValue.valueWithContext) - } - } - return values + |> map { result in + return EncryptedAllSecureIdValues(values: result) } } + +public func decryptedAllSecureIdValues(context: SecureIdAccessContext, encryptedValues: EncryptedAllSecureIdValues) -> [SecureIdValueWithContext] { + var values: [SecureIdValueWithContext] = [] + for value in encryptedValues.values { + if let parsedValue = parseSecureValue(context: context, value: value, errors: []) { + values.append(parsedValue.valueWithContext) + } + } + return values +} diff --git a/TelegramCore/SecureIdPersonalDetailsValue.swift b/TelegramCore/SecureIdPersonalDetailsValue.swift index e30a7bd222..4c84e51785 100644 --- a/TelegramCore/SecureIdPersonalDetailsValue.swift +++ b/TelegramCore/SecureIdPersonalDetailsValue.swift @@ -71,7 +71,7 @@ extension SecureIdPersonalDetailsValue { dict["birth_date"] = self.birthdate.serialize() dict["gender"] = self.gender.serialize() dict["country_code"] = self.countryCode - dict["residenceCountryCode"] = self.residenceCountryCode + dict["residence_country_code"] = self.residenceCountryCode return (dict, []) } diff --git a/TelegramCore/TwoStepVerification.swift b/TelegramCore/TwoStepVerification.swift index 9cd7590b80..f8cfe39552 100644 --- a/TelegramCore/TwoStepVerification.swift +++ b/TelegramCore/TwoStepVerification.swift @@ -229,7 +229,7 @@ func updateTwoStepVerificationSecureSecret(network: Network, password: String, s } let flags: Int32 = (1 << 2) - return network.request(Api.functions.account.updatePasswordSettings(currentPasswordHash: currentPasswordHash, newSettings: .passwordInputSettings(flags: flags, newSalt: Buffer(data: Data()), newPasswordHash: Buffer(data: Data()), hint: "", email: "", newSecureSalt: nil, newSecureSecret: nil, newSecureSecretId: nil)), automaticFloodWait: true) + return network.request(Api.functions.account.updatePasswordSettings(currentPasswordHash: currentPasswordHash, newSettings: .passwordInputSettings(flags: flags, newSalt: Buffer(data: Data()), newPasswordHash: Buffer(data: Data()), hint: "", email: "", newSecureSalt: Buffer(data: secretSalt), newSecureSecret: Buffer(data: encryptedSecret), newSecureSecretId: secretId)), automaticFloodWait: true) |> mapError { _ -> UpdateTwoStepVerificationSecureSecretError in return .generic }