From 6d34268a0fd7c891b5322de14693ddf89924723c Mon Sep 17 00:00:00 2001 From: Daniil Okhlopkov <5613295+ohld@users.noreply.github.com> Date: Thu, 25 Jun 2026 22:16:44 +0300 Subject: [PATCH 1/2] Render rich bot messages as fallback text --- submodules/TelegramApi/Sources/Api0.swift | 1 + submodules/TelegramApi/Sources/Api15.swift | 38 +- .../Sources/ApiRichMessageFallback.swift | 434 ++++++++++++++++++ .../Sources/State/Serialization.swift | 2 +- 4 files changed, 472 insertions(+), 3 deletions(-) create mode 100644 submodules/TelegramApi/Sources/ApiRichMessageFallback.swift diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index 0bf257604c1..50a963337ac 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -555,6 +555,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1235637404] = { return Api.MediaArea.parse_mediaAreaWeather($0) } dict[-808853502] = { return Api.MediaAreaCoordinates.parse_mediaAreaCoordinates($0) } dict[-1743401272] = { return Api.Message.parse_message($0) } + dict[1979759059] = { return Api.Message.parse_message($0) } dict[-1868117372] = { return Api.Message.parse_messageEmpty($0) } dict[2055212554] = { return Api.Message.parse_messageService($0) } dict[-872240531] = { return Api.MessageAction.parse_messageActionBoostApply($0) } diff --git a/submodules/TelegramApi/Sources/Api15.swift b/submodules/TelegramApi/Sources/Api15.swift index 5c2505e3796..aa6495f12a6 100644 --- a/submodules/TelegramApi/Sources/Api15.swift +++ b/submodules/TelegramApi/Sources/Api15.swift @@ -160,6 +160,8 @@ public extension Api { } } var _5: Int32? if Int(_1!) & Int(1 << 29) != 0 {_5 = reader.readInt32() } + var _5a: String? + if Int(_2!) & Int(1 << 12) != 0 {_5a = parseString(reader) } var _6: Api.Peer? if let signature = reader.readInt32() { _6 = Api.parse(reader, signature: signature) as? Api.Peer @@ -176,6 +178,10 @@ public extension Api { if Int(_1!) & Int(1 << 11) != 0 {_9 = reader.readInt64() } var _10: Int64? if Int(_2!) & Int(1 << 0) != 0 {_10 = reader.readInt64() } + var _10a: Api.Peer? + if Int(_2!) & Int(1 << 19) != 0 {if let signature = reader.readInt32() { + _10a = Api.parse(reader, signature: signature) as? Api.Peer + } } var _11: Api.MessageReplyHeader? if Int(_1!) & Int(1 << 3) != 0 {if let signature = reader.readInt32() { _11 = Api.parse(reader, signature: signature) as? Api.MessageReplyHeader @@ -236,16 +242,26 @@ public extension Api { if Int(_2!) & Int(1 << 7) != 0 {if let signature = reader.readInt32() { _31 = Api.parse(reader, signature: signature) as? Api.SuggestedPost } } + var _31a: Int32? + if Int(_2!) & Int(1 << 10) != 0 {_31a = reader.readInt32() } + var _31b: String? + if Int(_2!) & Int(1 << 11) != 0 {_31b = parseString(reader) } + var _32: String? + if Int(_2!) & Int(1 << 13) != 0 {if let signature = reader.readInt32() { + _32 = parseRichMessageFallbackText(reader: reader, signature: signature) + } } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = _3 != nil let _c4 = (Int(_1!) & Int(1 << 8) == 0) || _4 != nil let _c5 = (Int(_1!) & Int(1 << 29) == 0) || _5 != nil + let _c5a = (Int(_2!) & Int(1 << 12) == 0) || _5a != nil let _c6 = _6 != nil let _c7 = (Int(_1!) & Int(1 << 28) == 0) || _7 != nil let _c8 = (Int(_1!) & Int(1 << 2) == 0) || _8 != nil let _c9 = (Int(_1!) & Int(1 << 11) == 0) || _9 != nil let _c10 = (Int(_2!) & Int(1 << 0) == 0) || _10 != nil + let _c10a = (Int(_2!) & Int(1 << 19) == 0) || _10a != nil let _c11 = (Int(_1!) & Int(1 << 3) == 0) || _11 != nil let _c12 = _12 != nil let _c13 = _13 != nil @@ -267,8 +283,26 @@ public extension Api { let _c29 = (Int(_2!) & Int(1 << 5) == 0) || _29 != nil let _c30 = (Int(_2!) & Int(1 << 6) == 0) || _30 != nil let _c31 = (Int(_2!) & Int(1 << 7) == 0) || _31 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 && _c17 && _c18 && _c19 && _c20 && _c21 && _c22 && _c23 && _c24 && _c25 && _c26 && _c27 && _c28 && _c29 && _c30 && _c31 { - return Api.Message.message(flags: _1!, flags2: _2!, id: _3!, fromId: _4, fromBoostsApplied: _5, peerId: _6!, savedPeerId: _7, fwdFrom: _8, viaBotId: _9, viaBusinessBotId: _10, replyTo: _11, date: _12!, message: _13!, media: _14, replyMarkup: _15, entities: _16, views: _17, forwards: _18, replies: _19, editDate: _20, postAuthor: _21, groupedId: _22, reactions: _23, restrictionReason: _24, ttlPeriod: _25, quickReplyShortcutId: _26, effect: _27, factcheck: _28, reportDeliveryUntilDate: _29, paidMessageStars: _30, suggestedPost: _31) + let _c31a = (Int(_2!) & Int(1 << 10) == 0) || _31a != nil + let _c31b = (Int(_2!) & Int(1 << 11) == 0) || _31b != nil + let _c32 = (Int(_2!) & Int(1 << 13) == 0) || _32 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c5a && _c6 && _c7 && _c8 && _c9 && _c10 && _c10a && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 && _c17 && _c18 && _c19 && _c20 && _c21 && _c22 && _c23 && _c24 && _c25 && _c26 && _c27 && _c28 && _c29 && _c30 && _c31 && _c31a && _c31b && _c32 { + let dropUnsupportedMedia: Swift.Bool + if _32 != nil, case .messageMediaUnsupported? = _14 { + dropUnsupportedMedia = true + } else { + dropUnsupportedMedia = false + } + let messageText: String + if dropUnsupportedMedia, let richFallbackText = _32 { + messageText = mergeRichMessageFallback(message: _13!, fallback: richFallbackText) + } else { + messageText = _13!.isEmpty ? (_32 ?? _13!) : _13! + } + let flags2UnsupportedMask = Int32(1 << 10) | Int32(1 << 11) | Int32(1 << 12) | Int32(1 << 13) | Int32(1 << 19) + let sanitizedFlags = dropUnsupportedMedia ? (_1! & ~Int32(1 << 9)) : _1! + let sanitizedFlags2 = _2! & ~flags2UnsupportedMask + return Api.Message.message(flags: sanitizedFlags, flags2: sanitizedFlags2, id: _3!, fromId: _4, fromBoostsApplied: _5, peerId: _6!, savedPeerId: _7, fwdFrom: _8, viaBotId: _9, viaBusinessBotId: _10, replyTo: _11, date: _12!, message: messageText, media: dropUnsupportedMedia ? nil : _14, replyMarkup: _15, entities: _16, views: _17, forwards: _18, replies: _19, editDate: _20, postAuthor: _21, groupedId: _22, reactions: _23, restrictionReason: _24, ttlPeriod: _25, quickReplyShortcutId: _26, effect: _27, factcheck: _28, reportDeliveryUntilDate: _29, paidMessageStars: _30, suggestedPost: _31) } else { return nil diff --git a/submodules/TelegramApi/Sources/ApiRichMessageFallback.swift b/submodules/TelegramApi/Sources/ApiRichMessageFallback.swift new file mode 100644 index 00000000000..c4fff72fed1 --- /dev/null +++ b/submodules/TelegramApi/Sources/ApiRichMessageFallback.swift @@ -0,0 +1,434 @@ +import Foundation + +private let richMessageConstructor: Int32 = -1158439541 +private let vectorConstructor: Int32 = 481674261 + +func parseRichMessageFallbackText(reader: BufferReader, signature: Int32) -> String? { + guard signature == richMessageConstructor else { + telegramApiLog("Unexpected rich message constructor \(String(UInt32(bitPattern: signature), radix: 16, uppercase: false))") + return nil + } + guard reader.readInt32() != nil else { + return nil + } + guard let blocks = parseRichMessageBlockVectorText(reader: reader) else { + return nil + } + guard consumeApiObjectVector(reader: reader, elementType: Api.Photo.self) else { + return nil + } + guard consumeApiObjectVector(reader: reader, elementType: Api.Document.self) else { + return nil + } + return joinRichMessageLines(blocks) +} + +func mergeRichMessageFallback(message: String, fallback: String) -> String { + let trimmedMessage = message.trimmingCharacters(in: .whitespacesAndNewlines) + let trimmedFallback = fallback.trimmingCharacters(in: .whitespacesAndNewlines) + if trimmedMessage.isEmpty || trimmedFallback.contains(trimmedMessage) { + return fallback + } + if trimmedFallback.isEmpty { + return message + } + return joinRichMessageLines([message, fallback]) +} + +private func consumeApiObjectVector(reader: BufferReader, elementType: T.Type) -> Bool { + guard reader.readInt32() != nil else { + return false + } + return Api.parseVector(reader, elementSignature: 0, elementType: elementType) != nil +} + +private func parseRichMessageBlockVectorText(reader: BufferReader) -> [String]? { + guard reader.readInt32() == vectorConstructor, let count = reader.readInt32() else { + return nil + } + var result: [String] = [] + for _ in 0 ..< count { + guard let signature = reader.readInt32(), let text = parseRichMessageBlockText(reader: reader, signature: signature) else { + return nil + } + if !text.isEmpty { + result.append(text) + } + } + return result +} + +private func parseRichTextVectorText(reader: BufferReader) -> [String]? { + guard reader.readInt32() == vectorConstructor, let count = reader.readInt32() else { + return nil + } + var result: [String] = [] + for _ in 0 ..< count { + guard let signature = reader.readInt32(), let text = parseRichTextFallbackText(reader: reader, signature: signature) else { + return nil + } + result.append(text) + } + return result +} + +private func parseRichTextChild(reader: BufferReader) -> String? { + guard let signature = reader.readInt32() else { + return nil + } + return parseRichTextFallbackText(reader: reader, signature: signature) +} + +private func parseRichTextFallbackText(reader: BufferReader, signature: Int32) -> String? { + switch signature { + case -599948721: + return "" + case 1950782688: + return parseString(reader) + case 2120376535: + return parseRichTextVectorText(reader: reader)?.joined() + case 894777186: + guard let text = parseRichTextChild(reader: reader), parseString(reader) != nil else { + return nil + } + return text + case -564523562, 1009288385: + guard let text = parseRichTextChild(reader: reader), let fallback = parseString(reader) else { + return nil + } + if signature == 1009288385, reader.readInt64() == nil { + return nil + } + return text.isEmpty ? fallback : text + case 27917308: + guard let text = parseRichTextChild(reader: reader), reader.readInt64() != nil else { + return nil + } + return text + case -1514906069: + guard reader.readInt32() != nil, let text = parseRichTextChild(reader: reader), reader.readInt32() != nil else { + return nil + } + return text + case 136105807: + guard reader.readInt64() != nil, reader.readInt32() != nil, reader.readInt32() != nil else { + return nil + } + return "" + case -1570679104: + guard reader.readInt64() != nil, let alt = parseString(reader) else { + return nil + } + return alt + case -1657885545: + guard let source = parseString(reader) else { + return nil + } + return source + case 1730456516, -653089380, -1054465340, -1678197867, 1816074681, 55281185, + -311786236, -939827711, -984177571, 616720265, -1402305622, -1185513171, + 50276819, 2073958401, 1368728810, -853225660, 1277844834: + return parseRichTextChild(reader: reader) + case 483104362: + guard let text = parseRichTextChild(reader: reader), let fallback = parseString(reader) else { + return nil + } + return text.isEmpty ? fallback : text + default: + telegramApiLog("Unsupported rich text constructor \(String(UInt32(bitPattern: signature), radix: 16, uppercase: false))") + return nil + } +} + +private func parsePageCaptionFallbackText(reader: BufferReader) -> String? { + guard reader.readInt32() == 1869903447 else { + return nil + } + guard let text = parseRichTextChild(reader: reader), let credit = parseRichTextChild(reader: reader) else { + return nil + } + return joinRichMessageLines([text, credit]) +} + +private func parsePageListItems(reader: BufferReader, ordered: Bool) -> [String]? { + guard reader.readInt32() == vectorConstructor, let count = reader.readInt32() else { + return nil + } + var result: [String] = [] + for index in 0 ..< count { + guard let signature = reader.readInt32() else { + return nil + } + let text: String? + var orderedLabel: String? + switch signature { + case -1188055347: + text = parseRichTextChild(reader: reader) + case 635466748: + text = parseRichMessageBlockVectorText(reader: reader).map(joinRichMessageLines) + case 794323004: + guard reader.readInt32() != nil else { + return nil + } + text = parseRichTextChild(reader: reader) + case 1674209194: + guard reader.readInt32() != nil else { + return nil + } + text = parseRichMessageBlockVectorText(reader: reader).map(joinRichMessageLines) + case 1577484359: + guard let num = parseString(reader) else { + return nil + } + orderedLabel = num + text = parseRichTextChild(reader: reader) + case -1730311882: + guard let num = parseString(reader) else { + return nil + } + orderedLabel = num + text = parseRichMessageBlockVectorText(reader: reader).map(joinRichMessageLines) + case 352522633: + guard let flags = reader.readInt32() else { + return nil + } + if Int(flags) & Int(1 << 2) != 0 { + guard let num = parseString(reader) else { + return nil + } + orderedLabel = num + } + text = parseRichTextChild(reader: reader) + if Int(flags) & Int(1 << 3) != 0 { + guard let value = reader.readInt32() else { + return nil + } + if orderedLabel == nil { + orderedLabel = "\(value)" + } + } + if Int(flags) & Int(1 << 4) != 0, parseString(reader) == nil { + return nil + } + case -1879910928: + guard let flags = reader.readInt32() else { + return nil + } + if Int(flags) & Int(1 << 2) != 0 { + guard let num = parseString(reader) else { + return nil + } + orderedLabel = num + } + text = parseRichMessageBlockVectorText(reader: reader).map(joinRichMessageLines) + if Int(flags) & Int(1 << 3) != 0 { + guard let value = reader.readInt32() else { + return nil + } + if orderedLabel == nil { + orderedLabel = "\(value)" + } + } + if Int(flags) & Int(1 << 4) != 0, parseString(reader) == nil { + return nil + } + default: + telegramApiLog("Unsupported rich list item constructor \(String(UInt32(bitPattern: signature), radix: 16, uppercase: false))") + return nil + } + guard let itemText = text else { + return nil + } + if !itemText.isEmpty { + let prefix = orderedLabel.flatMap { $0.isEmpty ? nil : $0 } ?? "\(index + 1)." + result.append(ordered ? "\(prefix) \(itemText)" : "- \(itemText)") + } + } + return result +} + +private func parsePageTableRows(reader: BufferReader) -> [[String]]? { + guard reader.readInt32() == vectorConstructor, let rowCount = reader.readInt32() else { + return nil + } + var rows: [[String]] = [] + for _ in 0 ..< rowCount { + guard reader.readInt32() == -524237339 else { + return nil + } + guard reader.readInt32() == vectorConstructor, let cellCount = reader.readInt32() else { + return nil + } + var cells: [String] = [] + for _ in 0 ..< cellCount { + guard reader.readInt32() == 878078826, let flags = reader.readInt32() else { + return nil + } + let text: String + if Int(flags) & Int(1 << 7) != 0 { + guard let cellText = parseRichTextChild(reader: reader) else { + return nil + } + text = cellText + } else { + text = "" + } + if Int(flags) & Int(1 << 1) != 0, reader.readInt32() == nil { + return nil + } + if Int(flags) & Int(1 << 2) != 0, reader.readInt32() == nil { + return nil + } + cells.append(text.replacingOccurrences(of: "\n", with: " ")) + } + rows.append(cells) + } + return rows +} + +private func parseRichMessageBlockText(reader: BufferReader, signature: Int32) -> String? { + switch signature { + case -837994576: + return parseString(reader).map { _ in "" } + case 1890305021, -1879401953, -1076861716, -248793375, 1216809369, 504660880, + -1157691601, 158018284, 1743204781, -1254983893, -608277398, 1747599785: + return parseRichTextChild(reader: reader) + case 1182402406: + return parseRichTextChild(reader: reader) + case -1066346178: + guard let text = parseRichTextChild(reader: reader), parseString(reader) != nil else { + return nil + } + return text + case -618614392: + return "---" + case 641563686, 1329878739: + guard let text = parseRichTextChild(reader: reader), let caption = parseRichTextChild(reader: reader) else { + return nil + } + return joinRichMessageLines([quoteRichMessageText(text), caption]) + case 242108356: + guard let blocks = parseRichMessageBlockVectorText(reader: reader), let caption = parseRichTextChild(reader: reader) else { + return nil + } + return joinRichMessageLines([quoteRichMessageText(joinRichMessageLines(blocks)), caption]) + case 1987480557: + guard reader.readInt32() != nil, let blocks = parseRichMessageBlockVectorText(reader: reader), let title = parseRichTextChild(reader: reader) else { + return nil + } + return joinRichMessageLines([title, joinRichMessageLines(blocks)]) + case -454524911: + return parsePageListItems(reader: reader, ordered: false).map(joinRichMessageLines) + case -1702174239: + return parsePageListItems(reader: reader, ordered: true).map(joinRichMessageLines) + case 534181569: + guard let flags = reader.readInt32(), let items = parsePageListItems(reader: reader, ordered: true) else { + return nil + } + if Int(flags) & Int(1 << 0) != 0, reader.readInt32() == nil { + return nil + } + if Int(flags) & Int(1 << 1) != 0, parseString(reader) == nil { + return nil + } + return joinRichMessageLines(items) + case -1085412734: + guard reader.readInt32() != nil, let title = parseRichTextChild(reader: reader), let rows = parsePageTableRows(reader: reader) else { + return nil + } + let rowText = rows.map { $0.joined(separator: " | ") } + return joinRichMessageLines([title] + rowText) + case 1493699616: + return parseString(reader) + case 1009361890: + return parseRichTextChild(reader: reader) + case 324435594: + return "" + case 972174080: + guard let nestedSignature = reader.readInt32() else { + return nil + } + return parseRichMessageBlockText(reader: reader, signature: nestedSignature) + case 1705048653, 52401552: + guard let blocks = parseRichMessageBlockVectorText(reader: reader), let caption = parsePageCaptionFallbackText(reader: reader) else { + return nil + } + return joinRichMessageLines(blocks + [caption]) + case -2143067670: + guard reader.readInt64() != nil else { + return nil + } + return parsePageCaptionFallbackText(reader: reader) + case 391759200: + guard let flags = reader.readInt32(), reader.readInt64() != nil, let caption = parsePageCaptionFallbackText(reader: reader) else { + return nil + } + if Int(flags) & Int(1 << 0) != 0 { + guard parseString(reader) != nil, reader.readInt64() != nil else { + return nil + } + } + return caption + case 2089805750: + guard reader.readInt32() != nil, reader.readInt64() != nil else { + return nil + } + return parsePageCaptionFallbackText(reader: reader) + case -1162877472: + guard let author = parseRichTextChild(reader: reader), reader.readInt32() != nil else { + return nil + } + return author + case -283684427: + guard let chatSignature = reader.readInt32(), Api.parse(reader, signature: chatSignature) as? Api.Chat != nil else { + return nil + } + return "" + case -1468953147: + guard let flags = reader.readInt32() else { + return nil + } + if Int(flags) & Int(1 << 1) != 0, parseString(reader) == nil { + return nil + } + if Int(flags) & Int(1 << 2) != 0, parseString(reader) == nil { + return nil + } + if Int(flags) & Int(1 << 4) != 0, reader.readInt64() == nil { + return nil + } + if Int(flags) & Int(1 << 5) != 0, (reader.readInt32() == nil || reader.readInt32() == nil) { + return nil + } + return parsePageCaptionFallbackText(reader: reader) + case -229005301: + guard parseString(reader) != nil, reader.readInt64() != nil, reader.readInt64() != nil, let author = parseString(reader), reader.readInt32() != nil, let blocks = parseRichMessageBlockVectorText(reader: reader), let caption = parsePageCaptionFallbackText(reader: reader) else { + return nil + } + return joinRichMessageLines([author, joinRichMessageLines(blocks), caption]) + case 370236054: + guard let title = parseRichTextChild(reader: reader), consumeApiObjectVector(reader: reader, elementType: Api.PageRelatedArticle.self) else { + return nil + } + return title + case -1538310410: + guard let geoSignature = reader.readInt32(), Api.parse(reader, signature: geoSignature) as? Api.GeoPoint != nil, reader.readInt32() != nil, reader.readInt32() != nil, reader.readInt32() != nil else { + return nil + } + return parsePageCaptionFallbackText(reader: reader) + default: + telegramApiLog("Unsupported rich message block constructor \(String(UInt32(bitPattern: signature), radix: 16, uppercase: false))") + return nil + } +} + +private func quoteRichMessageText(_ text: String) -> String { + if text.isEmpty { + return "" + } + return text.split(separator: "\n", omittingEmptySubsequences: false).map { "> \($0)" }.joined(separator: "\n") +} + +private func joinRichMessageLines(_ lines: [String]) -> String { + return lines.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.filter { !$0.isEmpty }.joined(separator: "\n") +} diff --git a/submodules/TelegramCore/Sources/State/Serialization.swift b/submodules/TelegramCore/Sources/State/Serialization.swift index ddd61c801ed..155a72ac3b8 100644 --- a/submodules/TelegramCore/Sources/State/Serialization.swift +++ b/submodules/TelegramCore/Sources/State/Serialization.swift @@ -210,7 +210,7 @@ public class BoxedMessage: NSObject { public class Serialization: NSObject, MTSerialization { public func currentLayer() -> UInt { - return 210 + return 227 } public func parseMessage(_ data: Data!) -> Any! { From c15631ac1067e26c6fdc1efe56826c246ae721a9 Mon Sep 17 00:00:00 2001 From: Daniil Okhlopkov <5613295+ohld@users.noreply.github.com> Date: Fri, 26 Jun 2026 02:31:01 +0300 Subject: [PATCH 2/2] Handle newer Telegram TL constructors --- submodules/TelegramApi/Sources/Api0.swift | 21 +++ submodules/TelegramApi/Sources/Api14.swift | 63 +++++++++ submodules/TelegramApi/Sources/Api16.swift | 51 +++++++ submodules/TelegramApi/Sources/Api17.swift | 8 +- submodules/TelegramApi/Sources/Api20.swift | 132 ++++++++++++++++++ submodules/TelegramApi/Sources/Api24.swift | 35 ++++- submodules/TelegramApi/Sources/Api26.swift | 15 +- submodules/TelegramApi/Sources/Api27.swift | 92 ++++++++++++ submodules/TelegramApi/Sources/Api34.swift | 89 ++++++++++++ submodules/TelegramApi/Sources/Api39.swift | 16 +++ submodules/TelegramApi/Sources/Api4.swift | 43 +++++- submodules/TelegramApi/Sources/Api6.swift | 47 +++++++ .../Sources/State/AccountViewTracker.swift | 47 +++++-- 13 files changed, 640 insertions(+), 19 deletions(-) diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index 50a963337ac..acf759bd630 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -183,6 +183,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-847783593] = { return Api.ChannelMessagesFilter.parse_channelMessagesFilter($0) } dict[-1798033689] = { return Api.ChannelMessagesFilter.parse_channelMessagesFilterEmpty($0) } dict[-885426663] = { return Api.ChannelParticipant.parse_channelParticipant($0) } + dict[466961494] = { return Api.ChannelParticipant.parse_channelParticipantWithRank($0) } dict[885242707] = { return Api.ChannelParticipant.parse_channelParticipantAdmin($0) } dict[1844969806] = { return Api.ChannelParticipant.parse_channelParticipantBanned($0) } dict[803602899] = { return Api.ChannelParticipant.parse_channelParticipantCreator($0) } @@ -197,6 +198,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-566281095] = { return Api.ChannelParticipantsFilter.parse_channelParticipantsRecent($0) } dict[106343499] = { return Api.ChannelParticipantsFilter.parse_channelParticipantsSearch($0) } dict[-26717355] = { return Api.Chat.parse_channel($0) } + dict[473084188] = { return Api.Chat.parse_channel($0) } dict[399807445] = { return Api.Chat.parse_channelForbidden($0) } dict[1103884886] = { return Api.Chat.parse_chat($0) } dict[693512293] = { return Api.Chat.parse_chatEmpty($0) } @@ -205,6 +207,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-219353309] = { return Api.ChatAdminWithInvites.parse_chatAdminWithInvites($0) } dict[-1626209256] = { return Api.ChatBannedRights.parse_chatBannedRights($0) } dict[-529258018] = { return Api.ChatFull.parse_channelFull($0) } + dict[-1605464774] = { return Api.ChatFull.parse_channelFull($0) } dict[640893467] = { return Api.ChatFull.parse_chatFull($0) } dict[1553807106] = { return Api.ChatInvite.parse_chatInvite($0) } dict[1516793212] = { return Api.ChatInvite.parse_chatInviteAlready($0) } @@ -251,6 +254,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1662637586] = { return Api.DocumentAttribute.parse_documentAttributeSticker($0) } dict[1137015880] = { return Api.DocumentAttribute.parse_documentAttributeVideo($0) } dict[-1763006997] = { return Api.DraftMessage.parse_draftMessage($0) } + dict[1627271828] = { return Api.DraftMessage.parse_draftMessageWithRichMessage($0) } dict[453805082] = { return Api.DraftMessage.parse_draftMessageEmpty($0) } dict[-1764723459] = { return Api.EmailVerification.parse_emailVerificationApple($0) } dict[-1842457175] = { return Api.EmailVerification.parse_emailVerificationCode($0) } @@ -524,6 +528,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1560655744] = { return Api.KeyboardButton.parse_keyboardButton($0) } dict[-1344716869] = { return Api.KeyboardButton.parse_keyboardButtonBuy($0) } dict[901503851] = { return Api.KeyboardButton.parse_keyboardButtonCallback($0) } + dict[-433338016] = { return Api.KeyboardButton.parse_keyboardButtonCallbackWithStyle($0) } dict[1976723854] = { return Api.KeyboardButton.parse_keyboardButtonCopy($0) } dict[1358175439] = { return Api.KeyboardButton.parse_keyboardButtonGame($0) } dict[-59151553] = { return Api.KeyboardButton.parse_keyboardButtonRequestGeoLocation($0) } @@ -533,6 +538,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1598009252] = { return Api.KeyboardButton.parse_keyboardButtonSimpleWebView($0) } dict[-1816527947] = { return Api.KeyboardButton.parse_keyboardButtonSwitchInline($0) } dict[629866245] = { return Api.KeyboardButton.parse_keyboardButtonUrl($0) } + dict[-670292500] = { return Api.KeyboardButton.parse_keyboardButtonUrlWithStyle($0) } dict[280464681] = { return Api.KeyboardButton.parse_keyboardButtonUrlAuth($0) } dict[814112961] = { return Api.KeyboardButton.parse_keyboardButtonUserProfile($0) } dict[326529584] = { return Api.KeyboardButton.parse_keyboardButtonWebView($0) } @@ -650,7 +656,9 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-827703647] = { return Api.MessageMedia.parse_messageMediaGiveawayResults($0) } dict[-156940077] = { return Api.MessageMedia.parse_messageMediaInvoice($0) } dict[-1467669359] = { return Api.MessageMedia.parse_messageMediaPaidMedia($0) } + dict[-501814429] = { return Api.MessageMedia.parse_messageMediaPhotoWithVideo($0) } dict[1766936791] = { return Api.MessageMedia.parse_messageMediaPhoto($0) } + dict[2000637542] = { return Api.MessageMedia.parse_messageMediaPollWithAttachedMedia($0) } dict[1272375192] = { return Api.MessageMedia.parse_messageMediaPoll($0) } dict[1758159491] = { return Api.MessageMedia.parse_messageMediaStory($0) } dict[-1974226924] = { return Api.MessageMedia.parse_messageMediaToDo($0) } @@ -665,6 +673,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[171155211] = { return Api.MessageReactions.parse_messageReactions($0) } dict[1269016922] = { return Api.MessageReactor.parse_messageReactor($0) } dict[-2083123262] = { return Api.MessageReplies.parse_messageReplies($0) } + dict[462937446] = { return Api.MessageReplyHeader.parse_messageReplyHeader($0) } dict[1763137035] = { return Api.MessageReplyHeader.parse_messageReplyHeader($0) } dict[240843065] = { return Api.MessageReplyHeader.parse_messageReplyStoryHeader($0) } dict[2030298073] = { return Api.MessageReportOption.parse_messageReportOption($0) } @@ -780,9 +789,13 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-96535659] = { return Api.PhotoSize.parse_photoSizeProgressive($0) } dict[-525288402] = { return Api.PhotoSize.parse_photoStrippedSize($0) } dict[1484026161] = { return Api.Poll.parse_poll($0) } + dict[-1771164225] = { return Api.Poll.parse_pollWithHash($0) } dict[-15277366] = { return Api.PollAnswer.parse_pollAnswer($0) } + dict[1266514026] = { return Api.PollAnswer.parse_pollAnswerWithMedia($0) } dict[997055186] = { return Api.PollAnswerVoters.parse_pollAnswerVoters($0) } + dict[910500618] = { return Api.PollAnswerVoters.parse_pollAnswerVotersWithRecentVoters($0) } dict[2061444128] = { return Api.PollResults.parse_pollResults($0) } + dict[-1166298786] = { return Api.PollResults.parse_pollResultsWithSolutionMedia($0) } dict[1558266229] = { return Api.PopularContact.parse_popularContact($0) } dict[512535275] = { return Api.PostAddress.parse_postAddress($0) } dict[-419066241] = { return Api.PostInteractionCounters.parse_postInteractionCountersMessage($0) } @@ -945,6 +958,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1124938064] = { return Api.SponsoredMessageReportOption.parse_sponsoredMessageReportOption($0) } dict[-963180333] = { return Api.SponsoredPeer.parse_sponsoredPeer($0) } dict[12386139] = { return Api.StarGift.parse_starGift($0) } + dict[825922887] = { return Api.StarGift.parse_starGift($0) } dict[-164136786] = { return Api.StarGift.parse_starGiftUnique($0) } dict[-650279524] = { return Api.StarGiftAttribute.parse_starGiftAttributeBackdrop($0) } dict[970559507] = { return Api.StarGiftAttribute.parse_starGiftAttributeModel($0) } @@ -995,6 +1009,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1898850301] = { return Api.StoriesStealthMode.parse_storiesStealthMode($0) } dict[-1205411504] = { return Api.StoryFwdHeader.parse_storyFwdHeader($0) } dict[2041735716] = { return Api.StoryItem.parse_storyItem($0) } + dict[379894076] = { return Api.StoryItem.parse_storyItem($0) } dict[1374088783] = { return Api.StoryItem.parse_storyItemDeleted($0) } dict[-5388013] = { return Api.StoryItem.parse_storyItemSkipped($0) } dict[1620104917] = { return Api.StoryReaction.parse_storyReaction($0) } @@ -1097,6 +1112,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1448076945] = { return Api.Update.parse_updateLoginToken($0) } dict[-710666460] = { return Api.Update.parse_updateMessageExtendedMedia($0) } dict[1318109142] = { return Api.Update.parse_updateMessageID($0) } + dict[-699641301] = { return Api.Update.parse_updateMessagePollWithPeer($0) } dict[-1398708869] = { return Api.Update.parse_updateMessagePoll($0) } dict[619974263] = { return Api.Update.parse_updateMessagePollVote($0) } dict[506035194] = { return Api.Update.parse_updateMessageReactions($0) } @@ -1135,6 +1151,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-78886548] = { return Api.Update.parse_updateReadFeaturedEmojiStickers($0) } dict[1461528386] = { return Api.Update.parse_updateReadFeaturedStickers($0) } dict[-1667805217] = { return Api.Update.parse_updateReadHistoryInbox($0) } + dict[-1635468135] = { return Api.Update.parse_updateReadHistoryInboxWithTopMessage($0) } dict[791617983] = { return Api.Update.parse_updateReadHistoryOutbox($0) } dict[-131960447] = { return Api.Update.parse_updateReadMessagesContents($0) } dict[2008081266] = { return Api.Update.parse_updateReadMonoForumInbox($0) } @@ -1166,6 +1183,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[88680979] = { return Api.Update.parse_updateUserPhone($0) } dict[-440534818] = { return Api.Update.parse_updateUserStatus($0) } dict[-1071741569] = { return Api.Update.parse_updateUserTyping($0) } + dict[706199388] = { return Api.Update.parse_updateUserTypingWithTopMessage($0) } dict[2139689491] = { return Api.Update.parse_updateWebPage($0) } dict[361936797] = { return Api.Update.parse_updateWebViewResultSent($0) } dict[2027216577] = { return Api.Updates.parse_updateShort($0) } @@ -1179,6 +1197,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1445536993] = { return Api.UrlAuthResult.parse_urlAuthResultDefault($0) } dict[-1831650802] = { return Api.UrlAuthResult.parse_urlAuthResultRequest($0) } dict[34280482] = { return Api.User.parse_user($0) } + dict[829899656] = { return Api.User.parse_user($0) } dict[-742634630] = { return Api.User.parse_userEmpty($0) } dict[702447806] = { return Api.UserFull.parse_userFull($0) } dict[-2100168954] = { return Api.UserProfilePhoto.parse_userProfilePhoto($0) } @@ -1379,8 +1398,10 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[834488621] = { return Api.messages.MessageReactionsList.parse_messageReactionsList($0) } dict[-1228606141] = { return Api.messages.MessageViews.parse_messageViews($0) } dict[-948520370] = { return Api.messages.Messages.parse_channelMessages($0) } + dict[494135274] = { return Api.messages.Messages.parse_messagesWithTopics($0) } dict[-1938715001] = { return Api.messages.Messages.parse_messages($0) } dict[1951620897] = { return Api.messages.Messages.parse_messagesNotModified($0) } + dict[1595959062] = { return Api.messages.Messages.parse_messagesSliceWithTopics($0) } dict[978610270] = { return Api.messages.Messages.parse_messagesSlice($0) } dict[-83926371] = { return Api.messages.MyStickers.parse_myStickers($0) } dict[863093588] = { return Api.messages.PeerDialogs.parse_peerDialogs($0) } diff --git a/submodules/TelegramApi/Sources/Api14.swift b/submodules/TelegramApi/Sources/Api14.swift index b1d5202b08f..f89405af496 100644 --- a/submodules/TelegramApi/Sources/Api14.swift +++ b/submodules/TelegramApi/Sources/Api14.swift @@ -310,6 +310,31 @@ public extension Api { return nil } } + public static func parse_keyboardButtonCallbackWithStyle(_ reader: BufferReader) -> KeyboardButton? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Swift.Bool = true + if let flags = _1, Int(flags) & Int(1 << 10) != 0 { + _2 = consumeKeyboardButtonStyle(reader) + } + var _3: String? + _3 = parseString(reader) + var _4: Buffer? + _4 = parseBytes(reader) + let _c1 = _1 != nil + let _c2 = _1.map { flags in + (Int(flags) & Int(1 << 10) == 0) || _2 + } ?? false + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + let sanitizedFlags = _1! & ~Int32(1 << 10) + return Api.KeyboardButton.keyboardButtonCallback(flags: sanitizedFlags, text: _3!, data: _4!) + } + else { + return nil + } + } public static func parse_keyboardButtonCopy(_ reader: BufferReader) -> KeyboardButton? { var _1: String? _1 = parseString(reader) @@ -448,6 +473,44 @@ public extension Api { return nil } } + public static func parse_keyboardButtonUrlWithStyle(_ reader: BufferReader) -> KeyboardButton? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Swift.Bool = true + if Int(_1!) & Int(1 << 10) != 0 { + _2 = consumeKeyboardButtonStyle(reader) + } + var _3: String? + _3 = parseString(reader) + var _4: String? + _4 = parseString(reader) + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 10) == 0) || _2 + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.KeyboardButton.keyboardButtonUrl(text: _3!, url: _4!) + } + else { + return nil + } + } + private static func consumeKeyboardButtonStyle(_ reader: BufferReader) -> Swift.Bool { + guard let signature = reader.readInt32() else { + return false + } + guard signature == 1339896880 else { + telegramApiLog("KeyboardButtonStyle constructor \(String(UInt32(bitPattern: signature), radix: 16, uppercase: false)) not supported") + return false + } + guard let flags = reader.readInt32() else { + return false + } + if Int(flags) & Int(1 << 3) != 0 { + return reader.readInt64() != nil + } + return true + } public static func parse_keyboardButtonUrlAuth(_ reader: BufferReader) -> KeyboardButton? { var _1: Int32? _1 = reader.readInt32() diff --git a/submodules/TelegramApi/Sources/Api16.swift b/submodules/TelegramApi/Sources/Api16.swift index 8638c17facd..80b08187f46 100644 --- a/submodules/TelegramApi/Sources/Api16.swift +++ b/submodules/TelegramApi/Sources/Api16.swift @@ -1235,6 +1235,31 @@ public extension Api { return nil } } + public static func parse_messageMediaPhotoWithVideo(_ reader: BufferReader) -> MessageMedia? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.Photo? + if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.Photo + } } + var _3: Int32? + if Int(_1!) & Int(1 << 2) != 0 {_3 = reader.readInt32() } + var _4: Api.Document? + if Int(_1!) & Int(1 << 4) != 0 {if let signature = reader.readInt32() { + _4 = Api.parse(reader, signature: signature) as? Api.Document + } } + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil + let _c3 = (Int(_1!) & Int(1 << 2) == 0) || _3 != nil + let _c4 = (Int(_1!) & Int(1 << 4) == 0) || _4 != nil + if _c1 && _c2 && _c3 && _c4 { + let sanitizedFlags = _1! & ~Int32(1 << 4) + return Api.MessageMedia.messageMediaPhoto(flags: sanitizedFlags, photo: _2, ttlSeconds: _3) + } + else { + return nil + } + } public static func parse_messageMediaPoll(_ reader: BufferReader) -> MessageMedia? { var _1: Api.Poll? if let signature = reader.readInt32() { @@ -1253,6 +1278,32 @@ public extension Api { return nil } } + public static func parse_messageMediaPollWithAttachedMedia(_ reader: BufferReader) -> MessageMedia? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.Poll? + if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.Poll + } + var _3: Api.PollResults? + if let signature = reader.readInt32() { + _3 = Api.parse(reader, signature: signature) as? Api.PollResults + } + var _4: Api.MessageMedia? + if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { + _4 = Api.parse(reader, signature: signature) as? Api.MessageMedia + } } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.MessageMedia.messageMediaPoll(poll: _2!, results: _3!) + } + else { + return nil + } + } public static func parse_messageMediaStory(_ reader: BufferReader) -> MessageMedia? { var _1: Int32? _1 = reader.readInt32() diff --git a/submodules/TelegramApi/Sources/Api17.swift b/submodules/TelegramApi/Sources/Api17.swift index abefb9f76c2..a412bc2076f 100644 --- a/submodules/TelegramApi/Sources/Api17.swift +++ b/submodules/TelegramApi/Sources/Api17.swift @@ -450,6 +450,8 @@ public extension Api { if Int(_1!) & Int(1 << 10) != 0 {_9 = reader.readInt32() } var _10: Int32? if Int(_1!) & Int(1 << 11) != 0 {_10 = reader.readInt32() } + var _11: Buffer? + if Int(_1!) & Int(1 << 12) != 0 {_11 = parseBytes(reader) } let _c1 = _1 != nil let _c2 = (Int(_1!) & Int(1 << 4) == 0) || _2 != nil let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil @@ -460,8 +462,10 @@ public extension Api { let _c8 = (Int(_1!) & Int(1 << 7) == 0) || _8 != nil let _c9 = (Int(_1!) & Int(1 << 10) == 0) || _9 != nil let _c10 = (Int(_1!) & Int(1 << 11) == 0) || _10 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 { - return Api.MessageReplyHeader.messageReplyHeader(flags: _1!, replyToMsgId: _2, replyToPeerId: _3, replyFrom: _4, replyMedia: _5, replyToTopId: _6, quoteText: _7, quoteEntities: _8, quoteOffset: _9, todoItemId: _10) + let _c11 = (Int(_1!) & Int(1 << 12) == 0) || _11 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 { + let sanitizedFlags = _1! & ~Int32(1 << 12) + return Api.MessageReplyHeader.messageReplyHeader(flags: sanitizedFlags, replyToMsgId: _2, replyToPeerId: _3, replyFrom: _4, replyMedia: _5, replyToTopId: _6, quoteText: _7, quoteEntities: _8, quoteOffset: _9, todoItemId: _10) } else { return nil diff --git a/submodules/TelegramApi/Sources/Api20.swift b/submodules/TelegramApi/Sources/Api20.swift index 906318b8be3..5bd8e1c190d 100644 --- a/submodules/TelegramApi/Sources/Api20.swift +++ b/submodules/TelegramApi/Sources/Api20.swift @@ -579,6 +579,45 @@ public extension Api { return nil } } + public static func parse_pollWithHash(_ reader: BufferReader) -> Poll? { + var _1: Int64? + _1 = reader.readInt64() + var _2: Int32? + _2 = reader.readInt32() + var _3: Api.TextWithEntities? + if let signature = reader.readInt32() { + _3 = Api.parse(reader, signature: signature) as? Api.TextWithEntities + } + var _4: [Api.PollAnswer]? + if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.PollAnswer.self) + } + var _5: Int32? + if Int(_2!) & Int(1 << 4) != 0 {_5 = reader.readInt32() } + var _6: Int32? + if Int(_2!) & Int(1 << 5) != 0 {_6 = reader.readInt32() } + var _7: [String]? + if Int(_2!) & Int(1 << 12) != 0 {if let _ = reader.readInt32() { + _7 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self) + } } + var _8: Int64? + _8 = reader.readInt64() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = (Int(_2!) & Int(1 << 4) == 0) || _5 != nil + let _c6 = (Int(_2!) & Int(1 << 5) == 0) || _6 != nil + let _c7 = (Int(_2!) & Int(1 << 12) == 0) || _7 != nil + let _c8 = _8 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 { + let normalizedFlags = _2! & ~Int32(1 << 12) + return Api.Poll.poll(id: _1!, flags: normalizedFlags, question: _3!, answers: _4!, closePeriod: _5, closeDate: _6) + } + else { + return nil + } + } } } @@ -621,6 +660,38 @@ public extension Api { return nil } } + public static func parse_pollAnswerWithMedia(_ reader: BufferReader) -> PollAnswer? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.TextWithEntities? + if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.TextWithEntities + } + var _3: Buffer? + _3 = parseBytes(reader) + var _4: Api.MessageMedia? + if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { + _4 = Api.parse(reader, signature: signature) as? Api.MessageMedia + } } + var _5: Api.Peer? + if Int(_1!) & Int(1 << 1) != 0 {if let signature = reader.readInt32() { + _5 = Api.parse(reader, signature: signature) as? Api.Peer + } } + var _6: Int32? + if Int(_1!) & Int(1 << 1) != 0 {_6 = reader.readInt32() } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil + let _c5 = (Int(_1!) & Int(1 << 1) == 0) || _5 != nil + let _c6 = (Int(_1!) & Int(1 << 1) == 0) || _6 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 { + return Api.PollAnswer.pollAnswer(text: _2!, option: _3!) + } + else { + return nil + } + } } } @@ -665,6 +736,29 @@ public extension Api { return nil } } + public static func parse_pollAnswerVotersWithRecentVoters(_ reader: BufferReader) -> PollAnswerVoters? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Buffer? + _2 = parseBytes(reader) + var _3: Int32? + if Int(_1!) & Int(1 << 2) != 0 {_3 = reader.readInt32() } + var _4: [Api.Peer]? + if Int(_1!) & Int(1 << 2) != 0 {if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Peer.self) + } } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = (Int(_1!) & Int(1 << 2) == 0) || _3 != nil + let _c4 = (Int(_1!) & Int(1 << 2) == 0) || _4 != nil + if _c1 && _c2 && _c3 && _c4 { + let normalizedFlags = _1! & ~Int32(1 << 2) + return Api.PollAnswerVoters.pollAnswerVoters(flags: normalizedFlags, option: _2!, voters: _3 ?? 0) + } + else { + return nil + } + } } } @@ -739,6 +833,44 @@ public extension Api { return nil } } + public static func parse_pollResultsWithSolutionMedia(_ reader: BufferReader) -> PollResults? { + var _1: Int32? + _1 = reader.readInt32() + var _2: [Api.PollAnswerVoters]? + if Int(_1!) & Int(1 << 1) != 0 {if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.PollAnswerVoters.self) + } } + var _3: Int32? + if Int(_1!) & Int(1 << 2) != 0 {_3 = reader.readInt32() } + var _4: [Api.Peer]? + if Int(_1!) & Int(1 << 3) != 0 {if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Peer.self) + } } + var _5: String? + if Int(_1!) & Int(1 << 4) != 0 {_5 = parseString(reader) } + var _6: [Api.MessageEntity]? + if Int(_1!) & Int(1 << 4) != 0 {if let _ = reader.readInt32() { + _6 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MessageEntity.self) + } } + var _7: Api.MessageMedia? + if Int(_1!) & Int(1 << 5) != 0 {if let signature = reader.readInt32() { + _7 = Api.parse(reader, signature: signature) as? Api.MessageMedia + } } + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 1) == 0) || _2 != nil + let _c3 = (Int(_1!) & Int(1 << 2) == 0) || _3 != nil + let _c4 = (Int(_1!) & Int(1 << 3) == 0) || _4 != nil + let _c5 = (Int(_1!) & Int(1 << 4) == 0) || _5 != nil + let _c6 = (Int(_1!) & Int(1 << 4) == 0) || _6 != nil + let _c7 = (Int(_1!) & Int(1 << 5) == 0) || _7 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 { + let normalizedFlags = _1! & ~Int32((1 << 5) | (1 << 6) | (1 << 7)) + return Api.PollResults.pollResults(flags: normalizedFlags, results: _2, totalVoters: _3, recentVoters: _4, solution: _5, solutionEntities: _6) + } + else { + return nil + } + } } } diff --git a/submodules/TelegramApi/Sources/Api24.swift b/submodules/TelegramApi/Sources/Api24.swift index 204da6c1772..1b24e942842 100644 --- a/submodules/TelegramApi/Sources/Api24.swift +++ b/submodules/TelegramApi/Sources/Api24.swift @@ -734,6 +734,20 @@ public extension Api { if Int(_1!) & Int(1 << 8) != 0 {_15 = reader.readInt32() } var _16: Int32? if Int(_1!) & Int(1 << 8) != 0 {_16 = reader.readInt32() } + var _17: Int32? + if Int(_1!) & Int(1 << 9) != 0 {_17 = reader.readInt32() } + var _18: String? + if Int(_1!) & Int(1 << 11) != 0 {_18 = parseString(reader) } + var _19: Int32? + if Int(_1!) & Int(1 << 11) != 0 {_19 = reader.readInt32() } + var _20: Int32? + if Int(_1!) & Int(1 << 11) != 0 {_20 = reader.readInt32() } + var _21: Int32? + if Int(_1!) & Int(1 << 12) != 0 {_21 = reader.readInt32() } + var _22: Swift.Bool = true + if Int(_1!) & Int(1 << 13) != 0 { + _22 = consumeStarGiftBackground(reader) + } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = _3 != nil @@ -750,13 +764,30 @@ public extension Api { let _c14 = (Int(_1!) & Int(1 << 6) == 0) || _14 != nil let _c15 = (Int(_1!) & Int(1 << 8) == 0) || _15 != nil let _c16 = (Int(_1!) & Int(1 << 8) == 0) || _16 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 { - return Api.StarGift.starGift(flags: _1!, id: _2!, sticker: _3!, stars: _4!, availabilityRemains: _5, availabilityTotal: _6, availabilityResale: _7, convertStars: _8!, firstSaleDate: _9, lastSaleDate: _10, upgradeStars: _11, resellMinStars: _12, title: _13, releasedBy: _14, perUserTotal: _15, perUserRemains: _16) + let _c17 = (Int(_1!) & Int(1 << 9) == 0) || _17 != nil + let _c18 = (Int(_1!) & Int(1 << 11) == 0) || _18 != nil + let _c19 = (Int(_1!) & Int(1 << 11) == 0) || _19 != nil + let _c20 = (Int(_1!) & Int(1 << 11) == 0) || _20 != nil + let _c21 = (Int(_1!) & Int(1 << 12) == 0) || _21 != nil + let _c22 = (Int(_1!) & Int(1 << 13) == 0) || _22 + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 && _c17 && _c18 && _c19 && _c20 && _c21 && _c22 { + let sanitizedFlags = _1! & ~((Int32(1) << 7) | (Int32(1) << 9) | (Int32(1) << 10) | (Int32(1) << 11) | (Int32(1) << 12) | (Int32(1) << 13)) + return Api.StarGift.starGift(flags: sanitizedFlags, id: _2!, sticker: _3!, stars: _4!, availabilityRemains: _5, availabilityTotal: _6, availabilityResale: _7, convertStars: _8!, firstSaleDate: _9, lastSaleDate: _10, upgradeStars: _11, resellMinStars: _12, title: _13, releasedBy: _14, perUserTotal: _15, perUserRemains: _16) } else { return nil } } + private static func consumeStarGiftBackground(_ reader: BufferReader) -> Swift.Bool { + guard let signature = reader.readInt32() else { + return false + } + guard signature == -1342872680 else { + telegramApiLog("StarGiftBackground constructor \(String(UInt32(bitPattern: signature), radix: 16, uppercase: false)) not supported") + return false + } + return reader.readInt32() != nil && reader.readInt32() != nil && reader.readInt32() != nil + } public static func parse_starGiftUnique(_ reader: BufferReader) -> StarGift? { var _1: Int32? _1 = reader.readInt32() diff --git a/submodules/TelegramApi/Sources/Api26.swift b/submodules/TelegramApi/Sources/Api26.swift index dff9d155749..d7cf1df1465 100644 --- a/submodules/TelegramApi/Sources/Api26.swift +++ b/submodules/TelegramApi/Sources/Api26.swift @@ -484,6 +484,14 @@ public extension Api { if Int(_1!) & Int(1 << 15) != 0 {if let signature = reader.readInt32() { _13 = Api.parse(reader, signature: signature) as? Api.Reaction } } + var _14: [Int32]? + if Int(_1!) & Int(1 << 19) != 0 {if let _ = reader.readInt32() { + _14 = Api.parseVector(reader, elementSignature: -1471112230, elementType: Int32.self) + } } + var _15: Api.Document? + if Int(_1!) & Int(1 << 20) != 0 {if let signature = reader.readInt32() { + _15 = Api.parse(reader, signature: signature) as? Api.Document + } } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = _3 != nil @@ -497,8 +505,11 @@ public extension Api { let _c11 = (Int(_1!) & Int(1 << 2) == 0) || _11 != nil let _c12 = (Int(_1!) & Int(1 << 3) == 0) || _12 != nil let _c13 = (Int(_1!) & Int(1 << 15) == 0) || _13 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 { - return Api.StoryItem.storyItem(flags: _1!, id: _2!, date: _3!, fromId: _4, fwdFrom: _5, expireDate: _6!, caption: _7, entities: _8, media: _9!, mediaAreas: _10, privacy: _11, views: _12, sentReaction: _13) + let _c14 = (Int(_1!) & Int(1 << 19) == 0) || _14 != nil + let _c15 = (Int(_1!) & Int(1 << 20) == 0) || _15 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 { + let sanitizedFlags = _1! & ~((Int32(1) << 19) | (Int32(1) << 20)) + return Api.StoryItem.storyItem(flags: sanitizedFlags, id: _2!, date: _3!, fromId: _4, fwdFrom: _5, expireDate: _6!, caption: _7, entities: _8, media: _9!, mediaAreas: _10, privacy: _11, views: _12, sentReaction: _13) } else { return nil diff --git a/submodules/TelegramApi/Sources/Api27.swift b/submodules/TelegramApi/Sources/Api27.swift index 372c196121c..d2b2736378c 100644 --- a/submodules/TelegramApi/Sources/Api27.swift +++ b/submodules/TelegramApi/Sources/Api27.swift @@ -3227,6 +3227,41 @@ public extension Api { return nil } } + public static func parse_updateMessagePollWithPeer(_ reader: BufferReader) -> Update? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.Peer? + if Int(_1!) & Int(1 << 1) != 0 {if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.Peer + } } + var _3: Int32? + if Int(_1!) & Int(1 << 1) != 0 {_3 = reader.readInt32() } + var _4: Int32? + if Int(_1!) & Int(1 << 2) != 0 {_4 = reader.readInt32() } + var _5: Int64? + _5 = reader.readInt64() + var _6: Api.Poll? + if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { + _6 = Api.parse(reader, signature: signature) as? Api.Poll + } } + var _7: Api.PollResults? + if let signature = reader.readInt32() { + _7 = Api.parse(reader, signature: signature) as? Api.PollResults + } + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 1) == 0) || _2 != nil + let _c3 = (Int(_1!) & Int(1 << 1) == 0) || _3 != nil + let _c4 = (Int(_1!) & Int(1 << 2) == 0) || _4 != nil + let _c5 = _5 != nil + let _c6 = (Int(_1!) & Int(1 << 0) == 0) || _6 != nil + let _c7 = _7 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 { + return Api.Update.updateMessagePoll(flags: _1! & ~Int32(6), pollId: _5!, poll: _6, results: _7!) + } + else { + return nil + } + } public static func parse_updateMessagePollVote(_ reader: BufferReader) -> Update? { var _1: Int64? _1 = reader.readInt64() @@ -3873,6 +3908,41 @@ public extension Api { return nil } } + public static func parse_updateReadHistoryInboxWithTopMessage(_ reader: BufferReader) -> Update? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + if Int(_1!) & Int(1 << 0) != 0 {_2 = reader.readInt32() } + var _3: Api.Peer? + if let signature = reader.readInt32() { + _3 = Api.parse(reader, signature: signature) as? Api.Peer + } + var _4: Int32? + if Int(_1!) & Int(1 << 1) != 0 {_4 = reader.readInt32() } + var _5: Int32? + _5 = reader.readInt32() + var _6: Int32? + _6 = reader.readInt32() + var _7: Int32? + _7 = reader.readInt32() + var _8: Int32? + _8 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil + let _c3 = _3 != nil + let _c4 = (Int(_1!) & Int(1 << 1) == 0) || _4 != nil + let _c5 = _5 != nil + let _c6 = _6 != nil + let _c7 = _7 != nil + let _c8 = _8 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 { + let sanitizedFlags = _1! & ~Int32(1 << 1) + return Api.Update.updateReadHistoryInbox(flags: sanitizedFlags, folderId: _2, peer: _3!, maxId: _5!, stillUnreadCount: _6!, pts: _7!, ptsCount: _8!) + } + else { + return nil + } + } public static func parse_updateReadHistoryOutbox(_ reader: BufferReader) -> Update? { var _1: Api.Peer? if let signature = reader.readInt32() { @@ -4319,6 +4389,28 @@ public extension Api { return nil } } + public static func parse_updateUserTypingWithTopMessage(_ reader: BufferReader) -> Update? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: Int32? + if Int(_1!) & Int(1 << 0) != 0 {_3 = reader.readInt32() } + var _4: Api.SendMessageAction? + if let signature = reader.readInt32() { + _4 = Api.parse(reader, signature: signature) as? Api.SendMessageAction + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.Update.updateUserTyping(userId: _2!, action: _4!) + } + else { + return nil + } + } public static func parse_updateWebPage(_ reader: BufferReader) -> Update? { var _1: Api.WebPage? if let signature = reader.readInt32() { diff --git a/submodules/TelegramApi/Sources/Api34.swift b/submodules/TelegramApi/Sources/Api34.swift index 8104601a667..ba2fff54a23 100644 --- a/submodules/TelegramApi/Sources/Api34.swift +++ b/submodules/TelegramApi/Sources/Api34.swift @@ -1,3 +1,20 @@ +private func consumeSearchPostsFlood(_ reader: BufferReader) -> Bool { + guard let signature = reader.readInt32() else { + return false + } + guard signature == 1040931690 else { + telegramApiLog("Unsupported searchPostsFlood constructor \(String(UInt32(bitPattern: signature), radix: 16, uppercase: false))") + return false + } + guard let flags = reader.readInt32(), reader.readInt32() != nil, reader.readInt32() != nil else { + return false + } + if Int(flags) & Int(1 << 1) != 0, reader.readInt32() == nil { + return false + } + return reader.readInt64() != nil +} + public extension Api.messages { enum ForumTopics: TypeConstructorDescription { case forumTopics(flags: Int32, count: Int32, topics: [Api.ForumTopic], messages: [Api.Message], chats: [Api.Chat], users: [Api.User], pts: Int32) @@ -795,6 +812,34 @@ public extension Api.messages { return nil } } + public static func parse_messagesWithTopics(_ reader: BufferReader) -> Messages? { + var _1: [Api.Message]? + if let _ = reader.readInt32() { + _1 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Message.self) + } + var _2: [Api.ForumTopic]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.ForumTopic.self) + } + var _3: [Api.Chat]? + if let _ = reader.readInt32() { + _3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Chat.self) + } + var _4: [Api.User]? + if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.messages.Messages.messages(messages: _1!, chats: _3!, users: _4!) + } + else { + return nil + } + } public static func parse_messagesNotModified(_ reader: BufferReader) -> Messages? { var _1: Int32? _1 = reader.readInt32() @@ -841,6 +886,50 @@ public extension Api.messages { return nil } } + public static func parse_messagesSliceWithTopics(_ reader: BufferReader) -> Messages? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: Int32? + if Int(_1!) & Int(1 << 0) != 0 {_3 = reader.readInt32() } + var _4: Int32? + if Int(_1!) & Int(1 << 2) != 0 {_4 = reader.readInt32() } + var _5: Bool? + if Int(_1!) & Int(1 << 3) != 0 {_5 = consumeSearchPostsFlood(reader) } + var _6: [Api.Message]? + if let _ = reader.readInt32() { + _6 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Message.self) + } + var _7: [Api.ForumTopic]? + if let _ = reader.readInt32() { + _7 = Api.parseVector(reader, elementSignature: 0, elementType: Api.ForumTopic.self) + } + var _8: [Api.Chat]? + if let _ = reader.readInt32() { + _8 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Chat.self) + } + var _9: [Api.User]? + if let _ = reader.readInt32() { + _9 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil + let _c4 = (Int(_1!) & Int(1 << 2) == 0) || _4 != nil + let _c5 = (Int(_1!) & Int(1 << 3) == 0) || _5 == true + let _c6 = _6 != nil + let _c7 = _7 != nil + let _c8 = _8 != nil + let _c9 = _9 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 { + let sanitizedFlags = _1! & ~Int32(1 << 3) + return Api.messages.Messages.messagesSlice(flags: sanitizedFlags, count: _2!, nextRate: _3, offsetIdOffset: _4, messages: _6!, chats: _8!, users: _9!) + } + else { + return nil + } + } } } diff --git a/submodules/TelegramApi/Sources/Api39.swift b/submodules/TelegramApi/Sources/Api39.swift index 43e04f36f2e..ff80e39c5f8 100644 --- a/submodules/TelegramApi/Sources/Api39.swift +++ b/submodules/TelegramApi/Sources/Api39.swift @@ -6532,6 +6532,22 @@ public extension Api.functions.messages { }) } } +public extension Api.functions.messages { + static func getRichMessage(peer: Api.InputPeer, id: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(1343580623) + peer.serialize(buffer, true) + serializeInt32(id, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getRichMessage", parameters: [("peer", String(describing: peer)), ("id", String(describing: id))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Messages? in + let reader = BufferReader(buffer) + var result: Api.messages.Messages? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.messages.Messages + } + return result + }) + } +} public extension Api.functions.messages { static func getMessagesReactions(peer: Api.InputPeer, id: [Int32]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() diff --git a/submodules/TelegramApi/Sources/Api4.swift b/submodules/TelegramApi/Sources/Api4.swift index 30ed7397d4d..1f3e9793835 100644 --- a/submodules/TelegramApi/Sources/Api4.swift +++ b/submodules/TelegramApi/Sources/Api4.swift @@ -253,6 +253,30 @@ public extension Api { return nil } } + public static func parse_channelParticipantWithRank(_ reader: BufferReader) -> ChannelParticipant? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: Int32? + _3 = reader.readInt32() + var _4: Int32? + if Int(_1!) & Int(1 << 0) != 0 {_4 = reader.readInt32() } + var _5: String? + if Int(_1!) & Int(1 << 2) != 0 {_5 = parseString(reader) } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil + let _c5 = (Int(_1!) & Int(1 << 2) == 0) || _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + let sanitizedFlags = _1! & ~(Int32(1) << 2) + return Api.ChannelParticipant.channelParticipant(flags: sanitizedFlags, userId: _2!, date: _3!, subscriptionUntilDate: _4) + } + else { + return nil + } + } public static func parse_channelParticipantAdmin(_ reader: BufferReader) -> ChannelParticipant? { var _1: Int32? _1 = reader.readInt32() @@ -1184,6 +1208,12 @@ public extension Api { if Int(_2!) & Int(1 << 18) != 0 {_45 = reader.readInt32() } var _46: Int64? if Int(_2!) & Int(1 << 21) != 0 {_46 = reader.readInt64() } + var _47: Swift.Bool = true + if Int(_2!) & Int(1 << 22) != 0 { + _47 = consumeProfileTab(reader) + } + var _48: Int64? + if Int(_2!) & Int(1 << 23) != 0 {_48 = reader.readInt64() } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = _3 != nil @@ -1230,13 +1260,22 @@ public extension Api { let _c44 = (Int(_2!) & Int(1 << 17) == 0) || _44 != nil let _c45 = (Int(_2!) & Int(1 << 18) == 0) || _45 != nil let _c46 = (Int(_2!) & Int(1 << 21) == 0) || _46 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 && _c17 && _c18 && _c19 && _c20 && _c21 && _c22 && _c23 && _c24 && _c25 && _c26 && _c27 && _c28 && _c29 && _c30 && _c31 && _c32 && _c33 && _c34 && _c35 && _c36 && _c37 && _c38 && _c39 && _c40 && _c41 && _c42 && _c43 && _c44 && _c45 && _c46 { - return Api.ChatFull.channelFull(flags: _1!, flags2: _2!, id: _3!, about: _4!, participantsCount: _5, adminsCount: _6, kickedCount: _7, bannedCount: _8, onlineCount: _9, readInboxMaxId: _10!, readOutboxMaxId: _11!, unreadCount: _12!, chatPhoto: _13!, notifySettings: _14!, exportedInvite: _15, botInfo: _16!, migratedFromChatId: _17, migratedFromMaxId: _18, pinnedMsgId: _19, stickerset: _20, availableMinId: _21, folderId: _22, linkedChatId: _23, location: _24, slowmodeSeconds: _25, slowmodeNextSendDate: _26, statsDc: _27, pts: _28!, call: _29, ttlPeriod: _30, pendingSuggestions: _31, groupcallDefaultJoinAs: _32, themeEmoticon: _33, requestsPending: _34, recentRequesters: _35, defaultSendAs: _36, availableReactions: _37, reactionsLimit: _38, stories: _39, wallpaper: _40, boostsApplied: _41, boostsUnrestrict: _42, emojiset: _43, botVerification: _44, stargiftsCount: _45, sendPaidMessagesStars: _46) + let _c47 = (Int(_2!) & Int(1 << 22) == 0) || _47 + let _c48 = (Int(_2!) & Int(1 << 23) == 0) || _48 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 && _c17 && _c18 && _c19 && _c20 && _c21 && _c22 && _c23 && _c24 && _c25 && _c26 && _c27 && _c28 && _c29 && _c30 && _c31 && _c32 && _c33 && _c34 && _c35 && _c36 && _c37 && _c38 && _c39 && _c40 && _c41 && _c42 && _c43 && _c44 && _c45 && _c46 && _c47 && _c48 { + let sanitizedFlags2 = _2! & ~((Int32(1) << 22) | (Int32(1) << 23)) + return Api.ChatFull.channelFull(flags: _1!, flags2: sanitizedFlags2, id: _3!, about: _4!, participantsCount: _5, adminsCount: _6, kickedCount: _7, bannedCount: _8, onlineCount: _9, readInboxMaxId: _10!, readOutboxMaxId: _11!, unreadCount: _12!, chatPhoto: _13!, notifySettings: _14!, exportedInvite: _15, botInfo: _16!, migratedFromChatId: _17, migratedFromMaxId: _18, pinnedMsgId: _19, stickerset: _20, availableMinId: _21, folderId: _22, linkedChatId: _23, location: _24, slowmodeSeconds: _25, slowmodeNextSendDate: _26, statsDc: _27, pts: _28!, call: _29, ttlPeriod: _30, pendingSuggestions: _31, groupcallDefaultJoinAs: _32, themeEmoticon: _33, requestsPending: _34, recentRequesters: _35, defaultSendAs: _36, availableReactions: _37, reactionsLimit: _38, stories: _39, wallpaper: _40, boostsApplied: _41, boostsUnrestrict: _42, emojiset: _43, botVerification: _44, stargiftsCount: _45, sendPaidMessagesStars: _46) } else { return nil } } + private static func consumeProfileTab(_ reader: BufferReader) -> Swift.Bool { + guard reader.readInt32() != nil else { + return false + } + return true + } public static func parse_chatFull(_ reader: BufferReader) -> ChatFull? { var _1: Int32? _1 = reader.readInt32() diff --git a/submodules/TelegramApi/Sources/Api6.swift b/submodules/TelegramApi/Sources/Api6.swift index c149e4cc891..c2597a3103e 100644 --- a/submodules/TelegramApi/Sources/Api6.swift +++ b/submodules/TelegramApi/Sources/Api6.swift @@ -311,6 +311,53 @@ public extension Api { return nil } } + public static func parse_draftMessageWithRichMessage(_ reader: BufferReader) -> DraftMessage? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.InputReplyTo? + if Int(_1!) & Int(1 << 4) != 0 {if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.InputReplyTo + } } + var _3: String? + _3 = parseString(reader) + var _4: [Api.MessageEntity]? + if Int(_1!) & Int(1 << 3) != 0 {if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MessageEntity.self) + } } + var _5: Api.InputMedia? + if Int(_1!) & Int(1 << 5) != 0 {if let signature = reader.readInt32() { + _5 = Api.parse(reader, signature: signature) as? Api.InputMedia + } } + var _6: Int32? + _6 = reader.readInt32() + var _7: Int64? + if Int(_1!) & Int(1 << 7) != 0 {_7 = reader.readInt64() } + var _8: Api.SuggestedPost? + if Int(_1!) & Int(1 << 8) != 0 {if let signature = reader.readInt32() { + _8 = Api.parse(reader, signature: signature) as? Api.SuggestedPost + } } + var _9: String? + if Int(_1!) & Int(1 << 9) != 0 {if let signature = reader.readInt32() { + _9 = parseRichMessageFallbackText(reader: reader, signature: signature) + } } + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 4) == 0) || _2 != nil + let _c3 = _3 != nil + let _c4 = (Int(_1!) & Int(1 << 3) == 0) || _4 != nil + let _c5 = (Int(_1!) & Int(1 << 5) == 0) || _5 != nil + let _c6 = _6 != nil + let _c7 = (Int(_1!) & Int(1 << 7) == 0) || _7 != nil + let _c8 = (Int(_1!) & Int(1 << 8) == 0) || _8 != nil + let _c9 = (Int(_1!) & Int(1 << 9) == 0) || _9 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 { + let sanitizedFlags = _1! & ~Int32(1 << 9) + let messageText = _9.map { mergeRichMessageFallback(message: _3!, fallback: $0) } ?? _3! + return Api.DraftMessage.draftMessage(flags: sanitizedFlags, replyTo: _2, message: messageText, entities: _4, media: _5, date: _6!, effect: _7, suggestedPost: _8) + } + else { + return nil + } + } public static func parse_draftMessageEmpty(_ reader: BufferReader) -> DraftMessage? { var _1: Int32? _1 = reader.readInt32() diff --git a/submodules/TelegramCore/Sources/State/AccountViewTracker.swift b/submodules/TelegramCore/Sources/State/AccountViewTracker.swift index 3f55897d543..b554aebfa2e 100644 --- a/submodules/TelegramCore/Sources/State/AccountViewTracker.swift +++ b/submodules/TelegramCore/Sources/State/AccountViewTracker.swift @@ -1060,22 +1060,35 @@ public final class AccountViewTracker { guard let peer = peer else { return .complete() } - var fetchSignal: Signal? + var fetchSignal: Signal<[Api.messages.Messages], MTRpcError>? if let messageId = messageIds.first, messageId.namespace == Namespaces.Message.ScheduledCloud { if let inputPeer = apiInputPeer(peer) { fetchSignal = account.network.request(Api.functions.messages.getScheduledMessages(peer: inputPeer, id: messageIds.map { $0.id })) + |> map { [$0] } } } else if let messageId = messageIds.first, messageId.namespace == Namespaces.Message.QuickReplyCloud { if let threadId = peerIdAndThreadId.threadId { fetchSignal = account.network.request(Api.functions.messages.getQuickReplyMessages(flags: 1 << 0, shortcutId: Int32(clamping: threadId), id: messageIds.map { $0.id }, hash: 0)) + |> map { [$0] } } else { fetchSignal = .never() } - } else if peerIdAndThreadId.peerId.namespace == Namespaces.Peer.CloudUser || peerIdAndThreadId.peerId.namespace == Namespaces.Peer.CloudGroup { - fetchSignal = account.network.request(Api.functions.messages.getMessages(id: messageIds.map { Api.InputMessage.inputMessageID(id: $0.id) })) - } else if peerIdAndThreadId.peerId.namespace == Namespaces.Peer.CloudChannel { - if let inputChannel = apiInputChannel(peer) { - fetchSignal = account.network.request(Api.functions.channels.getMessages(channel: inputChannel, id: messageIds.map { Api.InputMessage.inputMessageID(id: $0.id) })) + } else if let inputPeer = apiInputPeer(peer), peerIdAndThreadId.peerId.namespace == Namespaces.Peer.CloudUser || peerIdAndThreadId.peerId.namespace == Namespaces.Peer.CloudGroup || peerIdAndThreadId.peerId.namespace == Namespaces.Peer.CloudChannel { + var requests: [Signal] = [] + for messageId in messageIds { + let fallback: Signal + if peerIdAndThreadId.peerId.namespace == Namespaces.Peer.CloudChannel, let inputChannel = apiInputChannel(peer) { + fallback = account.network.request(Api.functions.channels.getMessages(channel: inputChannel, id: [Api.InputMessage.inputMessageID(id: messageId.id)])) + } else { + fallback = account.network.request(Api.functions.messages.getMessages(id: [Api.InputMessage.inputMessageID(id: messageId.id)])) + } + requests.append(account.network.request(Api.functions.messages.getRichMessage(peer: inputPeer, id: messageId.id)) + |> `catch` { _ -> Signal in + return fallback + }) + } + if !requests.isEmpty { + fetchSignal = combineLatest(requests) } } guard let signal = fetchSignal else { @@ -1083,17 +1096,29 @@ public final class AccountViewTracker { } return signal - |> map { result -> (Peer, [Api.Message], [Api.Chat], [Api.User]) in + |> map { results -> (Peer, [Api.Message], [Api.Chat], [Api.User]) in + var mergedMessages: [Api.Message] = [] + var mergedChats: [Api.Chat] = [] + var mergedUsers: [Api.User] = [] + for result in results { switch result { case let .messages(messages, chats, users): - return (peer, messages, chats, users) + mergedMessages.append(contentsOf: messages) + mergedChats.append(contentsOf: chats) + mergedUsers.append(contentsOf: users) case let .messagesSlice(_, _, _, _, messages, chats, users): - return (peer, messages, chats, users) + mergedMessages.append(contentsOf: messages) + mergedChats.append(contentsOf: chats) + mergedUsers.append(contentsOf: users) case let .channelMessages(_, _, _, _, messages, _, chats, users): - return (peer, messages, chats, users) + mergedMessages.append(contentsOf: messages) + mergedChats.append(contentsOf: chats) + mergedUsers.append(contentsOf: users) case .messagesNotModified: - return (peer, [], [], []) + break + } } + return (peer, mergedMessages, mergedChats, mergedUsers) } |> `catch` { _ in return Signal<(Peer, [Api.Message], [Api.Chat], [Api.User]), NoError>.single((peer, [], [], []))