From 4291cd627912655a0c160b921f49ee1c195e40fc Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 17 Mar 2025 21:10:07 +0400 Subject: [PATCH] Update API --- .../Sources/BundleIconComponent.swift | 15 +- submodules/TelegramApi/Sources/Api0.swift | 7 + submodules/TelegramApi/Sources/Api24.swift | 106 +++++----- submodules/TelegramApi/Sources/Api25.swift | 52 +++++ submodules/TelegramApi/Sources/Api30.swift | 160 +++++++-------- submodules/TelegramApi/Sources/Api31.swift | 144 +++++++------ submodules/TelegramApi/Sources/Api32.swift | 142 ++++++------- submodules/TelegramApi/Sources/Api33.swift | 142 +++++++------ submodules/TelegramApi/Sources/Api34.swift | 100 +++++---- submodules/TelegramApi/Sources/Api35.swift | 192 ++++-------------- submodules/TelegramApi/Sources/Api36.swift | 150 ++++++++++++++ submodules/TelegramApi/Sources/Api38.swift | 36 ++-- .../TelegramEngine/Messages/AdMessages.swift | 44 ++-- .../TelegramEngine/Messages/BotWebView.swift | 2 +- .../Messages/QuickReplyMessages.swift | 150 +++++++++++++- .../TelegramEngine/Messages/ReportAds.swift | 45 ++-- .../TelegramEngine/Peers/AdPeers.swift | 75 +++++++ .../Peers/TelegramEnginePeers.swift | 4 + .../Peers/UpdateCachedPeerData.swift | 4 +- .../Sources/ListActionItemComponent.swift | 12 +- .../Sources/MessageInputPanelComponent.swift | 2 + .../Sources/ChatbotSetupScreen.swift | 192 +++++++++++++++--- 22 files changed, 1138 insertions(+), 638 deletions(-) create mode 100644 submodules/TelegramCore/Sources/TelegramEngine/Peers/AdPeers.swift diff --git a/submodules/Components/BundleIconComponent/Sources/BundleIconComponent.swift b/submodules/Components/BundleIconComponent/Sources/BundleIconComponent.swift index 6ad895ce4f..c48f851ca9 100644 --- a/submodules/Components/BundleIconComponent/Sources/BundleIconComponent.swift +++ b/submodules/Components/BundleIconComponent/Sources/BundleIconComponent.swift @@ -11,14 +11,16 @@ public final class BundleIconComponent: Component { public let scaleFactor: CGFloat public let shadowColor: UIColor? public let shadowBlur: CGFloat + public let flipVertically: Bool - public init(name: String, tintColor: UIColor?, maxSize: CGSize? = nil, scaleFactor: CGFloat = 1.0, shadowColor: UIColor? = nil, shadowBlur: CGFloat = 0.0) { + public init(name: String, tintColor: UIColor?, maxSize: CGSize? = nil, scaleFactor: CGFloat = 1.0, shadowColor: UIColor? = nil, shadowBlur: CGFloat = 0.0, flipVertically: Bool = false) { self.name = name self.tintColor = tintColor self.maxSize = maxSize self.scaleFactor = scaleFactor self.shadowColor = shadowColor self.shadowBlur = shadowBlur + self.flipVertically = flipVertically } public static func ==(lhs: BundleIconComponent, rhs: BundleIconComponent) -> Bool { @@ -40,6 +42,9 @@ public final class BundleIconComponent: Component { if lhs.shadowBlur != rhs.shadowBlur { return false } + if lhs.flipVertically != rhs.flipVertically { + return false + } return true } @@ -55,7 +60,7 @@ public final class BundleIconComponent: Component { } func update(component: BundleIconComponent, availableSize: CGSize, transition: ComponentTransition) -> CGSize { - if self.component?.name != component.name || self.component?.tintColor != component.tintColor || self.component?.shadowColor != component.shadowColor || self.component?.shadowBlur != component.shadowBlur { + if self.component?.name != component.name || self.component?.tintColor != component.tintColor || self.component?.shadowColor != component.shadowColor || self.component?.shadowBlur != component.shadowBlur || self.component?.flipVertically != component.flipVertically { var image: UIImage? if let tintColor = component.tintColor { image = generateTintedImage(image: UIImage(bundleImageName: component.name), color: tintColor, backgroundColor: nil) @@ -72,7 +77,11 @@ public final class BundleIconComponent: Component { } }) } - self.image = image + if component.flipVertically, let cgImage = image?.cgImage { + self.image = UIImage(cgImage: cgImage, scale: image?.scale ?? 0.0, orientation: .down) + } else { + self.image = image + } } self.component = component diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index d8542385a3..6a20e73065 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -926,6 +926,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-425595208] = { return Api.SmsJob.parse_smsJob($0) } dict[1301522832] = { return Api.SponsoredMessage.parse_sponsoredMessage($0) } dict[1124938064] = { return Api.SponsoredMessageReportOption.parse_sponsoredMessageReportOption($0) } + dict[-963180333] = { return Api.SponsoredPeer.parse_sponsoredPeer($0) } dict[46953416] = { return Api.StarGift.parse_starGift($0) } dict[1549979985] = { return Api.StarGift.parse_starGiftUnique($0) } dict[-1809377438] = { return Api.StarGiftAttribute.parse_starGiftAttributeBackdrop($0) } @@ -1260,6 +1261,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1290580579] = { return Api.contacts.Found.parse_found($0) } dict[2010127419] = { return Api.contacts.ImportedContacts.parse_importedContacts($0) } dict[2131196633] = { return Api.contacts.ResolvedPeer.parse_resolvedPeer($0) } + dict[-352114556] = { return Api.contacts.SponsoredPeers.parse_sponsoredPeers($0) } + dict[-365775695] = { return Api.contacts.SponsoredPeers.parse_sponsoredPeersEmpty($0) } dict[1891070632] = { return Api.contacts.TopPeers.parse_topPeers($0) } dict[-1255369827] = { return Api.contacts.TopPeers.parse_topPeersDisabled($0) } dict[-567906571] = { return Api.contacts.TopPeers.parse_topPeersNotModified($0) } @@ -2102,6 +2105,8 @@ public extension Api { _1.serialize(buffer, boxed) case let _1 as Api.SponsoredMessageReportOption: _1.serialize(buffer, boxed) + case let _1 as Api.SponsoredPeer: + _1.serialize(buffer, boxed) case let _1 as Api.StarGift: _1.serialize(buffer, boxed) case let _1 as Api.StarGiftAttribute: @@ -2312,6 +2317,8 @@ public extension Api { _1.serialize(buffer, boxed) case let _1 as Api.contacts.ResolvedPeer: _1.serialize(buffer, boxed) + case let _1 as Api.contacts.SponsoredPeers: + _1.serialize(buffer, boxed) case let _1 as Api.contacts.TopPeers: _1.serialize(buffer, boxed) case let _1 as Api.fragment.CollectibleInfo: diff --git a/submodules/TelegramApi/Sources/Api24.swift b/submodules/TelegramApi/Sources/Api24.swift index d272074c77..fcaefc6eca 100644 --- a/submodules/TelegramApi/Sources/Api24.swift +++ b/submodules/TelegramApi/Sources/Api24.swift @@ -572,6 +572,60 @@ public extension Api { } } +public extension Api { + enum SponsoredPeer: TypeConstructorDescription { + case sponsoredPeer(flags: Int32, randomId: Buffer, peer: Api.Peer, sponsorInfo: String?, additionalInfo: String?) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .sponsoredPeer(let flags, let randomId, let peer, let sponsorInfo, let additionalInfo): + if boxed { + buffer.appendInt32(-963180333) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeBytes(randomId, buffer: buffer, boxed: false) + peer.serialize(buffer, true) + if Int(flags) & Int(1 << 0) != 0 {serializeString(sponsorInfo!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 1) != 0 {serializeString(additionalInfo!, buffer: buffer, boxed: false)} + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .sponsoredPeer(let flags, let randomId, let peer, let sponsorInfo, let additionalInfo): + return ("sponsoredPeer", [("flags", flags as Any), ("randomId", randomId as Any), ("peer", peer as Any), ("sponsorInfo", sponsorInfo as Any), ("additionalInfo", additionalInfo as Any)]) + } + } + + public static func parse_sponsoredPeer(_ reader: BufferReader) -> SponsoredPeer? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Buffer? + _2 = parseBytes(reader) + var _3: Api.Peer? + if let signature = reader.readInt32() { + _3 = Api.parse(reader, signature: signature) as? Api.Peer + } + var _4: String? + if Int(_1!) & Int(1 << 0) != 0 {_4 = parseString(reader) } + var _5: String? + if Int(_1!) & Int(1 << 1) != 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 << 1) == 0) || _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return Api.SponsoredPeer.sponsoredPeer(flags: _1!, randomId: _2!, peer: _3!, sponsorInfo: _4, additionalInfo: _5) + } + else { + return nil + } + } + + } +} public extension Api { enum StarGift: TypeConstructorDescription { case starGift(flags: Int32, id: Int64, sticker: Api.Document, stars: Int64, availabilityRemains: Int32?, availabilityTotal: Int32?, convertStars: Int64, firstSaleDate: Int32?, lastSaleDate: Int32?, upgradeStars: Int64?) @@ -974,55 +1028,3 @@ public extension Api { } } -public extension Api { - enum StarsGiftOption: TypeConstructorDescription { - case starsGiftOption(flags: Int32, stars: Int64, storeProduct: String?, currency: String, amount: Int64) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .starsGiftOption(let flags, let stars, let storeProduct, let currency, let amount): - if boxed { - buffer.appendInt32(1577421297) - } - serializeInt32(flags, buffer: buffer, boxed: false) - serializeInt64(stars, buffer: buffer, boxed: false) - if Int(flags) & Int(1 << 0) != 0 {serializeString(storeProduct!, buffer: buffer, boxed: false)} - serializeString(currency, buffer: buffer, boxed: false) - serializeInt64(amount, buffer: buffer, boxed: false) - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .starsGiftOption(let flags, let stars, let storeProduct, let currency, let amount): - return ("starsGiftOption", [("flags", flags as Any), ("stars", stars as Any), ("storeProduct", storeProduct as Any), ("currency", currency as Any), ("amount", amount as Any)]) - } - } - - public static func parse_starsGiftOption(_ reader: BufferReader) -> StarsGiftOption? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Int64? - _2 = reader.readInt64() - var _3: String? - if Int(_1!) & Int(1 << 0) != 0 {_3 = parseString(reader) } - var _4: String? - _4 = parseString(reader) - var _5: Int64? - _5 = reader.readInt64() - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil - let _c4 = _4 != nil - let _c5 = _5 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 { - return Api.StarsGiftOption.starsGiftOption(flags: _1!, stars: _2!, storeProduct: _3, currency: _4!, amount: _5!) - } - else { - return nil - } - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api25.swift b/submodules/TelegramApi/Sources/Api25.swift index 41895ccb45..5a4cffd9d3 100644 --- a/submodules/TelegramApi/Sources/Api25.swift +++ b/submodules/TelegramApi/Sources/Api25.swift @@ -1,3 +1,55 @@ +public extension Api { + enum StarsGiftOption: TypeConstructorDescription { + case starsGiftOption(flags: Int32, stars: Int64, storeProduct: String?, currency: String, amount: Int64) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .starsGiftOption(let flags, let stars, let storeProduct, let currency, let amount): + if boxed { + buffer.appendInt32(1577421297) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt64(stars, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {serializeString(storeProduct!, buffer: buffer, boxed: false)} + serializeString(currency, buffer: buffer, boxed: false) + serializeInt64(amount, buffer: buffer, boxed: false) + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .starsGiftOption(let flags, let stars, let storeProduct, let currency, let amount): + return ("starsGiftOption", [("flags", flags as Any), ("stars", stars as Any), ("storeProduct", storeProduct as Any), ("currency", currency as Any), ("amount", amount as Any)]) + } + } + + public static func parse_starsGiftOption(_ reader: BufferReader) -> StarsGiftOption? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: String? + if Int(_1!) & Int(1 << 0) != 0 {_3 = parseString(reader) } + var _4: String? + _4 = parseString(reader) + var _5: Int64? + _5 = reader.readInt64() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return Api.StarsGiftOption.starsGiftOption(flags: _1!, stars: _2!, storeProduct: _3, currency: _4!, amount: _5!) + } + else { + return nil + } + } + + } +} public extension Api { enum StarsGiveawayOption: TypeConstructorDescription { case starsGiveawayOption(flags: Int32, stars: Int64, yearlyBoosts: Int32, storeProduct: String?, currency: String, amount: Int64, winners: [Api.StarsGiveawayWinnersOption]) diff --git a/submodules/TelegramApi/Sources/Api30.swift b/submodules/TelegramApi/Sources/Api30.swift index 8fff493cf4..b35e39041e 100644 --- a/submodules/TelegramApi/Sources/Api30.swift +++ b/submodules/TelegramApi/Sources/Api30.swift @@ -1212,6 +1212,80 @@ public extension Api.contacts { } } +public extension Api.contacts { + enum SponsoredPeers: TypeConstructorDescription { + case sponsoredPeers(peers: [Api.SponsoredPeer], chats: [Api.Chat], users: [Api.User]) + case sponsoredPeersEmpty + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .sponsoredPeers(let peers, let chats, let users): + if boxed { + buffer.appendInt32(-352114556) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(peers.count)) + for item in peers { + item.serialize(buffer, true) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(chats.count)) + for item in chats { + item.serialize(buffer, true) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(users.count)) + for item in users { + item.serialize(buffer, true) + } + break + case .sponsoredPeersEmpty: + if boxed { + buffer.appendInt32(-365775695) + } + + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .sponsoredPeers(let peers, let chats, let users): + return ("sponsoredPeers", [("peers", peers as Any), ("chats", chats as Any), ("users", users as Any)]) + case .sponsoredPeersEmpty: + return ("sponsoredPeersEmpty", []) + } + } + + public static func parse_sponsoredPeers(_ reader: BufferReader) -> SponsoredPeers? { + var _1: [Api.SponsoredPeer]? + if let _ = reader.readInt32() { + _1 = Api.parseVector(reader, elementSignature: 0, elementType: Api.SponsoredPeer.self) + } + var _2: [Api.Chat]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Chat.self) + } + var _3: [Api.User]? + if let _ = reader.readInt32() { + _3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + if _c1 && _c2 && _c3 { + return Api.contacts.SponsoredPeers.sponsoredPeers(peers: _1!, chats: _2!, users: _3!) + } + else { + return nil + } + } + public static func parse_sponsoredPeersEmpty(_ reader: BufferReader) -> SponsoredPeers? { + return Api.contacts.SponsoredPeers.sponsoredPeersEmpty + } + + } +} public extension Api.contacts { enum TopPeers: TypeConstructorDescription { case topPeers(categories: [Api.TopPeerCategoryPeers], chats: [Api.Chat], users: [Api.User]) @@ -1408,89 +1482,3 @@ public extension Api.help { } } -public extension Api.help { - enum AppUpdate: TypeConstructorDescription { - case appUpdate(flags: Int32, id: Int32, version: String, text: String, entities: [Api.MessageEntity], document: Api.Document?, url: String?, sticker: Api.Document?) - case noAppUpdate - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .appUpdate(let flags, let id, let version, let text, let entities, let document, let url, let sticker): - if boxed { - buffer.appendInt32(-860107216) - } - serializeInt32(flags, buffer: buffer, boxed: false) - serializeInt32(id, buffer: buffer, boxed: false) - serializeString(version, buffer: buffer, boxed: false) - serializeString(text, buffer: buffer, boxed: false) - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(entities.count)) - for item in entities { - item.serialize(buffer, true) - } - if Int(flags) & Int(1 << 1) != 0 {document!.serialize(buffer, true)} - if Int(flags) & Int(1 << 2) != 0 {serializeString(url!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 3) != 0 {sticker!.serialize(buffer, true)} - break - case .noAppUpdate: - if boxed { - buffer.appendInt32(-1000708810) - } - - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .appUpdate(let flags, let id, let version, let text, let entities, let document, let url, let sticker): - return ("appUpdate", [("flags", flags as Any), ("id", id as Any), ("version", version as Any), ("text", text as Any), ("entities", entities as Any), ("document", document as Any), ("url", url as Any), ("sticker", sticker as Any)]) - case .noAppUpdate: - return ("noAppUpdate", []) - } - } - - public static func parse_appUpdate(_ reader: BufferReader) -> AppUpdate? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Int32? - _2 = reader.readInt32() - var _3: String? - _3 = parseString(reader) - var _4: String? - _4 = parseString(reader) - var _5: [Api.MessageEntity]? - if let _ = reader.readInt32() { - _5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MessageEntity.self) - } - var _6: Api.Document? - if Int(_1!) & Int(1 << 1) != 0 {if let signature = reader.readInt32() { - _6 = Api.parse(reader, signature: signature) as? Api.Document - } } - var _7: String? - if Int(_1!) & Int(1 << 2) != 0 {_7 = parseString(reader) } - var _8: Api.Document? - if Int(_1!) & Int(1 << 3) != 0 {if let signature = reader.readInt32() { - _8 = Api.parse(reader, signature: signature) as? Api.Document - } } - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = _3 != nil - let _c4 = _4 != nil - let _c5 = _5 != nil - let _c6 = (Int(_1!) & Int(1 << 1) == 0) || _6 != nil - let _c7 = (Int(_1!) & Int(1 << 2) == 0) || _7 != nil - let _c8 = (Int(_1!) & Int(1 << 3) == 0) || _8 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 { - return Api.help.AppUpdate.appUpdate(flags: _1!, id: _2!, version: _3!, text: _4!, entities: _5!, document: _6, url: _7, sticker: _8) - } - else { - return nil - } - } - public static func parse_noAppUpdate(_ reader: BufferReader) -> AppUpdate? { - return Api.help.AppUpdate.noAppUpdate - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api31.swift b/submodules/TelegramApi/Sources/Api31.swift index 4cb01769af..8f0b7e1295 100644 --- a/submodules/TelegramApi/Sources/Api31.swift +++ b/submodules/TelegramApi/Sources/Api31.swift @@ -1,3 +1,89 @@ +public extension Api.help { + enum AppUpdate: TypeConstructorDescription { + case appUpdate(flags: Int32, id: Int32, version: String, text: String, entities: [Api.MessageEntity], document: Api.Document?, url: String?, sticker: Api.Document?) + case noAppUpdate + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .appUpdate(let flags, let id, let version, let text, let entities, let document, let url, let sticker): + if boxed { + buffer.appendInt32(-860107216) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(id, buffer: buffer, boxed: false) + serializeString(version, buffer: buffer, boxed: false) + serializeString(text, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(entities.count)) + for item in entities { + item.serialize(buffer, true) + } + if Int(flags) & Int(1 << 1) != 0 {document!.serialize(buffer, true)} + if Int(flags) & Int(1 << 2) != 0 {serializeString(url!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 3) != 0 {sticker!.serialize(buffer, true)} + break + case .noAppUpdate: + if boxed { + buffer.appendInt32(-1000708810) + } + + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .appUpdate(let flags, let id, let version, let text, let entities, let document, let url, let sticker): + return ("appUpdate", [("flags", flags as Any), ("id", id as Any), ("version", version as Any), ("text", text as Any), ("entities", entities as Any), ("document", document as Any), ("url", url as Any), ("sticker", sticker as Any)]) + case .noAppUpdate: + return ("noAppUpdate", []) + } + } + + public static func parse_appUpdate(_ reader: BufferReader) -> AppUpdate? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: String? + _3 = parseString(reader) + var _4: String? + _4 = parseString(reader) + var _5: [Api.MessageEntity]? + if let _ = reader.readInt32() { + _5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MessageEntity.self) + } + var _6: Api.Document? + if Int(_1!) & Int(1 << 1) != 0 {if let signature = reader.readInt32() { + _6 = Api.parse(reader, signature: signature) as? Api.Document + } } + var _7: String? + if Int(_1!) & Int(1 << 2) != 0 {_7 = parseString(reader) } + var _8: Api.Document? + if Int(_1!) & Int(1 << 3) != 0 {if let signature = reader.readInt32() { + _8 = Api.parse(reader, signature: signature) as? Api.Document + } } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + let _c6 = (Int(_1!) & Int(1 << 1) == 0) || _6 != nil + let _c7 = (Int(_1!) & Int(1 << 2) == 0) || _7 != nil + let _c8 = (Int(_1!) & Int(1 << 3) == 0) || _8 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 { + return Api.help.AppUpdate.appUpdate(flags: _1!, id: _2!, version: _3!, text: _4!, entities: _5!, document: _6, url: _7, sticker: _8) + } + else { + return nil + } + } + public static func parse_noAppUpdate(_ reader: BufferReader) -> AppUpdate? { + return Api.help.AppUpdate.noAppUpdate + } + + } +} public extension Api.help { enum CountriesList: TypeConstructorDescription { case countriesList(countries: [Api.help.Country], hash: Int32) @@ -1236,61 +1322,3 @@ public extension Api.messages { } } -public extension Api.messages { - enum AllStickers: TypeConstructorDescription { - case allStickers(hash: Int64, sets: [Api.StickerSet]) - case allStickersNotModified - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .allStickers(let hash, let sets): - if boxed { - buffer.appendInt32(-843329861) - } - serializeInt64(hash, buffer: buffer, boxed: false) - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(sets.count)) - for item in sets { - item.serialize(buffer, true) - } - break - case .allStickersNotModified: - if boxed { - buffer.appendInt32(-395967805) - } - - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .allStickers(let hash, let sets): - return ("allStickers", [("hash", hash as Any), ("sets", sets as Any)]) - case .allStickersNotModified: - return ("allStickersNotModified", []) - } - } - - public static func parse_allStickers(_ reader: BufferReader) -> AllStickers? { - var _1: Int64? - _1 = reader.readInt64() - var _2: [Api.StickerSet]? - if let _ = reader.readInt32() { - _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StickerSet.self) - } - let _c1 = _1 != nil - let _c2 = _2 != nil - if _c1 && _c2 { - return Api.messages.AllStickers.allStickers(hash: _1!, sets: _2!) - } - else { - return nil - } - } - public static func parse_allStickersNotModified(_ reader: BufferReader) -> AllStickers? { - return Api.messages.AllStickers.allStickersNotModified - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api32.swift b/submodules/TelegramApi/Sources/Api32.swift index 0c987587ba..1341629fd0 100644 --- a/submodules/TelegramApi/Sources/Api32.swift +++ b/submodules/TelegramApi/Sources/Api32.swift @@ -1,3 +1,61 @@ +public extension Api.messages { + enum AllStickers: TypeConstructorDescription { + case allStickers(hash: Int64, sets: [Api.StickerSet]) + case allStickersNotModified + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .allStickers(let hash, let sets): + if boxed { + buffer.appendInt32(-843329861) + } + serializeInt64(hash, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(sets.count)) + for item in sets { + item.serialize(buffer, true) + } + break + case .allStickersNotModified: + if boxed { + buffer.appendInt32(-395967805) + } + + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .allStickers(let hash, let sets): + return ("allStickers", [("hash", hash as Any), ("sets", sets as Any)]) + case .allStickersNotModified: + return ("allStickersNotModified", []) + } + } + + public static func parse_allStickers(_ reader: BufferReader) -> AllStickers? { + var _1: Int64? + _1 = reader.readInt64() + var _2: [Api.StickerSet]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StickerSet.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.messages.AllStickers.allStickers(hash: _1!, sets: _2!) + } + else { + return nil + } + } + public static func parse_allStickersNotModified(_ reader: BufferReader) -> AllStickers? { + return Api.messages.AllStickers.allStickersNotModified + } + + } +} public extension Api.messages { enum ArchivedStickers: TypeConstructorDescription { case archivedStickers(count: Int32, sets: [Api.StickerSetCovered]) @@ -1354,87 +1412,3 @@ public extension Api.messages { } } -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) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .forumTopics(let flags, let count, let topics, let messages, let chats, let users, let pts): - if boxed { - buffer.appendInt32(913709011) - } - serializeInt32(flags, buffer: buffer, boxed: false) - serializeInt32(count, buffer: buffer, boxed: false) - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(topics.count)) - for item in topics { - item.serialize(buffer, true) - } - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(messages.count)) - for item in messages { - item.serialize(buffer, true) - } - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(chats.count)) - for item in chats { - item.serialize(buffer, true) - } - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(users.count)) - for item in users { - item.serialize(buffer, true) - } - serializeInt32(pts, buffer: buffer, boxed: false) - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .forumTopics(let flags, let count, let topics, let messages, let chats, let users, let pts): - return ("forumTopics", [("flags", flags as Any), ("count", count as Any), ("topics", topics as Any), ("messages", messages as Any), ("chats", chats as Any), ("users", users as Any), ("pts", pts as Any)]) - } - } - - public static func parse_forumTopics(_ reader: BufferReader) -> ForumTopics? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Int32? - _2 = reader.readInt32() - var _3: [Api.ForumTopic]? - if let _ = reader.readInt32() { - _3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.ForumTopic.self) - } - var _4: [Api.Message]? - if let _ = reader.readInt32() { - _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Message.self) - } - var _5: [Api.Chat]? - if let _ = reader.readInt32() { - _5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Chat.self) - } - var _6: [Api.User]? - if let _ = reader.readInt32() { - _6 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) - } - var _7: Int32? - _7 = reader.readInt32() - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = _3 != nil - let _c4 = _4 != nil - let _c5 = _5 != nil - let _c6 = _6 != nil - let _c7 = _7 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 { - return Api.messages.ForumTopics.forumTopics(flags: _1!, count: _2!, topics: _3!, messages: _4!, chats: _5!, users: _6!, pts: _7!) - } - else { - return nil - } - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api33.swift b/submodules/TelegramApi/Sources/Api33.swift index e154e8f8ca..8104601a66 100644 --- a/submodules/TelegramApi/Sources/Api33.swift +++ b/submodules/TelegramApi/Sources/Api33.swift @@ -1,3 +1,87 @@ +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) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .forumTopics(let flags, let count, let topics, let messages, let chats, let users, let pts): + if boxed { + buffer.appendInt32(913709011) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(count, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(topics.count)) + for item in topics { + item.serialize(buffer, true) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(messages.count)) + for item in messages { + item.serialize(buffer, true) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(chats.count)) + for item in chats { + item.serialize(buffer, true) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(users.count)) + for item in users { + item.serialize(buffer, true) + } + serializeInt32(pts, buffer: buffer, boxed: false) + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .forumTopics(let flags, let count, let topics, let messages, let chats, let users, let pts): + return ("forumTopics", [("flags", flags as Any), ("count", count as Any), ("topics", topics as Any), ("messages", messages as Any), ("chats", chats as Any), ("users", users as Any), ("pts", pts as Any)]) + } + } + + public static func parse_forumTopics(_ reader: BufferReader) -> ForumTopics? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: [Api.ForumTopic]? + if let _ = reader.readInt32() { + _3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.ForumTopic.self) + } + var _4: [Api.Message]? + if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Message.self) + } + var _5: [Api.Chat]? + if let _ = reader.readInt32() { + _5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Chat.self) + } + var _6: [Api.User]? + if let _ = reader.readInt32() { + _6 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) + } + var _7: Int32? + _7 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + let _c6 = _6 != nil + let _c7 = _7 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 { + return Api.messages.ForumTopics.forumTopics(flags: _1!, count: _2!, topics: _3!, messages: _4!, chats: _5!, users: _6!, pts: _7!) + } + else { + return nil + } + } + + } +} public extension Api.messages { enum FoundStickerSets: TypeConstructorDescription { case foundStickerSets(hash: Int64, sets: [Api.StickerSetCovered]) @@ -1438,61 +1522,3 @@ public extension Api.messages { } } -public extension Api.messages { - enum SavedReactionTags: TypeConstructorDescription { - case savedReactionTags(tags: [Api.SavedReactionTag], hash: Int64) - case savedReactionTagsNotModified - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .savedReactionTags(let tags, let hash): - if boxed { - buffer.appendInt32(844731658) - } - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(tags.count)) - for item in tags { - item.serialize(buffer, true) - } - serializeInt64(hash, buffer: buffer, boxed: false) - break - case .savedReactionTagsNotModified: - if boxed { - buffer.appendInt32(-2003084817) - } - - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .savedReactionTags(let tags, let hash): - return ("savedReactionTags", [("tags", tags as Any), ("hash", hash as Any)]) - case .savedReactionTagsNotModified: - return ("savedReactionTagsNotModified", []) - } - } - - public static func parse_savedReactionTags(_ reader: BufferReader) -> SavedReactionTags? { - var _1: [Api.SavedReactionTag]? - if let _ = reader.readInt32() { - _1 = Api.parseVector(reader, elementSignature: 0, elementType: Api.SavedReactionTag.self) - } - var _2: Int64? - _2 = reader.readInt64() - let _c1 = _1 != nil - let _c2 = _2 != nil - if _c1 && _c2 { - return Api.messages.SavedReactionTags.savedReactionTags(tags: _1!, hash: _2!) - } - else { - return nil - } - } - public static func parse_savedReactionTagsNotModified(_ reader: BufferReader) -> SavedReactionTags? { - return Api.messages.SavedReactionTags.savedReactionTagsNotModified - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api34.swift b/submodules/TelegramApi/Sources/Api34.swift index b82d6421c4..b2ea498c9f 100644 --- a/submodules/TelegramApi/Sources/Api34.swift +++ b/submodules/TelegramApi/Sources/Api34.swift @@ -1,3 +1,61 @@ +public extension Api.messages { + enum SavedReactionTags: TypeConstructorDescription { + case savedReactionTags(tags: [Api.SavedReactionTag], hash: Int64) + case savedReactionTagsNotModified + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .savedReactionTags(let tags, let hash): + if boxed { + buffer.appendInt32(844731658) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(tags.count)) + for item in tags { + item.serialize(buffer, true) + } + serializeInt64(hash, buffer: buffer, boxed: false) + break + case .savedReactionTagsNotModified: + if boxed { + buffer.appendInt32(-2003084817) + } + + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .savedReactionTags(let tags, let hash): + return ("savedReactionTags", [("tags", tags as Any), ("hash", hash as Any)]) + case .savedReactionTagsNotModified: + return ("savedReactionTagsNotModified", []) + } + } + + public static func parse_savedReactionTags(_ reader: BufferReader) -> SavedReactionTags? { + var _1: [Api.SavedReactionTag]? + if let _ = reader.readInt32() { + _1 = Api.parseVector(reader, elementSignature: 0, elementType: Api.SavedReactionTag.self) + } + var _2: Int64? + _2 = reader.readInt64() + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.messages.SavedReactionTags.savedReactionTags(tags: _1!, hash: _2!) + } + else { + return nil + } + } + public static func parse_savedReactionTagsNotModified(_ reader: BufferReader) -> SavedReactionTags? { + return Api.messages.SavedReactionTags.savedReactionTagsNotModified + } + + } +} public extension Api.messages { enum SearchCounter: TypeConstructorDescription { case searchCounter(flags: Int32, filter: Api.MessagesFilter, count: Int32) @@ -1544,45 +1602,3 @@ public extension Api.payments { } } -public extension Api.payments { - enum SavedInfo: TypeConstructorDescription { - case savedInfo(flags: Int32, savedInfo: Api.PaymentRequestedInfo?) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .savedInfo(let flags, let savedInfo): - if boxed { - buffer.appendInt32(-74456004) - } - serializeInt32(flags, buffer: buffer, boxed: false) - if Int(flags) & Int(1 << 0) != 0 {savedInfo!.serialize(buffer, true)} - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .savedInfo(let flags, let savedInfo): - return ("savedInfo", [("flags", flags as Any), ("savedInfo", savedInfo as Any)]) - } - } - - public static func parse_savedInfo(_ reader: BufferReader) -> SavedInfo? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Api.PaymentRequestedInfo? - if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { - _2 = Api.parse(reader, signature: signature) as? Api.PaymentRequestedInfo - } } - let _c1 = _1 != nil - let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil - if _c1 && _c2 { - return Api.payments.SavedInfo.savedInfo(flags: _1!, savedInfo: _2) - } - else { - return nil - } - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api35.swift b/submodules/TelegramApi/Sources/Api35.swift index c8dbfa6fa7..a67f9921d3 100644 --- a/submodules/TelegramApi/Sources/Api35.swift +++ b/submodules/TelegramApi/Sources/Api35.swift @@ -1,3 +1,45 @@ +public extension Api.payments { + enum SavedInfo: TypeConstructorDescription { + case savedInfo(flags: Int32, savedInfo: Api.PaymentRequestedInfo?) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .savedInfo(let flags, let savedInfo): + if boxed { + buffer.appendInt32(-74456004) + } + serializeInt32(flags, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {savedInfo!.serialize(buffer, true)} + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .savedInfo(let flags, let savedInfo): + return ("savedInfo", [("flags", flags as Any), ("savedInfo", savedInfo as Any)]) + } + } + + public static func parse_savedInfo(_ reader: BufferReader) -> SavedInfo? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.PaymentRequestedInfo? + if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.PaymentRequestedInfo + } } + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil + if _c1 && _c2 { + return Api.payments.SavedInfo.savedInfo(flags: _1!, savedInfo: _2) + } + else { + return nil + } + } + + } +} public extension Api.payments { enum SavedStarGifts: TypeConstructorDescription { case savedStarGifts(flags: Int32, count: Int32, chatNotificationsEnabled: Api.Bool?, gifts: [Api.SavedStarGift], nextOffset: String?, chats: [Api.Chat], users: [Api.User]) @@ -1724,153 +1766,3 @@ public extension Api.stats { } } -public extension Api.stats { - enum MegagroupStats: TypeConstructorDescription { - case megagroupStats(period: Api.StatsDateRangeDays, members: Api.StatsAbsValueAndPrev, messages: Api.StatsAbsValueAndPrev, viewers: Api.StatsAbsValueAndPrev, posters: Api.StatsAbsValueAndPrev, growthGraph: Api.StatsGraph, membersGraph: Api.StatsGraph, newMembersBySourceGraph: Api.StatsGraph, languagesGraph: Api.StatsGraph, messagesGraph: Api.StatsGraph, actionsGraph: Api.StatsGraph, topHoursGraph: Api.StatsGraph, weekdaysGraph: Api.StatsGraph, topPosters: [Api.StatsGroupTopPoster], topAdmins: [Api.StatsGroupTopAdmin], topInviters: [Api.StatsGroupTopInviter], users: [Api.User]) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .megagroupStats(let period, let members, let messages, let viewers, let posters, let growthGraph, let membersGraph, let newMembersBySourceGraph, let languagesGraph, let messagesGraph, let actionsGraph, let topHoursGraph, let weekdaysGraph, let topPosters, let topAdmins, let topInviters, let users): - if boxed { - buffer.appendInt32(-276825834) - } - period.serialize(buffer, true) - members.serialize(buffer, true) - messages.serialize(buffer, true) - viewers.serialize(buffer, true) - posters.serialize(buffer, true) - growthGraph.serialize(buffer, true) - membersGraph.serialize(buffer, true) - newMembersBySourceGraph.serialize(buffer, true) - languagesGraph.serialize(buffer, true) - messagesGraph.serialize(buffer, true) - actionsGraph.serialize(buffer, true) - topHoursGraph.serialize(buffer, true) - weekdaysGraph.serialize(buffer, true) - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(topPosters.count)) - for item in topPosters { - item.serialize(buffer, true) - } - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(topAdmins.count)) - for item in topAdmins { - item.serialize(buffer, true) - } - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(topInviters.count)) - for item in topInviters { - item.serialize(buffer, true) - } - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(users.count)) - for item in users { - item.serialize(buffer, true) - } - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .megagroupStats(let period, let members, let messages, let viewers, let posters, let growthGraph, let membersGraph, let newMembersBySourceGraph, let languagesGraph, let messagesGraph, let actionsGraph, let topHoursGraph, let weekdaysGraph, let topPosters, let topAdmins, let topInviters, let users): - return ("megagroupStats", [("period", period as Any), ("members", members as Any), ("messages", messages as Any), ("viewers", viewers as Any), ("posters", posters as Any), ("growthGraph", growthGraph as Any), ("membersGraph", membersGraph as Any), ("newMembersBySourceGraph", newMembersBySourceGraph as Any), ("languagesGraph", languagesGraph as Any), ("messagesGraph", messagesGraph as Any), ("actionsGraph", actionsGraph as Any), ("topHoursGraph", topHoursGraph as Any), ("weekdaysGraph", weekdaysGraph as Any), ("topPosters", topPosters as Any), ("topAdmins", topAdmins as Any), ("topInviters", topInviters as Any), ("users", users as Any)]) - } - } - - public static func parse_megagroupStats(_ reader: BufferReader) -> MegagroupStats? { - var _1: Api.StatsDateRangeDays? - if let signature = reader.readInt32() { - _1 = Api.parse(reader, signature: signature) as? Api.StatsDateRangeDays - } - var _2: Api.StatsAbsValueAndPrev? - if let signature = reader.readInt32() { - _2 = Api.parse(reader, signature: signature) as? Api.StatsAbsValueAndPrev - } - var _3: Api.StatsAbsValueAndPrev? - if let signature = reader.readInt32() { - _3 = Api.parse(reader, signature: signature) as? Api.StatsAbsValueAndPrev - } - var _4: Api.StatsAbsValueAndPrev? - if let signature = reader.readInt32() { - _4 = Api.parse(reader, signature: signature) as? Api.StatsAbsValueAndPrev - } - var _5: Api.StatsAbsValueAndPrev? - if let signature = reader.readInt32() { - _5 = Api.parse(reader, signature: signature) as? Api.StatsAbsValueAndPrev - } - var _6: Api.StatsGraph? - if let signature = reader.readInt32() { - _6 = Api.parse(reader, signature: signature) as? Api.StatsGraph - } - var _7: Api.StatsGraph? - if let signature = reader.readInt32() { - _7 = Api.parse(reader, signature: signature) as? Api.StatsGraph - } - var _8: Api.StatsGraph? - if let signature = reader.readInt32() { - _8 = Api.parse(reader, signature: signature) as? Api.StatsGraph - } - var _9: Api.StatsGraph? - if let signature = reader.readInt32() { - _9 = Api.parse(reader, signature: signature) as? Api.StatsGraph - } - var _10: Api.StatsGraph? - if let signature = reader.readInt32() { - _10 = Api.parse(reader, signature: signature) as? Api.StatsGraph - } - var _11: Api.StatsGraph? - if let signature = reader.readInt32() { - _11 = Api.parse(reader, signature: signature) as? Api.StatsGraph - } - var _12: Api.StatsGraph? - if let signature = reader.readInt32() { - _12 = Api.parse(reader, signature: signature) as? Api.StatsGraph - } - var _13: Api.StatsGraph? - if let signature = reader.readInt32() { - _13 = Api.parse(reader, signature: signature) as? Api.StatsGraph - } - var _14: [Api.StatsGroupTopPoster]? - if let _ = reader.readInt32() { - _14 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StatsGroupTopPoster.self) - } - var _15: [Api.StatsGroupTopAdmin]? - if let _ = reader.readInt32() { - _15 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StatsGroupTopAdmin.self) - } - var _16: [Api.StatsGroupTopInviter]? - if let _ = reader.readInt32() { - _16 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StatsGroupTopInviter.self) - } - var _17: [Api.User]? - if let _ = reader.readInt32() { - _17 = 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 - let _c5 = _5 != nil - let _c6 = _6 != nil - let _c7 = _7 != nil - let _c8 = _8 != nil - let _c9 = _9 != nil - let _c10 = _10 != nil - let _c11 = _11 != nil - let _c12 = _12 != nil - let _c13 = _13 != nil - let _c14 = _14 != nil - let _c15 = _15 != nil - let _c16 = _16 != nil - let _c17 = _17 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 && _c17 { - return Api.stats.MegagroupStats.megagroupStats(period: _1!, members: _2!, messages: _3!, viewers: _4!, posters: _5!, growthGraph: _6!, membersGraph: _7!, newMembersBySourceGraph: _8!, languagesGraph: _9!, messagesGraph: _10!, actionsGraph: _11!, topHoursGraph: _12!, weekdaysGraph: _13!, topPosters: _14!, topAdmins: _15!, topInviters: _16!, users: _17!) - } - else { - return nil - } - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api36.swift b/submodules/TelegramApi/Sources/Api36.swift index 8d26c615bc..6018b0652b 100644 --- a/submodules/TelegramApi/Sources/Api36.swift +++ b/submodules/TelegramApi/Sources/Api36.swift @@ -1,3 +1,153 @@ +public extension Api.stats { + enum MegagroupStats: TypeConstructorDescription { + case megagroupStats(period: Api.StatsDateRangeDays, members: Api.StatsAbsValueAndPrev, messages: Api.StatsAbsValueAndPrev, viewers: Api.StatsAbsValueAndPrev, posters: Api.StatsAbsValueAndPrev, growthGraph: Api.StatsGraph, membersGraph: Api.StatsGraph, newMembersBySourceGraph: Api.StatsGraph, languagesGraph: Api.StatsGraph, messagesGraph: Api.StatsGraph, actionsGraph: Api.StatsGraph, topHoursGraph: Api.StatsGraph, weekdaysGraph: Api.StatsGraph, topPosters: [Api.StatsGroupTopPoster], topAdmins: [Api.StatsGroupTopAdmin], topInviters: [Api.StatsGroupTopInviter], users: [Api.User]) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .megagroupStats(let period, let members, let messages, let viewers, let posters, let growthGraph, let membersGraph, let newMembersBySourceGraph, let languagesGraph, let messagesGraph, let actionsGraph, let topHoursGraph, let weekdaysGraph, let topPosters, let topAdmins, let topInviters, let users): + if boxed { + buffer.appendInt32(-276825834) + } + period.serialize(buffer, true) + members.serialize(buffer, true) + messages.serialize(buffer, true) + viewers.serialize(buffer, true) + posters.serialize(buffer, true) + growthGraph.serialize(buffer, true) + membersGraph.serialize(buffer, true) + newMembersBySourceGraph.serialize(buffer, true) + languagesGraph.serialize(buffer, true) + messagesGraph.serialize(buffer, true) + actionsGraph.serialize(buffer, true) + topHoursGraph.serialize(buffer, true) + weekdaysGraph.serialize(buffer, true) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(topPosters.count)) + for item in topPosters { + item.serialize(buffer, true) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(topAdmins.count)) + for item in topAdmins { + item.serialize(buffer, true) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(topInviters.count)) + for item in topInviters { + item.serialize(buffer, true) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(users.count)) + for item in users { + item.serialize(buffer, true) + } + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .megagroupStats(let period, let members, let messages, let viewers, let posters, let growthGraph, let membersGraph, let newMembersBySourceGraph, let languagesGraph, let messagesGraph, let actionsGraph, let topHoursGraph, let weekdaysGraph, let topPosters, let topAdmins, let topInviters, let users): + return ("megagroupStats", [("period", period as Any), ("members", members as Any), ("messages", messages as Any), ("viewers", viewers as Any), ("posters", posters as Any), ("growthGraph", growthGraph as Any), ("membersGraph", membersGraph as Any), ("newMembersBySourceGraph", newMembersBySourceGraph as Any), ("languagesGraph", languagesGraph as Any), ("messagesGraph", messagesGraph as Any), ("actionsGraph", actionsGraph as Any), ("topHoursGraph", topHoursGraph as Any), ("weekdaysGraph", weekdaysGraph as Any), ("topPosters", topPosters as Any), ("topAdmins", topAdmins as Any), ("topInviters", topInviters as Any), ("users", users as Any)]) + } + } + + public static func parse_megagroupStats(_ reader: BufferReader) -> MegagroupStats? { + var _1: Api.StatsDateRangeDays? + if let signature = reader.readInt32() { + _1 = Api.parse(reader, signature: signature) as? Api.StatsDateRangeDays + } + var _2: Api.StatsAbsValueAndPrev? + if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.StatsAbsValueAndPrev + } + var _3: Api.StatsAbsValueAndPrev? + if let signature = reader.readInt32() { + _3 = Api.parse(reader, signature: signature) as? Api.StatsAbsValueAndPrev + } + var _4: Api.StatsAbsValueAndPrev? + if let signature = reader.readInt32() { + _4 = Api.parse(reader, signature: signature) as? Api.StatsAbsValueAndPrev + } + var _5: Api.StatsAbsValueAndPrev? + if let signature = reader.readInt32() { + _5 = Api.parse(reader, signature: signature) as? Api.StatsAbsValueAndPrev + } + var _6: Api.StatsGraph? + if let signature = reader.readInt32() { + _6 = Api.parse(reader, signature: signature) as? Api.StatsGraph + } + var _7: Api.StatsGraph? + if let signature = reader.readInt32() { + _7 = Api.parse(reader, signature: signature) as? Api.StatsGraph + } + var _8: Api.StatsGraph? + if let signature = reader.readInt32() { + _8 = Api.parse(reader, signature: signature) as? Api.StatsGraph + } + var _9: Api.StatsGraph? + if let signature = reader.readInt32() { + _9 = Api.parse(reader, signature: signature) as? Api.StatsGraph + } + var _10: Api.StatsGraph? + if let signature = reader.readInt32() { + _10 = Api.parse(reader, signature: signature) as? Api.StatsGraph + } + var _11: Api.StatsGraph? + if let signature = reader.readInt32() { + _11 = Api.parse(reader, signature: signature) as? Api.StatsGraph + } + var _12: Api.StatsGraph? + if let signature = reader.readInt32() { + _12 = Api.parse(reader, signature: signature) as? Api.StatsGraph + } + var _13: Api.StatsGraph? + if let signature = reader.readInt32() { + _13 = Api.parse(reader, signature: signature) as? Api.StatsGraph + } + var _14: [Api.StatsGroupTopPoster]? + if let _ = reader.readInt32() { + _14 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StatsGroupTopPoster.self) + } + var _15: [Api.StatsGroupTopAdmin]? + if let _ = reader.readInt32() { + _15 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StatsGroupTopAdmin.self) + } + var _16: [Api.StatsGroupTopInviter]? + if let _ = reader.readInt32() { + _16 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StatsGroupTopInviter.self) + } + var _17: [Api.User]? + if let _ = reader.readInt32() { + _17 = 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 + let _c5 = _5 != nil + let _c6 = _6 != nil + let _c7 = _7 != nil + let _c8 = _8 != nil + let _c9 = _9 != nil + let _c10 = _10 != nil + let _c11 = _11 != nil + let _c12 = _12 != nil + let _c13 = _13 != nil + let _c14 = _14 != nil + let _c15 = _15 != nil + let _c16 = _16 != nil + let _c17 = _17 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 && _c17 { + return Api.stats.MegagroupStats.megagroupStats(period: _1!, members: _2!, messages: _3!, viewers: _4!, posters: _5!, growthGraph: _6!, membersGraph: _7!, newMembersBySourceGraph: _8!, languagesGraph: _9!, messagesGraph: _10!, actionsGraph: _11!, topHoursGraph: _12!, weekdaysGraph: _13!, topPosters: _14!, topAdmins: _15!, topInviters: _16!, users: _17!) + } + else { + return nil + } + } + + } +} public extension Api.stats { enum MessageStats: TypeConstructorDescription { case messageStats(viewsGraph: Api.StatsGraph, reactionsByEmotionGraph: Api.StatsGraph) diff --git a/submodules/TelegramApi/Sources/Api38.swift b/submodules/TelegramApi/Sources/Api38.swift index e2bf3f4406..dcba940f91 100644 --- a/submodules/TelegramApi/Sources/Api38.swift +++ b/submodules/TelegramApi/Sources/Api38.swift @@ -4245,6 +4245,21 @@ public extension Api.functions.contacts { }) } } +public extension Api.functions.contacts { + static func getSponsoredPeers(q: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(-1228356717) + serializeString(q, buffer: buffer, boxed: false) + return (FunctionDescription(name: "contacts.getSponsoredPeers", parameters: [("q", String(describing: q))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.contacts.SponsoredPeers? in + let reader = BufferReader(buffer) + var result: Api.contacts.SponsoredPeers? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.contacts.SponsoredPeers + } + return result + }) + } +} public extension Api.functions.contacts { static func getStatuses() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.ContactStatus]>) { let buffer = Buffer() @@ -5124,13 +5139,12 @@ public extension Api.functions.messages { } } public extension Api.functions.messages { - static func clickSponsoredMessage(flags: Int32, peer: Api.InputPeer, randomId: Buffer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func clickSponsoredMessage(flags: Int32, randomId: Buffer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(252261477) + buffer.appendInt32(-2110454402) serializeInt32(flags, buffer: buffer, boxed: false) - peer.serialize(buffer, true) serializeBytes(randomId, buffer: buffer, boxed: false) - return (FunctionDescription(name: "messages.clickSponsoredMessage", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("randomId", String(describing: randomId))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in + return (FunctionDescription(name: "messages.clickSponsoredMessage", parameters: [("flags", String(describing: flags)), ("randomId", String(describing: randomId))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in let reader = BufferReader(buffer) var result: Api.Bool? if let signature = reader.readInt32() { @@ -7636,13 +7650,12 @@ public extension Api.functions.messages { } } public extension Api.functions.messages { - static func reportSponsoredMessage(peer: Api.InputPeer, randomId: Buffer, option: Buffer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func reportSponsoredMessage(randomId: Buffer, option: Buffer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(452189112) - peer.serialize(buffer, true) + buffer.appendInt32(315355332) serializeBytes(randomId, buffer: buffer, boxed: false) serializeBytes(option, buffer: buffer, boxed: false) - return (FunctionDescription(name: "messages.reportSponsoredMessage", parameters: [("peer", String(describing: peer)), ("randomId", String(describing: randomId)), ("option", String(describing: option))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.channels.SponsoredMessageReportResult? in + return (FunctionDescription(name: "messages.reportSponsoredMessage", parameters: [("randomId", String(describing: randomId)), ("option", String(describing: option))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.channels.SponsoredMessageReportResult? in let reader = BufferReader(buffer) var result: Api.channels.SponsoredMessageReportResult? if let signature = reader.readInt32() { @@ -8984,12 +8997,11 @@ public extension Api.functions.messages { } } public extension Api.functions.messages { - static func viewSponsoredMessage(peer: Api.InputPeer, randomId: Buffer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func viewSponsoredMessage(randomId: Buffer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(1731909873) - peer.serialize(buffer, true) + buffer.appendInt32(647902787) serializeBytes(randomId, buffer: buffer, boxed: false) - return (FunctionDescription(name: "messages.viewSponsoredMessage", parameters: [("peer", String(describing: peer)), ("randomId", String(describing: randomId))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in + return (FunctionDescription(name: "messages.viewSponsoredMessage", parameters: [("randomId", String(describing: randomId))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in let reader = BufferReader(buffer) var result: Api.Bool? if let signature = reader.readInt32() { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/AdMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/AdMessages.swift index 13dd9630b4..55962f61db 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/AdMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/AdMessages.swift @@ -517,19 +517,11 @@ private class AdMessagesHistoryContextImpl { } func markAsSeen(opaqueId: Data) { - let signal: Signal = account.postbox.transaction { transaction -> Api.InputPeer? in - return transaction.getPeer(self.peerId).flatMap(apiInputPeer) - } - |> mapToSignal { inputPeer -> Signal in - guard let inputPeer else { - return .complete() - } - return self.account.network.request(Api.functions.messages.viewSponsoredMessage(peer: inputPeer, randomId: Buffer(data: opaqueId))) - |> `catch` { _ -> Signal in - return .single(.boolFalse) - } - |> ignoreValues + let signal: Signal = self.account.network.request(Api.functions.messages.viewSponsoredMessage(randomId: Buffer(data: opaqueId))) + |> `catch` { _ -> Signal in + return .single(.boolFalse) } + |> ignoreValues self.maskAsSeenDisposables.set(signal.start(), forKey: opaqueId) } @@ -610,25 +602,17 @@ public class AdMessagesHistoryContext { func _internal_markAdAction(account: Account, peerId: EnginePeer.Id, opaqueId: Data, media: Bool, fullscreen: Bool) { - let signal: Signal = account.postbox.transaction { transaction -> Api.InputPeer? in - return transaction.getPeer(peerId).flatMap(apiInputPeer) + var flags: Int32 = 0 + if media { + flags |= (1 << 0) } - |> mapToSignal { inputPeer -> Signal in - guard let inputPeer else { - return .complete() - } - var flags: Int32 = 0 - if media { - flags |= (1 << 0) - } - if fullscreen { - flags |= (1 << 1) - } - return account.network.request(Api.functions.messages.clickSponsoredMessage(flags: flags, peer: inputPeer, randomId: Buffer(data: opaqueId))) - |> `catch` { _ -> Signal in - return .single(.boolFalse) - } - |> ignoreValues + if fullscreen { + flags |= (1 << 1) } + let signal = account.network.request(Api.functions.messages.clickSponsoredMessage(flags: flags, randomId: Buffer(data: opaqueId))) + |> `catch` { _ -> Signal in + return .single(.boolFalse) + } + |> ignoreValues let _ = signal.start() } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift index a7893ba74d..57deb4e298 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift @@ -565,7 +565,7 @@ func _internal_removeChatManagingBot(account: Account, chatId: EnginePeer.Id) -> excludePeers: excludePeers, exclude: connectedBot.recipients.exclude ), - canReply: connectedBot.canReply + rights: connectedBot.rights )) } else { return current diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/QuickReplyMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/QuickReplyMessages.swift index 4c7c5b1471..75181796e7 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/QuickReplyMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/QuickReplyMessages.swift @@ -764,6 +764,59 @@ extension TelegramBusinessIntro { } } +extension TelegramBusinessBotRights { + init(apiValue: Api.BusinessBotRights) { + var value: TelegramBusinessBotRights = [] + switch apiValue { + case let .businessBotRights(flags): + if (flags & (1 << 0)) != 0 { + value.insert(.reply) + } + if (flags & (1 << 1)) != 0 { + value.insert(.readMessages) + } + if (flags & (1 << 2)) != 0 { + value.insert(.deleteSentMessages) + } + if (flags & (1 << 3)) != 0 { + value.insert(.deleteReceivedMessages) + } + + if (flags & (1 << 4)) != 0 { + value.insert(.editName) + } + if (flags & (1 << 5)) != 0 { + value.insert(.editBio) + } + if (flags & (1 << 6)) != 0 { + value.insert(.editProfilePhoto) + } + if (flags & (1 << 7)) != 0 { + value.insert(.editUsername) + } + if (flags & (1 << 8)) != 0 { + value.insert(.viewGifts) + } + if (flags & (1 << 9)) != 0 { + value.insert(.sellGifts) + } + if (flags & (1 << 10)) != 0 { + value.insert(.changeGiftSettings) + } + if (flags & (1 << 11)) != 0 { + value.insert(.transferAndUpgradeGifts) + } + if (flags & (1 << 12)) != 0 { + value.insert(.transferStars) + } + if (flags & (1 << 13)) != 0 { + value.insert(.manageStories) + } + } + self = value + } +} + extension TelegramBusinessRecipients { convenience init(apiValue: Api.BusinessRecipients) { switch apiValue { @@ -1021,12 +1074,12 @@ func _internal_updateBusinessIntro(account: Account, intro: TelegramBusinessIntr public final class TelegramAccountConnectedBot: Codable, Equatable { public let id: PeerId public let recipients: TelegramBusinessRecipients - public let canReply: Bool + public let rights: TelegramBusinessBotRights - public init(id: PeerId, recipients: TelegramBusinessRecipients, canReply: Bool) { + public init(id: PeerId, recipients: TelegramBusinessRecipients, rights: TelegramBusinessBotRights) { self.id = id self.recipients = recipients - self.canReply = canReply + self.rights = rights } public static func ==(lhs: TelegramAccountConnectedBot, rhs: TelegramAccountConnectedBot) -> Bool { @@ -1039,13 +1092,51 @@ public final class TelegramAccountConnectedBot: Codable, Equatable { if lhs.recipients != rhs.recipients { return false } - if lhs.canReply != rhs.canReply { + if lhs.rights != rhs.rights { return false } return true } } +public struct TelegramBusinessBotRights: OptionSet, Codable { + public var rawValue: Int32 + + public init() { + self.rawValue = 0 + } + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public static let reply = TelegramBusinessBotRights(rawValue: 1 << 0) + public static let readMessages = TelegramBusinessBotRights(rawValue: 1 << 1) + public static let deleteSentMessages = TelegramBusinessBotRights(rawValue: 1 << 2) + public static let deleteReceivedMessages = TelegramBusinessBotRights(rawValue: 1 << 3) + public static let editName = TelegramBusinessBotRights(rawValue: 1 << 4) + public static let editBio = TelegramBusinessBotRights(rawValue: 1 << 5) + public static let editProfilePhoto = TelegramBusinessBotRights(rawValue: 1 << 6) + public static let editUsername = TelegramBusinessBotRights(rawValue: 1 << 7) + public static let viewGifts = TelegramBusinessBotRights(rawValue: 1 << 8) + public static let sellGifts = TelegramBusinessBotRights(rawValue: 1 << 9) + public static let changeGiftSettings = TelegramBusinessBotRights(rawValue: 1 << 10) + public static let transferAndUpgradeGifts = TelegramBusinessBotRights(rawValue: 1 << 11) + public static let transferStars = TelegramBusinessBotRights(rawValue: 1 << 12) + public static let manageStories = TelegramBusinessBotRights(rawValue: 1 << 13) + + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: StringCodingKey.self) + let value = try? container.decode(Int32.self, forKey: "v") + self = TelegramBusinessBotRights(rawValue: value ?? 0) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: StringCodingKey.self) + try container.encode(self.rawValue, forKey: "v") + } +} + public func _internal_setAccountConnectedBot(account: Account, bot: TelegramAccountConnectedBot?) -> Signal { let remoteApply = account.postbox.transaction { transaction -> (Peer?, [Peer], [Peer]) in guard let bot else { @@ -1059,20 +1150,65 @@ public func _internal_setAccountConnectedBot(account: Account, bot: TelegramAcco } |> mapToSignal { botUser, additionalPeers, excludePeers in var flags: Int32 = 0 + var mappedRights: Api.BusinessBotRights? var mappedBot: Api.InputUser = .inputUserEmpty var mappedRecipients: Api.InputBusinessBotRecipients = .inputBusinessBotRecipients(flags: 0, users: nil, excludeUsers: nil) if let bot, let inputBotUser = botUser.flatMap(apiInputUser) { mappedBot = inputBotUser - if bot.canReply { - flags |= 1 << 0 + + flags |= 1 << 0 + + var rightsFlags: Int32 = 0 + if bot.rights.contains(.reply) { + rightsFlags |= (1 << 0) } + if bot.rights.contains(.readMessages) { + rightsFlags |= (1 << 1) + } + if bot.rights.contains(.deleteSentMessages) { + rightsFlags |= (1 << 2) + } + if bot.rights.contains(.deleteReceivedMessages) { + rightsFlags |= (1 << 3) + } + if bot.rights.contains(.editName) { + rightsFlags |= (1 << 4) + } + if bot.rights.contains(.editBio) { + rightsFlags |= (1 << 5) + } + if bot.rights.contains(.editProfilePhoto) { + rightsFlags |= (1 << 6) + } + if bot.rights.contains(.editUsername) { + rightsFlags |= (1 << 7) + } + if bot.rights.contains(.viewGifts) { + rightsFlags |= (1 << 8) + } + if bot.rights.contains(.sellGifts) { + rightsFlags |= (1 << 9) + } + if bot.rights.contains(.changeGiftSettings) { + rightsFlags |= (1 << 10) + } + if bot.rights.contains(.transferAndUpgradeGifts) { + rightsFlags |= (1 << 11) + } + if bot.rights.contains(.transferStars) { + rightsFlags |= (1 << 12) + } + if bot.rights.contains(.manageStories) { + rightsFlags |= (1 << 13) + } + mappedRights = .businessBotRights(flags: rightsFlags) mappedRecipients = bot.recipients.apiInputBotValue(additionalPeers: additionalPeers, excludePeers: excludePeers) } else { flags |= 1 << 1 } - return account.network.request(Api.functions.account.updateConnectedBot(flags: flags, rights: nil, bot: mappedBot, recipients: mappedRecipients)) + return account.network.request(Api.functions.account.updateConnectedBot(flags: flags, rights: mappedRights, bot: mappedBot, recipients: mappedRecipients)) |> map(Optional.init) |> `catch` { _ -> Signal in return .single(nil) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/ReportAds.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ReportAds.swift index 61fb824b75..3a93dd60b3 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/ReportAds.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ReportAds.swift @@ -20,33 +20,26 @@ public enum ReportAdMessageError { } func _internal_reportAdMessage(account: Account, peerId: EnginePeer.Id, opaqueId: Data, option: Data?) -> Signal { - return account.postbox.transaction { transaction -> Signal in - guard let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) else { - return .fail(.generic) + return account.network.request(Api.functions.messages.reportSponsoredMessage(randomId: Buffer(data: opaqueId), option: Buffer(data: option))) + |> mapError { error -> ReportAdMessageError in + if error.errorDescription == "PREMIUM_ACCOUNT_REQUIRED" { + return .premiumRequired } - return account.network.request(Api.functions.messages.reportSponsoredMessage(peer: inputPeer, randomId: Buffer(data: opaqueId), option: Buffer(data: option))) - |> mapError { error -> ReportAdMessageError in - if error.errorDescription == "PREMIUM_ACCOUNT_REQUIRED" { - return .premiumRequired - } - return .generic - } - |> map { result -> ReportAdMessageResult in - switch result { - case let .sponsoredMessageReportResultChooseOption(title, options): - return .options(title: title, options: options.map { - switch $0 { - case let .sponsoredMessageReportOption(text, option): - return ReportAdMessageResult.Option(text: text, option: option.makeData()) - } - }) - case .sponsoredMessageReportResultAdsHidden: - return .adsHidden - case .sponsoredMessageReportResultReported: - return .reported - } + return .generic + } + |> map { result -> ReportAdMessageResult in + switch result { + case let .sponsoredMessageReportResultChooseOption(title, options): + return .options(title: title, options: options.map { + switch $0 { + case let .sponsoredMessageReportOption(text, option): + return ReportAdMessageResult.Option(text: text, option: option.makeData()) + } + }) + case .sponsoredMessageReportResultAdsHidden: + return .adsHidden + case .sponsoredMessageReportResultReported: + return .reported } } - |> castError(ReportAdMessageError.self) - |> switchToLatest } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/AdPeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/AdPeers.swift new file mode 100644 index 0000000000..589bad08d4 --- /dev/null +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/AdPeers.swift @@ -0,0 +1,75 @@ +import Foundation +import Postbox +import SwiftSignalKit +import TelegramApi + +public class AdPeer: Equatable { + public let opaqueId: Data + public let peer: EnginePeer + public let sponsorInfo: String? + public let additionalInfo: String? + + public init(opaqueId: Data, peer: EnginePeer, sponsorInfo: String?, additionalInfo: String?) { + self.opaqueId = opaqueId + self.peer = peer + self.sponsorInfo = sponsorInfo + self.additionalInfo = additionalInfo + } + + public static func ==(lhs: AdPeer, rhs: AdPeer) -> Bool { + if lhs.opaqueId != rhs.opaqueId { + return false + } + if lhs.peer != rhs.peer { + return false + } + if lhs.sponsorInfo != rhs.sponsorInfo { + return false + } + if lhs.additionalInfo != rhs.additionalInfo { + return false + } + return true + } +} + +func _internal_searchAdPeers(account: Account, query: String) -> Signal<[AdPeer], NoError> { + return account.network.request(Api.functions.contacts.getSponsoredPeers(q: query)) + |> map(Optional.init) + |> `catch` { _ in + return .single(nil) + } + |> mapToSignal { result in + guard let result else { + return .single([]) + } + return account.postbox.transaction { transaction -> [AdPeer] in + switch result { + case let .sponsoredPeers(peers, chats, users): + let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users) + updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: parsedPeers) + + var result: [AdPeer] = [] + for peer in peers { + switch peer { + case let .sponsoredPeer(_, randomId, apiPeer, sponsorInfo, additionalInfo): + guard let peer = parsedPeers.peers[apiPeer.peerId] else { + continue + } + result.append( + AdPeer( + opaqueId: randomId.makeData(), + peer: EnginePeer(peer), + sponsorInfo: sponsorInfo, + additionalInfo: additionalInfo + ) + ) + } + } + return result + default: + return [] + } + } + } +} diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift index b5696bd678..06ae5607a4 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift @@ -1522,6 +1522,10 @@ public extension TelegramEngine { return _internal_requestRecommendedBots(account: self.account, peerId: peerId, forceUpdate: forceUpdate) } + public func searchAdPeers(query: String) -> Signal<[AdPeer], NoError> { + return _internal_searchAdPeers(account: self.account, query: query) + } + public func isPremiumRequiredToContact(_ peerIds: [EnginePeer.Id]) -> Signal<[EnginePeer.Id: RequirementToContact], NoError> { return _internal_updateIsPremiumRequiredToContact(account: self.account, peerIds: peerIds) } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/UpdateCachedPeerData.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/UpdateCachedPeerData.swift index c5ddf86611..101136152f 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/UpdateCachedPeerData.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/UpdateCachedPeerData.swift @@ -246,11 +246,11 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee if let apiBot = connectedBots.first { switch apiBot { - case let .connectedBot(flags, botId, recipients, _): + case let .connectedBot(_, botId, recipients, rights): mappedConnectedBot = TelegramAccountConnectedBot( id: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId)), recipients: TelegramBusinessRecipients(apiValue: recipients), - canReply: (flags & (1 << 0)) != 0 + rights: TelegramBusinessBotRights(apiValue: rights) ) } } diff --git a/submodules/TelegramUI/Components/ListActionItemComponent/Sources/ListActionItemComponent.swift b/submodules/TelegramUI/Components/ListActionItemComponent/Sources/ListActionItemComponent.swift index c149d857f3..43f978e590 100644 --- a/submodules/TelegramUI/Components/ListActionItemComponent/Sources/ListActionItemComponent.swift +++ b/submodules/TelegramUI/Components/ListActionItemComponent/Sources/ListActionItemComponent.swift @@ -83,10 +83,16 @@ public final class ListActionItemComponent: Component { public enum LeftIcon: Equatable { public final class Check: Equatable { public let isSelected: Bool + public let isEnabled: Bool public let toggle: (() -> Void)? - public init(isSelected: Bool, toggle: (() -> Void)?) { + public init( + isSelected: Bool, + isEnabled: Bool = true, + toggle: (() -> Void)? + ) { self.isSelected = isSelected + self.isEnabled = isEnabled self.toggle = toggle } @@ -97,6 +103,9 @@ public final class ListActionItemComponent: Component { if lhs.isSelected != rhs.isSelected { return false } + if lhs.isEnabled != rhs.isEnabled { + return false + } if (lhs.toggle == nil) != (rhs.toggle == nil) { return false } @@ -491,6 +500,7 @@ public final class ListActionItemComponent: Component { } leftCheckView.isUserInteractionEnabled = check.toggle != nil + leftCheckView.alpha = check.isEnabled ? 1.0 : 0.3 let checkSize = CGSize(width: 22.0, height: 22.0) let checkFrame = CGRect(origin: CGPoint(x: floor((contentLeftInset - checkSize.width) * 0.5), y: floor((contentHeight - checkSize.height) * 0.5)), size: checkSize) diff --git a/submodules/TelegramUI/Components/MessageInputPanelComponent/Sources/MessageInputPanelComponent.swift b/submodules/TelegramUI/Components/MessageInputPanelComponent/Sources/MessageInputPanelComponent.swift index 16994577f6..52492030e1 100644 --- a/submodules/TelegramUI/Components/MessageInputPanelComponent/Sources/MessageInputPanelComponent.swift +++ b/submodules/TelegramUI/Components/MessageInputPanelComponent/Sources/MessageInputPanelComponent.swift @@ -879,6 +879,7 @@ public final class MessageInputPanelComponent: Component { self.vibrancyPlaceholder.view?.removeFromSuperview() self.vibrancyPlaceholder = ComponentView() } + self.currentPlaceholderType = placeholderType let attributedPlaceholder = NSMutableAttributedString(string: string, font:Font.regular(17.0), textColor: UIColor(rgb: 0xffffff, alpha: 0.4)) if let range = attributedPlaceholder.string.range(of: "#") { @@ -916,6 +917,7 @@ public final class MessageInputPanelComponent: Component { self.vibrancyPlaceholder.view?.removeFromSuperview() self.vibrancyPlaceholder = ComponentView() } + self.currentPlaceholderType = placeholderType var placeholderItems: [AnimatedTextComponent.Item] = [] switch component.placeholder { diff --git a/submodules/TelegramUI/Components/Settings/ChatbotSetupScreen/Sources/ChatbotSetupScreen.swift b/submodules/TelegramUI/Components/Settings/ChatbotSetupScreen/Sources/ChatbotSetupScreen.swift index 44d355098a..2d8a980932 100644 --- a/submodules/TelegramUI/Components/Settings/ChatbotSetupScreen/Sources/ChatbotSetupScreen.swift +++ b/submodules/TelegramUI/Components/Settings/ChatbotSetupScreen/Sources/ChatbotSetupScreen.swift @@ -110,6 +110,24 @@ final class ChatbotSetupScreenComponent: Component { } } + final class Permission { + var id: String + var title: String + var value: Bool? + var enabled: Bool + var subpermissions: [Permission]? + var expanded: Bool? + + init(id: String, title: String, value: Bool? = nil, enabled: Bool = true, subpermissions: [Permission]? = nil, expanded: Bool? = nil) { + self.id = id + self.title = title + self.value = value + self.enabled = enabled + self.subpermissions = subpermissions + self.expanded = expanded + } + } + final class View: UIView, UIScrollViewDelegate { private let topOverscrollLayer = SimpleLayer() private let scrollView: ScrollView @@ -143,7 +161,9 @@ final class ChatbotSetupScreenComponent: Component { excludePeers: [] ) - private var replyToMessages: Bool = true + private var permissions: [Permission] = [] + + private var botRights: TelegramBusinessBotRights = [] override init(frame: CGRect) { self.scrollView = ScrollView() @@ -164,6 +184,30 @@ final class ChatbotSetupScreenComponent: Component { self.addSubview(self.scrollView) self.scrollView.layer.addSublayer(self.topOverscrollLayer) + + self.permissions = [ + Permission(id: "message", title: "Manage Messages", subpermissions: [ + Permission(id: "read", title: "Read Messages", value: true, enabled: false), + Permission(id: "reply", title: "Reply to Messages", value: true), + Permission(id: "mark", title: "Mark Messages as Read", value: true), + Permission(id: "deleteSent", title: "Delete Sent Messages", value: true), + Permission(id: "deleteReceived", title: "Delete Received Messages", value: true) + ], expanded: false), + Permission(id: "profile", title: "Manage Profile", subpermissions: [ + Permission(id: "name", title: "Edit Name", value: true), + Permission(id: "bio", title: "Edit Bio", value: true), + Permission(id: "avatar", title: "Edit Profile Picture", value: true), + Permission(id: "username", title: "Edit Username", value: true) + ], expanded: false), + Permission(id: "gifts", title: "Manage Gifts and Stars", subpermissions: [ + Permission(id: "view", title: "View Gifts", value: true), + Permission(id: "sell", title: "Sell Gifts", value: true), + Permission(id: "settings", title: "Change Gift Settings", value: true), + Permission(id: "transfer", title: "Transfer and Upgrade Gifts", value: true), + Permission(id: "transferStars", title: "Transfer Stars", value: true) + ], expanded: false), + Permission(id: "stories", title: "Manage Stories", value: true) + ] } required init?(coder: NSCoder) { @@ -206,7 +250,7 @@ final class ChatbotSetupScreenComponent: Component { let _ = component.context.engine.accountData.setAccountConnectedBot(bot: TelegramAccountConnectedBot( id: peer.id, recipients: recipients, - canReply: self.replyToMessages + rights: [] )).startStandalone() } else { let _ = component.context.engine.accountData.setAccountConnectedBot(bot: nil).startStandalone() @@ -487,7 +531,7 @@ final class ChatbotSetupScreenComponent: Component { self.botResolutionState = BotResolutionState(query: addressName, state: .found(peer: botPeer, isInstalled: true)) self.resetQueryText = addressName.lowercased() - self.replyToMessages = bot.canReply + self.botRights = bot.rights let initialRecipients = bot.recipients @@ -983,6 +1027,124 @@ final class ChatbotSetupScreenComponent: Component { if !self.hasAccessToAllChatsByDefault { contentHeight += excludedUsersContentHeight } + + var permissionsItems: [AnyComponentWithIdentity] = [] + + for permission in self.permissions { + var value = permission.value == true + + var titleItems: [AnyComponentWithIdentity] = [] + titleItems.append( + AnyComponentWithIdentity(id: AnyHashable(0), component: AnyComponent(MultilineTextComponent( + text: .plain(NSAttributedString( + string: permission.title, + font: Font.regular(presentationData.listsFontSize.baseDisplaySize), + textColor: environment.theme.list.itemPrimaryTextColor + )), + maximumNumberOfLines: 1 + ))) + ) + + if let subpermissions = permission.subpermissions { + value = false + var selectedCount = 0 + for subpermission in subpermissions { + if subpermission.value == true { + value = true + selectedCount += 1 + } + } + titleItems.append( + AnyComponentWithIdentity(id: AnyHashable(1), component: AnyComponent(MultilineTextComponent( + text: .plain(NSAttributedString( + string: "\(selectedCount)/\(subpermissions.count)", + font: Font.with(size: presentationData.listsFontSize.baseDisplaySize / 17.0 * 13.0, design: .round, weight: .semibold), + textColor: environment.theme.list.itemPrimaryTextColor + )), + maximumNumberOfLines: 1 + ))) + ) + titleItems.append( + AnyComponentWithIdentity(id: AnyHashable(2), component: AnyComponent(BundleIconComponent( + name: "Item List/ExpandingItemVerticalRegularArrow", + tintColor: environment.theme.list.itemPrimaryTextColor, + flipVertically: permission.expanded == true + ))) + ) + } + permissionsItems.append( + AnyComponentWithIdentity(id: permission.id, component: AnyComponent(ListActionItemComponent( + theme: environment.theme, + title: AnyComponent(HStack(titleItems, spacing: 6.0)), + accessory: .toggle(ListActionItemComponent.Toggle(style: .icons, isOn: value, action: { [weak self] value in + guard let self else { + return + } + if let subpermissions = permission.subpermissions { + for subpermission in subpermissions { + if subpermission.enabled { + subpermission.value = value + } + } + } else if let value = permission.value { + permission.value = value + } + self.state?.updated(transition: .spring(duration: 0.4)) + })), + action: permission.subpermissions != nil ? { [weak self] _ in + guard let self else { + return + } + var scrollToBottom = false + if let expanded = permission.expanded { + permission.expanded = !expanded + if !expanded { + scrollToBottom = true + } + } + self.state?.updated(transition: .spring(duration: 0.4)) + if scrollToBottom { + self.scrollView.setContentOffset(CGPoint(x: 0.0, y: self.scrollView.contentSize.height - self.scrollView.bounds.height), animated: true) + } + } : nil + ))) + ) + + if let subpermissions = permission.subpermissions, permission.expanded == true { + for subpermission in subpermissions { + permissionsItems.append( + AnyComponentWithIdentity(id: subpermission.id, component: AnyComponent(ListActionItemComponent( + theme: environment.theme, + title: AnyComponent(VStack([ + AnyComponentWithIdentity(id: AnyHashable(0), component: AnyComponent(MultilineTextComponent( + text: .plain(NSAttributedString( + string: subpermission.title, + font: Font.regular(presentationData.listsFontSize.baseDisplaySize), + textColor: environment.theme.list.itemPrimaryTextColor + )), + maximumNumberOfLines: 1 + ))), + ], alignment: .left, spacing: 2.0)), + leftIcon: .check(ListActionItemComponent.LeftIcon.Check(isSelected: subpermission.value == true, isEnabled: subpermission.enabled, toggle: nil)), + accessory: nil, + action: subpermission.enabled ? { [weak self] _ in + guard let self else { + return + } + if let value = subpermission.value { + subpermission.value = !value + } + self.state?.updated(transition: .spring(duration: 0.4)) + } : nil + ))) + ) + } + //permissionsItems.append(AnyComponentWithIdentity(id: "\(permission.id)_sub", component: AnyComponent(VStack(stackItems, spacing: 0.0)))) + } + } + + + let permissionsSectionSize = self.permissionsSection.update( transition: transition, @@ -1004,29 +1166,7 @@ final class ChatbotSetupScreenComponent: Component { )), maximumNumberOfLines: 0 )), - items: [ - AnyComponentWithIdentity(id: 0, component: AnyComponent(ListActionItemComponent( - theme: environment.theme, - title: AnyComponent(VStack([ - AnyComponentWithIdentity(id: AnyHashable(0), component: AnyComponent(MultilineTextComponent( - text: .plain(NSAttributedString( - string: environment.strings.ChatbotSetup_Permission_ReplyToMessages, - font: Font.regular(presentationData.listsFontSize.baseDisplaySize), - textColor: environment.theme.list.itemPrimaryTextColor - )), - maximumNumberOfLines: 1 - ))), - ], alignment: .left, spacing: 2.0)), - accessory: .toggle(ListActionItemComponent.Toggle(style: .icons, isOn: self.replyToMessages, action: { [weak self] _ in - guard let self else { - return - } - self.replyToMessages = !self.replyToMessages - self.state?.updated(transition: .spring(duration: 0.4)) - })), - action: nil - ))), - ] + items: permissionsItems )), environment: {}, containerSize: CGSize(width: availableSize.width - sideInset * 2.0, height: 10000.0)