From 545608e8d492e866297f54bbe2246838f37f1df4 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 13 Jan 2021 16:38:33 +0300 Subject: [PATCH] Update API [skip ci] --- .../SyncCore/Sources/ExportedInvitation.swift | 40 +- submodules/TelegramApi/Sources/Api0.swift | 18 +- submodules/TelegramApi/Sources/Api1.swift | 458 +++++++++++++----- submodules/TelegramApi/Sources/Api3.swift | 100 +++- .../Sources/ExportedInvitation.swift | 4 +- .../Sources/InvitationLinks.swift | 143 +++++- .../Sources/UpdateCachedPeerData.swift | 2 +- 7 files changed, 619 insertions(+), 146 deletions(-) diff --git a/submodules/SyncCore/Sources/ExportedInvitation.swift b/submodules/SyncCore/Sources/ExportedInvitation.swift index 29ff59ba9a..1a06cade2d 100644 --- a/submodules/SyncCore/Sources/ExportedInvitation.swift +++ b/submodules/SyncCore/Sources/ExportedInvitation.swift @@ -2,20 +2,56 @@ import Postbox public struct ExportedInvitation: PostboxCoding, Equatable { public let link: String + public let revoked: Bool + public let adminId: PeerId + public let date: Int32 + public let expireDate: Int32? + public let usageLimit: Int32? + public let count: Int32? - public init(link: String) { + public init(link: String, revoked: Bool, adminId: PeerId, date: Int32, expireDate: Int32?, usageLimit: Int32?, count: Int32?) { self.link = link + self.revoked = revoked + self.adminId = adminId + self.date = date + self.expireDate = expireDate + self.usageLimit = usageLimit + self.count = count } public init(decoder: PostboxDecoder) { self.link = decoder.decodeStringForKey("l", orElse: "") + self.revoked = decoder.decodeBoolForKey("revoked", orElse: false) + self.adminId = PeerId(decoder.decodeInt64ForKey("adminId", orElse: 0)) + self.date = decoder.decodeInt32ForKey("date", orElse: 0) + self.expireDate = decoder.decodeOptionalInt32ForKey("expireDate") + self.usageLimit = decoder.decodeOptionalInt32ForKey("usageLimit") + self.count = decoder.decodeOptionalInt32ForKey("count") } public func encode(_ encoder: PostboxEncoder) { encoder.encodeString(self.link, forKey: "l") + encoder.encodeBool(self.revoked, forKey: "revoked") + encoder.encodeInt64(self.adminId.toInt64(), forKey: "adminId") + encoder.encodeInt32(self.date, forKey: "date") + if let expireDate = self.expireDate { + encoder.encodeInt32(expireDate, forKey: "expireDate") + } else { + encoder.encodeNil(forKey: "expireDate") + } + if let usageLimit = self.usageLimit { + encoder.encodeInt32(usageLimit, forKey: "usageLimit") + } else { + encoder.encodeNil(forKey: "usageLimit") + } + if let count = self.count { + encoder.encodeInt32(count, forKey: "count") + } else { + encoder.encodeNil(forKey: "count") + } } public static func ==(lhs: ExportedInvitation, rhs: ExportedInvitation) -> Bool { - return lhs.link == rhs.link + return lhs.link == rhs.link && lhs.revoked == rhs.revoked && lhs.adminId == rhs.adminId && lhs.date == rhs.date && lhs.expireDate == rhs.expireDate && lhs.usageLimit == rhs.usageLimit && lhs.count == rhs.count } } diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index 585cbfb49b..12416d20aa 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -11,8 +11,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-457104426] = { return Api.InputGeoPoint.parse_inputGeoPointEmpty($0) } dict[1210199983] = { return Api.InputGeoPoint.parse_inputGeoPoint($0) } dict[-784000893] = { return Api.payments.ValidatedRequestedInfo.parse_validatedRequestedInfo($0) } - dict[-281384243] = { return Api.ChatFull.parse_channelFull($0) } dict[231260545] = { return Api.ChatFull.parse_chatFull($0) } + dict[2055070967] = { return Api.ChatFull.parse_channelFull($0) } dict[-1159937629] = { return Api.PollResults.parse_pollResults($0) } dict[-925415106] = { return Api.ChatParticipant.parse_chatParticipant($0) } dict[-636267638] = { return Api.ChatParticipant.parse_chatParticipantCreator($0) } @@ -150,6 +150,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1649296275] = { return Api.Peer.parse_peerUser($0) } dict[-1160714821] = { return Api.Peer.parse_peerChat($0) } dict[-1109531342] = { return Api.Peer.parse_peerChannel($0) } + dict[-1748638807] = { return Api.messages.ExportedChatInvite.parse_exportedChatInvite($0) } dict[-1868808300] = { return Api.PaymentRequestedInfo.parse_paymentRequestedInfo($0) } dict[164646985] = { return Api.UserStatus.parse_userStatusEmpty($0) } dict[-306628279] = { return Api.UserStatus.parse_userStatusOnline($0) } @@ -348,6 +349,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1768777083] = { return Api.InputBotInlineMessage.parse_inputBotInlineMessageMediaGeo($0) } dict[2002815875] = { return Api.KeyboardButtonRow.parse_keyboardButtonRow($0) } dict[1088567208] = { return Api.StickerSet.parse_stickerSet($0) } + dict[-1111085620] = { return Api.messages.ExportedChatInvites.parse_exportedChatInvites($0) } dict[354925740] = { return Api.SecureSecretSettings.parse_secureSecretSettings($0) } dict[539045032] = { return Api.photos.Photo.parse_photo($0) } dict[-208488460] = { return Api.InputContact.parse_inputPhoneContact($0) } @@ -404,6 +406,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-666824391] = { return Api.payments.PaymentResult.parse_paymentVerificationNeeded($0) } dict[1694474197] = { return Api.messages.Chats.parse_chats($0) } dict[-1663561404] = { return Api.messages.Chats.parse_chatsSlice($0) } + dict[-2118733814] = { return Api.messages.ChatInviteImporters.parse_chatInviteImporters($0) } dict[-659913713] = { return Api.InputGroupCall.parse_inputGroupCall($0) } dict[482797855] = { return Api.InputSingleMedia.parse_inputSingleMedia($0) } dict[1163625789] = { return Api.MessageViews.parse_messageViews($0) } @@ -543,6 +546,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1032140601] = { return Api.BotCommand.parse_botCommand($0) } dict[1474462241] = { return Api.account.ContentSettings.parse_contentSettings($0) } dict[-1661028051] = { return Api.phone.GroupParticipants.parse_groupParticipants($0) } + dict[507405952] = { return Api.ChatInviteImporter.parse_chatInviteImporter($0) } dict[-2066640507] = { return Api.messages.AffectedMessages.parse_affectedMessages($0) } dict[-402498398] = { return Api.messages.SavedGifs.parse_savedGifsNotModified($0) } dict[772213157] = { return Api.messages.SavedGifs.parse_savedGifs($0) } @@ -652,7 +656,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1056001329] = { return Api.InputPaymentCredentials.parse_inputPaymentCredentialsSaved($0) } dict[873977640] = { return Api.InputPaymentCredentials.parse_inputPaymentCredentials($0) } dict[178373535] = { return Api.InputPaymentCredentials.parse_inputPaymentCredentialsApplePay($0) } - dict[-1966921727] = { return Api.InputPaymentCredentials.parse_inputPaymentCredentialsGooglePay($0) } + dict[-905587442] = { return Api.InputPaymentCredentials.parse_inputPaymentCredentialsAndroidPay($0) } dict[-1239335713] = { return Api.ShippingOption.parse_shippingOption($0) } dict[859091184] = { return Api.InputSecureFile.parse_inputSecureFileUploaded($0) } dict[1399317950] = { return Api.InputSecureFile.parse_inputSecureFile($0) } @@ -733,7 +737,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1634752813] = { return Api.messages.FavedStickers.parse_favedStickersNotModified($0) } dict[-209768682] = { return Api.messages.FavedStickers.parse_favedStickers($0) } dict[1776236393] = { return Api.ExportedChatInvite.parse_chatInviteEmpty($0) } - dict[-64092740] = { return Api.ExportedChatInvite.parse_chatInviteExported($0) } + dict[-1448589334] = { return Api.ExportedChatInvite.parse_chatInviteExported($0) } dict[-1389486888] = { return Api.account.AuthorizationForm.parse_authorizationForm($0) } dict[-1392388579] = { return Api.Authorization.parse_authorization($0) } dict[-1361650766] = { return Api.MaskCoords.parse_maskCoords($0) } @@ -1032,6 +1036,8 @@ public struct Api { _1.serialize(buffer, boxed) case let _1 as Api.Peer: _1.serialize(buffer, boxed) + case let _1 as Api.messages.ExportedChatInvite: + _1.serialize(buffer, boxed) case let _1 as Api.PaymentRequestedInfo: _1.serialize(buffer, boxed) case let _1 as Api.UserStatus: @@ -1104,6 +1110,8 @@ public struct Api { _1.serialize(buffer, boxed) case let _1 as Api.StickerSet: _1.serialize(buffer, boxed) + case let _1 as Api.messages.ExportedChatInvites: + _1.serialize(buffer, boxed) case let _1 as Api.SecureSecretSettings: _1.serialize(buffer, boxed) case let _1 as Api.photos.Photo: @@ -1150,6 +1158,8 @@ public struct Api { _1.serialize(buffer, boxed) case let _1 as Api.messages.Chats: _1.serialize(buffer, boxed) + case let _1 as Api.messages.ChatInviteImporters: + _1.serialize(buffer, boxed) case let _1 as Api.InputGroupCall: _1.serialize(buffer, boxed) case let _1 as Api.InputSingleMedia: @@ -1278,6 +1288,8 @@ public struct Api { _1.serialize(buffer, boxed) case let _1 as Api.phone.GroupParticipants: _1.serialize(buffer, boxed) + case let _1 as Api.ChatInviteImporter: + _1.serialize(buffer, boxed) case let _1 as Api.messages.AffectedMessages: _1.serialize(buffer, boxed) case let _1 as Api.messages.SavedGifs: diff --git a/submodules/TelegramApi/Sources/Api1.swift b/submodules/TelegramApi/Sources/Api1.swift index 25153c7275..63f857aced 100644 --- a/submodules/TelegramApi/Sources/Api1.swift +++ b/submodules/TelegramApi/Sources/Api1.swift @@ -219,6 +219,62 @@ public struct messages { } } + } + public enum ExportedChatInvite: TypeConstructorDescription { + case exportedChatInvite(invite: Api.ExportedChatInvite, recentImporters: [Int32], users: [Api.User]) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .exportedChatInvite(let invite, let recentImporters, let users): + if boxed { + buffer.appendInt32(-1748638807) + } + invite.serialize(buffer, true) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(recentImporters.count)) + for item in recentImporters { + serializeInt32(item, buffer: buffer, boxed: false) + } + 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 .exportedChatInvite(let invite, let recentImporters, let users): + return ("exportedChatInvite", [("invite", invite), ("recentImporters", recentImporters), ("users", users)]) + } + } + + public static func parse_exportedChatInvite(_ reader: BufferReader) -> ExportedChatInvite? { + var _1: Api.ExportedChatInvite? + if let signature = reader.readInt32() { + _1 = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite + } + var _2: [Int32]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: -1471112230, elementType: Int32.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.messages.ExportedChatInvite.exportedChatInvite(invite: _1!, recentImporters: _2!, users: _3!) + } + else { + return nil + } + } + } public enum VotesList: TypeConstructorDescription { case votesList(flags: Int32, count: Int32, votes: [Api.MessageUserVote], users: [Api.User], nextOffset: String?) @@ -437,6 +493,60 @@ public struct messages { } } + } + public enum ExportedChatInvites: TypeConstructorDescription { + case exportedChatInvites(count: Int32, invites: [Api.ExportedChatInvite], users: [Api.User]) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .exportedChatInvites(let count, let invites, let users): + if boxed { + buffer.appendInt32(-1111085620) + } + serializeInt32(count, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(invites.count)) + for item in invites { + 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 .exportedChatInvites(let count, let invites, let users): + return ("exportedChatInvites", [("count", count), ("invites", invites), ("users", users)]) + } + } + + public static func parse_exportedChatInvites(_ reader: BufferReader) -> ExportedChatInvites? { + var _1: Int32? + _1 = reader.readInt32() + var _2: [Api.ExportedChatInvite]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.ExportedChatInvite.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.messages.ExportedChatInvites.exportedChatInvites(count: _1!, invites: _2!, users: _3!) + } + else { + return nil + } + } + } public enum BotResults: TypeConstructorDescription { case botResults(flags: Int32, queryId: Int64, nextOffset: String?, switchPm: Api.InlineBotSwitchPM?, results: [Api.BotInlineResult], cacheTime: Int32, users: [Api.User]) @@ -625,6 +735,60 @@ public struct messages { } } + } + public enum ChatInviteImporters: TypeConstructorDescription { + case chatInviteImporters(count: Int32, importers: [Api.ChatInviteImporter], users: [Api.User]) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .chatInviteImporters(let count, let importers, let users): + if boxed { + buffer.appendInt32(-2118733814) + } + serializeInt32(count, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(importers.count)) + for item in importers { + 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 .chatInviteImporters(let count, let importers, let users): + return ("chatInviteImporters", [("count", count), ("importers", importers), ("users", users)]) + } + } + + public static func parse_chatInviteImporters(_ reader: BufferReader) -> ChatInviteImporters? { + var _1: Int32? + _1 = reader.readInt32() + var _2: [Api.ChatInviteImporter]? + if let _ = reader.readInt32() { + _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.ChatInviteImporter.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.messages.ChatInviteImporters.chatInviteImporters(count: _1!, importers: _2!, users: _3!) + } + else { + return nil + } + } + } public enum DhConfig: TypeConstructorDescription { case dhConfigNotModified(random: Buffer) @@ -2052,48 +2216,11 @@ public extension Api { } public enum ChatFull: TypeConstructorDescription { - case channelFull(flags: Int32, id: Int32, about: String, participantsCount: Int32?, adminsCount: Int32?, kickedCount: Int32?, bannedCount: Int32?, onlineCount: Int32?, readInboxMaxId: Int32, readOutboxMaxId: Int32, unreadCount: Int32, chatPhoto: Api.Photo, notifySettings: Api.PeerNotifySettings, exportedInvite: Api.ExportedChatInvite, botInfo: [Api.BotInfo], migratedFromChatId: Int32?, migratedFromMaxId: Int32?, pinnedMsgId: Int32?, stickerset: Api.StickerSet?, availableMinId: Int32?, folderId: Int32?, linkedChatId: Int32?, location: Api.ChannelLocation?, slowmodeSeconds: Int32?, slowmodeNextSendDate: Int32?, statsDc: Int32?, pts: Int32, call: Api.InputGroupCall?) case chatFull(flags: Int32, id: Int32, about: String, participants: Api.ChatParticipants, chatPhoto: Api.Photo?, notifySettings: Api.PeerNotifySettings, exportedInvite: Api.ExportedChatInvite, botInfo: [Api.BotInfo]?, pinnedMsgId: Int32?, folderId: Int32?, call: Api.InputGroupCall?) + case channelFull(flags: Int32, id: Int32, about: String, participantsCount: Int32?, adminsCount: Int32?, kickedCount: Int32?, bannedCount: Int32?, onlineCount: Int32?, readInboxMaxId: Int32, readOutboxMaxId: Int32, unreadCount: Int32, chatPhoto: Api.Photo, notifySettings: Api.PeerNotifySettings, exportedInvite: Api.ExportedChatInvite?, botInfo: [Api.BotInfo], migratedFromChatId: Int32?, migratedFromMaxId: Int32?, pinnedMsgId: Int32?, stickerset: Api.StickerSet?, availableMinId: Int32?, folderId: Int32?, linkedChatId: Int32?, location: Api.ChannelLocation?, slowmodeSeconds: Int32?, slowmodeNextSendDate: Int32?, statsDc: Int32?, pts: Int32, call: Api.InputGroupCall?) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .channelFull(let flags, let id, let about, let participantsCount, let adminsCount, let kickedCount, let bannedCount, let onlineCount, let readInboxMaxId, let readOutboxMaxId, let unreadCount, let chatPhoto, let notifySettings, let exportedInvite, let botInfo, let migratedFromChatId, let migratedFromMaxId, let pinnedMsgId, let stickerset, let availableMinId, let folderId, let linkedChatId, let location, let slowmodeSeconds, let slowmodeNextSendDate, let statsDc, let pts, let call): - if boxed { - buffer.appendInt32(-281384243) - } - serializeInt32(flags, buffer: buffer, boxed: false) - serializeInt32(id, buffer: buffer, boxed: false) - serializeString(about, buffer: buffer, boxed: false) - if Int(flags) & Int(1 << 0) != 0 {serializeInt32(participantsCount!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 1) != 0 {serializeInt32(adminsCount!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 2) != 0 {serializeInt32(kickedCount!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 2) != 0 {serializeInt32(bannedCount!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 13) != 0 {serializeInt32(onlineCount!, buffer: buffer, boxed: false)} - serializeInt32(readInboxMaxId, buffer: buffer, boxed: false) - serializeInt32(readOutboxMaxId, buffer: buffer, boxed: false) - serializeInt32(unreadCount, buffer: buffer, boxed: false) - chatPhoto.serialize(buffer, true) - notifySettings.serialize(buffer, true) - exportedInvite.serialize(buffer, true) - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(botInfo.count)) - for item in botInfo { - item.serialize(buffer, true) - } - if Int(flags) & Int(1 << 4) != 0 {serializeInt32(migratedFromChatId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 4) != 0 {serializeInt32(migratedFromMaxId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 5) != 0 {serializeInt32(pinnedMsgId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 8) != 0 {stickerset!.serialize(buffer, true)} - if Int(flags) & Int(1 << 9) != 0 {serializeInt32(availableMinId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 11) != 0 {serializeInt32(folderId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 14) != 0 {serializeInt32(linkedChatId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 15) != 0 {location!.serialize(buffer, true)} - if Int(flags) & Int(1 << 17) != 0 {serializeInt32(slowmodeSeconds!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 18) != 0 {serializeInt32(slowmodeNextSendDate!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 12) != 0 {serializeInt32(statsDc!, buffer: buffer, boxed: false)} - serializeInt32(pts, buffer: buffer, boxed: false) - if Int(flags) & Int(1 << 21) != 0 {call!.serialize(buffer, true)} - break case .chatFull(let flags, let id, let about, let participants, let chatPhoto, let notifySettings, let exportedInvite, let botInfo, let pinnedMsgId, let folderId, let call): if boxed { buffer.appendInt32(231260545) @@ -2114,18 +2241,108 @@ public extension Api { if Int(flags) & Int(1 << 11) != 0 {serializeInt32(folderId!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 12) != 0 {call!.serialize(buffer, true)} break + case .channelFull(let flags, let id, let about, let participantsCount, let adminsCount, let kickedCount, let bannedCount, let onlineCount, let readInboxMaxId, let readOutboxMaxId, let unreadCount, let chatPhoto, let notifySettings, let exportedInvite, let botInfo, let migratedFromChatId, let migratedFromMaxId, let pinnedMsgId, let stickerset, let availableMinId, let folderId, let linkedChatId, let location, let slowmodeSeconds, let slowmodeNextSendDate, let statsDc, let pts, let call): + if boxed { + buffer.appendInt32(2055070967) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(id, buffer: buffer, boxed: false) + serializeString(about, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {serializeInt32(participantsCount!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 1) != 0 {serializeInt32(adminsCount!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 2) != 0 {serializeInt32(kickedCount!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 2) != 0 {serializeInt32(bannedCount!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 13) != 0 {serializeInt32(onlineCount!, buffer: buffer, boxed: false)} + serializeInt32(readInboxMaxId, buffer: buffer, boxed: false) + serializeInt32(readOutboxMaxId, buffer: buffer, boxed: false) + serializeInt32(unreadCount, buffer: buffer, boxed: false) + chatPhoto.serialize(buffer, true) + notifySettings.serialize(buffer, true) + if Int(flags) & Int(1 << 23) != 0 {exportedInvite!.serialize(buffer, true)} + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(botInfo.count)) + for item in botInfo { + item.serialize(buffer, true) + } + if Int(flags) & Int(1 << 4) != 0 {serializeInt32(migratedFromChatId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 4) != 0 {serializeInt32(migratedFromMaxId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 5) != 0 {serializeInt32(pinnedMsgId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 8) != 0 {stickerset!.serialize(buffer, true)} + if Int(flags) & Int(1 << 9) != 0 {serializeInt32(availableMinId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 11) != 0 {serializeInt32(folderId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 14) != 0 {serializeInt32(linkedChatId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 15) != 0 {location!.serialize(buffer, true)} + if Int(flags) & Int(1 << 17) != 0 {serializeInt32(slowmodeSeconds!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 18) != 0 {serializeInt32(slowmodeNextSendDate!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 12) != 0 {serializeInt32(statsDc!, buffer: buffer, boxed: false)} + serializeInt32(pts, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 21) != 0 {call!.serialize(buffer, true)} + break } } public func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .channelFull(let flags, let id, let about, let participantsCount, let adminsCount, let kickedCount, let bannedCount, let onlineCount, let readInboxMaxId, let readOutboxMaxId, let unreadCount, let chatPhoto, let notifySettings, let exportedInvite, let botInfo, let migratedFromChatId, let migratedFromMaxId, let pinnedMsgId, let stickerset, let availableMinId, let folderId, let linkedChatId, let location, let slowmodeSeconds, let slowmodeNextSendDate, let statsDc, let pts, let call): - return ("channelFull", [("flags", flags), ("id", id), ("about", about), ("participantsCount", participantsCount), ("adminsCount", adminsCount), ("kickedCount", kickedCount), ("bannedCount", bannedCount), ("onlineCount", onlineCount), ("readInboxMaxId", readInboxMaxId), ("readOutboxMaxId", readOutboxMaxId), ("unreadCount", unreadCount), ("chatPhoto", chatPhoto), ("notifySettings", notifySettings), ("exportedInvite", exportedInvite), ("botInfo", botInfo), ("migratedFromChatId", migratedFromChatId), ("migratedFromMaxId", migratedFromMaxId), ("pinnedMsgId", pinnedMsgId), ("stickerset", stickerset), ("availableMinId", availableMinId), ("folderId", folderId), ("linkedChatId", linkedChatId), ("location", location), ("slowmodeSeconds", slowmodeSeconds), ("slowmodeNextSendDate", slowmodeNextSendDate), ("statsDc", statsDc), ("pts", pts), ("call", call)]) case .chatFull(let flags, let id, let about, let participants, let chatPhoto, let notifySettings, let exportedInvite, let botInfo, let pinnedMsgId, let folderId, let call): return ("chatFull", [("flags", flags), ("id", id), ("about", about), ("participants", participants), ("chatPhoto", chatPhoto), ("notifySettings", notifySettings), ("exportedInvite", exportedInvite), ("botInfo", botInfo), ("pinnedMsgId", pinnedMsgId), ("folderId", folderId), ("call", call)]) + case .channelFull(let flags, let id, let about, let participantsCount, let adminsCount, let kickedCount, let bannedCount, let onlineCount, let readInboxMaxId, let readOutboxMaxId, let unreadCount, let chatPhoto, let notifySettings, let exportedInvite, let botInfo, let migratedFromChatId, let migratedFromMaxId, let pinnedMsgId, let stickerset, let availableMinId, let folderId, let linkedChatId, let location, let slowmodeSeconds, let slowmodeNextSendDate, let statsDc, let pts, let call): + return ("channelFull", [("flags", flags), ("id", id), ("about", about), ("participantsCount", participantsCount), ("adminsCount", adminsCount), ("kickedCount", kickedCount), ("bannedCount", bannedCount), ("onlineCount", onlineCount), ("readInboxMaxId", readInboxMaxId), ("readOutboxMaxId", readOutboxMaxId), ("unreadCount", unreadCount), ("chatPhoto", chatPhoto), ("notifySettings", notifySettings), ("exportedInvite", exportedInvite), ("botInfo", botInfo), ("migratedFromChatId", migratedFromChatId), ("migratedFromMaxId", migratedFromMaxId), ("pinnedMsgId", pinnedMsgId), ("stickerset", stickerset), ("availableMinId", availableMinId), ("folderId", folderId), ("linkedChatId", linkedChatId), ("location", location), ("slowmodeSeconds", slowmodeSeconds), ("slowmodeNextSendDate", slowmodeNextSendDate), ("statsDc", statsDc), ("pts", pts), ("call", call)]) } } + public static func parse_chatFull(_ reader: BufferReader) -> ChatFull? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: String? + _3 = parseString(reader) + var _4: Api.ChatParticipants? + if let signature = reader.readInt32() { + _4 = Api.parse(reader, signature: signature) as? Api.ChatParticipants + } + var _5: Api.Photo? + if Int(_1!) & Int(1 << 2) != 0 {if let signature = reader.readInt32() { + _5 = Api.parse(reader, signature: signature) as? Api.Photo + } } + var _6: Api.PeerNotifySettings? + if let signature = reader.readInt32() { + _6 = Api.parse(reader, signature: signature) as? Api.PeerNotifySettings + } + var _7: Api.ExportedChatInvite? + if let signature = reader.readInt32() { + _7 = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite + } + var _8: [Api.BotInfo]? + if Int(_1!) & Int(1 << 3) != 0 {if let _ = reader.readInt32() { + _8 = Api.parseVector(reader, elementSignature: 0, elementType: Api.BotInfo.self) + } } + var _9: Int32? + if Int(_1!) & Int(1 << 6) != 0 {_9 = reader.readInt32() } + var _10: Int32? + if Int(_1!) & Int(1 << 11) != 0 {_10 = reader.readInt32() } + var _11: Api.InputGroupCall? + if Int(_1!) & Int(1 << 12) != 0 {if let signature = reader.readInt32() { + _11 = Api.parse(reader, signature: signature) as? Api.InputGroupCall + } } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = (Int(_1!) & Int(1 << 2) == 0) || _5 != nil + let _c6 = _6 != nil + let _c7 = _7 != nil + let _c8 = (Int(_1!) & Int(1 << 3) == 0) || _8 != nil + let _c9 = (Int(_1!) & Int(1 << 6) == 0) || _9 != nil + let _c10 = (Int(_1!) & Int(1 << 11) == 0) || _10 != nil + let _c11 = (Int(_1!) & Int(1 << 12) == 0) || _11 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 { + return Api.ChatFull.chatFull(flags: _1!, id: _2!, about: _3!, participants: _4!, chatPhoto: _5, notifySettings: _6!, exportedInvite: _7!, botInfo: _8, pinnedMsgId: _9, folderId: _10, call: _11) + } + else { + return nil + } + } public static func parse_channelFull(_ reader: BufferReader) -> ChatFull? { var _1: Int32? _1 = reader.readInt32() @@ -2158,9 +2375,9 @@ public extension Api { _13 = Api.parse(reader, signature: signature) as? Api.PeerNotifySettings } var _14: Api.ExportedChatInvite? - if let signature = reader.readInt32() { + if Int(_1!) & Int(1 << 23) != 0 {if let signature = reader.readInt32() { _14 = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite - } + } } var _15: [Api.BotInfo]? if let _ = reader.readInt32() { _15 = Api.parseVector(reader, elementSignature: 0, elementType: Api.BotInfo.self) @@ -2210,7 +2427,7 @@ public extension Api { let _c11 = _11 != nil let _c12 = _12 != nil let _c13 = _13 != nil - let _c14 = _14 != nil + let _c14 = (Int(_1!) & Int(1 << 23) == 0) || _14 != nil let _c15 = _15 != nil let _c16 = (Int(_1!) & Int(1 << 4) == 0) || _16 != nil let _c17 = (Int(_1!) & Int(1 << 4) == 0) || _17 != nil @@ -2226,60 +2443,7 @@ public extension Api { let _c27 = _27 != nil let _c28 = (Int(_1!) & Int(1 << 21) == 0) || _28 != 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 { - return Api.ChatFull.channelFull(flags: _1!, id: _2!, about: _3!, participantsCount: _4, adminsCount: _5, kickedCount: _6, bannedCount: _7, onlineCount: _8, readInboxMaxId: _9!, readOutboxMaxId: _10!, unreadCount: _11!, chatPhoto: _12!, notifySettings: _13!, exportedInvite: _14!, botInfo: _15!, migratedFromChatId: _16, migratedFromMaxId: _17, pinnedMsgId: _18, stickerset: _19, availableMinId: _20, folderId: _21, linkedChatId: _22, location: _23, slowmodeSeconds: _24, slowmodeNextSendDate: _25, statsDc: _26, pts: _27!, call: _28) - } - else { - return nil - } - } - public static func parse_chatFull(_ reader: BufferReader) -> ChatFull? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Int32? - _2 = reader.readInt32() - var _3: String? - _3 = parseString(reader) - var _4: Api.ChatParticipants? - if let signature = reader.readInt32() { - _4 = Api.parse(reader, signature: signature) as? Api.ChatParticipants - } - var _5: Api.Photo? - if Int(_1!) & Int(1 << 2) != 0 {if let signature = reader.readInt32() { - _5 = Api.parse(reader, signature: signature) as? Api.Photo - } } - var _6: Api.PeerNotifySettings? - if let signature = reader.readInt32() { - _6 = Api.parse(reader, signature: signature) as? Api.PeerNotifySettings - } - var _7: Api.ExportedChatInvite? - if let signature = reader.readInt32() { - _7 = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite - } - var _8: [Api.BotInfo]? - if Int(_1!) & Int(1 << 3) != 0 {if let _ = reader.readInt32() { - _8 = Api.parseVector(reader, elementSignature: 0, elementType: Api.BotInfo.self) - } } - var _9: Int32? - if Int(_1!) & Int(1 << 6) != 0 {_9 = reader.readInt32() } - var _10: Int32? - if Int(_1!) & Int(1 << 11) != 0 {_10 = reader.readInt32() } - var _11: Api.InputGroupCall? - if Int(_1!) & Int(1 << 12) != 0 {if let signature = reader.readInt32() { - _11 = Api.parse(reader, signature: signature) as? Api.InputGroupCall - } } - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = _3 != nil - let _c4 = _4 != nil - let _c5 = (Int(_1!) & Int(1 << 2) == 0) || _5 != nil - let _c6 = _6 != nil - let _c7 = _7 != nil - let _c8 = (Int(_1!) & Int(1 << 3) == 0) || _8 != nil - let _c9 = (Int(_1!) & Int(1 << 6) == 0) || _9 != nil - let _c10 = (Int(_1!) & Int(1 << 11) == 0) || _10 != nil - let _c11 = (Int(_1!) & Int(1 << 12) == 0) || _11 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 { - return Api.ChatFull.chatFull(flags: _1!, id: _2!, about: _3!, participants: _4!, chatPhoto: _5, notifySettings: _6!, exportedInvite: _7!, botInfo: _8, pinnedMsgId: _9, folderId: _10, call: _11) + return Api.ChatFull.channelFull(flags: _1!, id: _2!, about: _3!, participantsCount: _4, adminsCount: _5, kickedCount: _6, bannedCount: _7, onlineCount: _8, readInboxMaxId: _9!, readOutboxMaxId: _10!, unreadCount: _11!, chatPhoto: _12!, notifySettings: _13!, exportedInvite: _14, botInfo: _15!, migratedFromChatId: _16, migratedFromMaxId: _17, pinnedMsgId: _18, stickerset: _19, availableMinId: _20, folderId: _21, linkedChatId: _22, location: _23, slowmodeSeconds: _24, slowmodeNextSendDate: _25, statsDc: _26, pts: _27!, call: _28) } else { return nil @@ -15864,6 +16028,44 @@ public extension Api { } } + } + public enum ChatInviteImporter: TypeConstructorDescription { + case chatInviteImporter(userId: Int32, date: Int32) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .chatInviteImporter(let userId, let date): + if boxed { + buffer.appendInt32(507405952) + } + serializeInt32(userId, buffer: buffer, boxed: false) + serializeInt32(date, buffer: buffer, boxed: false) + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .chatInviteImporter(let userId, let date): + return ("chatInviteImporter", [("userId", userId), ("date", date)]) + } + } + + public static func parse_chatInviteImporter(_ reader: BufferReader) -> ChatInviteImporter? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.ChatInviteImporter.chatInviteImporter(userId: _1!, date: _2!) + } + else { + return nil + } + } + } public enum CdnPublicKey: TypeConstructorDescription { case cdnPublicKey(dcId: Int32, publicKey: String) @@ -18921,7 +19123,7 @@ public extension Api { case inputPaymentCredentialsSaved(id: String, tmpPassword: Buffer) case inputPaymentCredentials(flags: Int32, data: Api.DataJSON) case inputPaymentCredentialsApplePay(paymentData: Api.DataJSON) - case inputPaymentCredentialsGooglePay(paymentToken: Api.DataJSON) + case inputPaymentCredentialsAndroidPay(paymentToken: Api.DataJSON, googleTransactionId: String) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -18945,11 +19147,12 @@ public extension Api { } paymentData.serialize(buffer, true) break - case .inputPaymentCredentialsGooglePay(let paymentToken): + case .inputPaymentCredentialsAndroidPay(let paymentToken, let googleTransactionId): if boxed { - buffer.appendInt32(-1966921727) + buffer.appendInt32(-905587442) } paymentToken.serialize(buffer, true) + serializeString(googleTransactionId, buffer: buffer, boxed: false) break } } @@ -18962,8 +19165,8 @@ public extension Api { return ("inputPaymentCredentials", [("flags", flags), ("data", data)]) case .inputPaymentCredentialsApplePay(let paymentData): return ("inputPaymentCredentialsApplePay", [("paymentData", paymentData)]) - case .inputPaymentCredentialsGooglePay(let paymentToken): - return ("inputPaymentCredentialsGooglePay", [("paymentToken", paymentToken)]) + case .inputPaymentCredentialsAndroidPay(let paymentToken, let googleTransactionId): + return ("inputPaymentCredentialsAndroidPay", [("paymentToken", paymentToken), ("googleTransactionId", googleTransactionId)]) } } @@ -19010,14 +19213,17 @@ public extension Api { return nil } } - public static func parse_inputPaymentCredentialsGooglePay(_ reader: BufferReader) -> InputPaymentCredentials? { + public static func parse_inputPaymentCredentialsAndroidPay(_ reader: BufferReader) -> InputPaymentCredentials? { var _1: Api.DataJSON? if let signature = reader.readInt32() { _1 = Api.parse(reader, signature: signature) as? Api.DataJSON } + var _2: String? + _2 = parseString(reader) let _c1 = _1 != nil - if _c1 { - return Api.InputPaymentCredentials.inputPaymentCredentialsGooglePay(paymentToken: _1!) + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.InputPaymentCredentials.inputPaymentCredentialsAndroidPay(paymentToken: _1!, googleTransactionId: _2!) } else { return nil @@ -20783,7 +20989,7 @@ public extension Api { } public enum ExportedChatInvite: TypeConstructorDescription { case chatInviteEmpty - case chatInviteExported(link: String) + case chatInviteExported(flags: Int32, link: String, adminId: Int32, date: Int32, expireDate: Int32?, usageLimit: Int32?, usage: Int32?) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -20793,11 +20999,17 @@ public extension Api { } break - case .chatInviteExported(let link): + case .chatInviteExported(let flags, let link, let adminId, let date, let expireDate, let usageLimit, let usage): if boxed { - buffer.appendInt32(-64092740) + buffer.appendInt32(-1448589334) } + serializeInt32(flags, buffer: buffer, boxed: false) serializeString(link, buffer: buffer, boxed: false) + serializeInt32(adminId, buffer: buffer, boxed: false) + serializeInt32(date, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 1) != 0 {serializeInt32(expireDate!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 2) != 0 {serializeInt32(usageLimit!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 3) != 0 {serializeInt32(usage!, buffer: buffer, boxed: false)} break } } @@ -20806,8 +21018,8 @@ public extension Api { switch self { case .chatInviteEmpty: return ("chatInviteEmpty", []) - case .chatInviteExported(let link): - return ("chatInviteExported", [("link", link)]) + case .chatInviteExported(let flags, let link, let adminId, let date, let expireDate, let usageLimit, let usage): + return ("chatInviteExported", [("flags", flags), ("link", link), ("adminId", adminId), ("date", date), ("expireDate", expireDate), ("usageLimit", usageLimit), ("usage", usage)]) } } @@ -20815,11 +21027,29 @@ public extension Api { return Api.ExportedChatInvite.chatInviteEmpty } public static func parse_chatInviteExported(_ reader: BufferReader) -> ExportedChatInvite? { - var _1: String? - _1 = parseString(reader) + var _1: Int32? + _1 = reader.readInt32() + var _2: String? + _2 = parseString(reader) + var _3: Int32? + _3 = reader.readInt32() + var _4: Int32? + _4 = reader.readInt32() + var _5: Int32? + if Int(_1!) & Int(1 << 1) != 0 {_5 = reader.readInt32() } + var _6: Int32? + if Int(_1!) & Int(1 << 2) != 0 {_6 = reader.readInt32() } + var _7: Int32? + if Int(_1!) & Int(1 << 3) != 0 {_7 = reader.readInt32() } let _c1 = _1 != nil - if _c1 { - return Api.ExportedChatInvite.chatInviteExported(link: _1!) + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = (Int(_1!) & Int(1 << 1) == 0) || _5 != nil + let _c6 = (Int(_1!) & Int(1 << 2) == 0) || _6 != nil + let _c7 = (Int(_1!) & Int(1 << 3) == 0) || _7 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 { + return Api.ExportedChatInvite.chatInviteExported(flags: _1!, link: _2!, adminId: _3!, date: _4!, expireDate: _5, usageLimit: _6, usage: _7) } else { return nil diff --git a/submodules/TelegramApi/Sources/Api3.swift b/submodules/TelegramApi/Sources/Api3.swift index 348014efbe..7ead727dbe 100644 --- a/submodules/TelegramApi/Sources/Api3.swift +++ b/submodules/TelegramApi/Sources/Api3.swift @@ -3219,20 +3219,6 @@ public extension Api { }) } - public static func exportChatInvite(peer: Api.InputPeer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { - let buffer = Buffer() - buffer.appendInt32(234312524) - peer.serialize(buffer, true) - return (FunctionDescription(name: "messages.exportChatInvite", parameters: [("peer", peer)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.ExportedChatInvite? in - let reader = BufferReader(buffer) - var result: Api.ExportedChatInvite? - if let signature = reader.readInt32() { - result = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite - } - return result - }) - } - public static func getEmojiKeywords(langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() buffer.appendInt32(899735650) @@ -3916,6 +3902,92 @@ public extension Api { return result }) } + + public static func exportChatInvite(flags: Int32, peer: Api.InputPeer, expireDate: Int32?, usageLimit: Int32?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(347716823) + serializeInt32(flags, buffer: buffer, boxed: false) + peer.serialize(buffer, true) + if Int(flags) & Int(1 << 0) != 0 {serializeInt32(expireDate!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 1) != 0 {serializeInt32(usageLimit!, buffer: buffer, boxed: false)} + return (FunctionDescription(name: "messages.exportChatInvite", parameters: [("flags", flags), ("peer", peer), ("expireDate", expireDate), ("usageLimit", usageLimit)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.ExportedChatInvite? in + let reader = BufferReader(buffer) + var result: Api.ExportedChatInvite? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite + } + return result + }) + } + + public static func getExportedChatInvites(flags: Int32, peer: Api.InputPeer, adminId: Api.InputUser?, offsetLink: String?, limit: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(1838984707) + serializeInt32(flags, buffer: buffer, boxed: false) + peer.serialize(buffer, true) + if Int(flags) & Int(1 << 0) != 0 {adminId!.serialize(buffer, true)} + if Int(flags) & Int(1 << 2) != 0 {serializeString(offsetLink!, buffer: buffer, boxed: false)} + serializeInt32(limit, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getExportedChatInvites", parameters: [("flags", flags), ("peer", peer), ("adminId", adminId), ("offsetLink", offsetLink), ("limit", limit)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.ExportedChatInvites? in + let reader = BufferReader(buffer) + var result: Api.messages.ExportedChatInvites? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.messages.ExportedChatInvites + } + return result + }) + } + + public static func editExportedChatInvite(flags: Int32, peer: Api.InputPeer, link: String, expireDate: Int32?, usageLimit: Int32?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(48562110) + serializeInt32(flags, buffer: buffer, boxed: false) + peer.serialize(buffer, true) + serializeString(link, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {serializeInt32(expireDate!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 1) != 0 {serializeInt32(usageLimit!, buffer: buffer, boxed: false)} + return (FunctionDescription(name: "messages.editExportedChatInvite", parameters: [("flags", flags), ("peer", peer), ("link", link), ("expireDate", expireDate), ("usageLimit", usageLimit)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.ExportedChatInvite? in + let reader = BufferReader(buffer) + var result: Api.messages.ExportedChatInvite? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.messages.ExportedChatInvite + } + return result + }) + } + + public static func getExportedChatInvite(peer: Api.InputPeer, link: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(1937010524) + peer.serialize(buffer, true) + serializeString(link, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getExportedChatInvite", parameters: [("peer", peer), ("link", link)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.ExportedChatInvite? in + let reader = BufferReader(buffer) + var result: Api.messages.ExportedChatInvite? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.messages.ExportedChatInvite + } + return result + }) + } + + public static func getChatInviteImporters(peer: Api.InputPeer, link: String, offsetDate: Int32, offsetUser: Api.InputUser, limit: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(654013065) + peer.serialize(buffer, true) + serializeString(link, buffer: buffer, boxed: false) + serializeInt32(offsetDate, buffer: buffer, boxed: false) + offsetUser.serialize(buffer, true) + serializeInt32(limit, buffer: buffer, boxed: false) + return (FunctionDescription(name: "messages.getChatInviteImporters", parameters: [("peer", peer), ("link", link), ("offsetDate", offsetDate), ("offsetUser", offsetUser), ("limit", limit)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.ChatInviteImporters? in + let reader = BufferReader(buffer) + var result: Api.messages.ChatInviteImporters? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.messages.ChatInviteImporters + } + return result + }) + } } public struct channels { public static func readHistory(channel: Api.InputChannel, maxId: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { diff --git a/submodules/TelegramCore/Sources/ExportedInvitation.swift b/submodules/TelegramCore/Sources/ExportedInvitation.swift index ec0b1d3dfc..7f2927fa3b 100644 --- a/submodules/TelegramCore/Sources/ExportedInvitation.swift +++ b/submodules/TelegramCore/Sources/ExportedInvitation.swift @@ -9,8 +9,8 @@ extension ExportedInvitation { switch apiExportedInvite { case .chatInviteEmpty: return nil - case let .chatInviteExported(link): - self = ExportedInvitation(link: link) + case let .chatInviteExported(flags, link, adminId, date, expireDate, usageLimit, usage): + self = ExportedInvitation(link: link, revoked: (flags & (1 << 0)) != 0, adminId: PeerId(namespace: Namespaces.Peer.CloudUser, id: adminId), date: date, expireDate: expireDate, usageLimit: usageLimit, count: usage) } } } diff --git a/submodules/TelegramCore/Sources/InvitationLinks.swift b/submodules/TelegramCore/Sources/InvitationLinks.swift index 00de49bdd1..0766a23934 100644 --- a/submodules/TelegramCore/Sources/InvitationLinks.swift +++ b/submodules/TelegramCore/Sources/InvitationLinks.swift @@ -6,17 +6,17 @@ import MtProtoKit import SyncCore -public func ensuredExistingPeerExportedInvitation(account: Account, peerId: PeerId, revokeExisted: Bool = false) -> Signal { - return account.postbox.transaction { transaction -> Signal in +public func ensuredExistingPeerExportedInvitation(account: Account, peerId: PeerId, revokeExisted: Bool = false) -> Signal { + return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) { if let _ = peer as? TelegramChannel { if let cachedData = transaction.getPeerCachedData(peerId: peerId) as? CachedChannelData, cachedData.exportedInvitation != nil && !revokeExisted { return .complete() } else { - return account.network.request(Api.functions.messages.exportChatInvite(peer: inputPeer)) + return account.network.request(Api.functions.messages.exportChatInvite(flags: 0, peer: inputPeer, expireDate: nil, usageLimit: nil)) |> retryRequest - |> mapToSignal { result -> Signal in - return account.postbox.transaction { transaction -> String? in + |> mapToSignal { result -> Signal in + return account.postbox.transaction { transaction -> ExportedInvitation? in if let invitation = ExportedInvitation(apiExportedInvite: result) { transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in if let current = current as? CachedChannelData { @@ -25,7 +25,7 @@ public func ensuredExistingPeerExportedInvitation(account: Account, peerId: Peer return CachedChannelData().withUpdatedExportedInvitation(invitation) } }) - return invitation.link + return invitation } else { return nil } @@ -36,10 +36,10 @@ public func ensuredExistingPeerExportedInvitation(account: Account, peerId: Peer if let cachedData = transaction.getPeerCachedData(peerId: peerId) as? CachedGroupData, cachedData.exportedInvitation != nil && !revokeExisted { return .complete() } else { - return account.network.request(Api.functions.messages.exportChatInvite(peer: inputPeer)) + return account.network.request(Api.functions.messages.exportChatInvite(flags: 0, peer: inputPeer, expireDate: nil, usageLimit: nil)) |> retryRequest - |> mapToSignal { result -> Signal in - return account.postbox.transaction { transaction -> String? in + |> mapToSignal { result -> Signal in + return account.postbox.transaction { transaction -> ExportedInvitation? in if let invitation = ExportedInvitation(apiExportedInvite: result) { transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in if let current = current as? CachedGroupData { @@ -48,7 +48,7 @@ public func ensuredExistingPeerExportedInvitation(account: Account, peerId: Peer return current } }) - return invitation.link + return invitation } else { return nil } @@ -63,3 +63,126 @@ public func ensuredExistingPeerExportedInvitation(account: Account, peerId: Peer } } |> switchToLatest } + +public func createPeerExportedInvitation(account: Account, peerId: PeerId, expireDate: Int32?, usageLimit: Int32?) -> Signal { + return account.postbox.transaction { transaction -> Signal in + if let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) { + var flags: Int32 = 0 + if let _ = expireDate { + flags |= (1 << 0) + } + if let _ = usageLimit { + flags |= (1 << 1) + } + return account.network.request(Api.functions.messages.exportChatInvite(flags: flags, peer: inputPeer, expireDate: expireDate, usageLimit: usageLimit)) + |> retryRequest + |> map { result -> ExportedInvitation? in + if let invitation = ExportedInvitation(apiExportedInvite: result) { + return invitation + } else { + return nil + } + } + } else { + return .complete() + } + } |> switchToLatest +} + +public func peerExportedInvitations(account: Account, peerId: PeerId) -> Signal<[ExportedInvitation]?, NoError> { + return account.postbox.transaction { transaction -> Signal<[ExportedInvitation]?, NoError> in + if let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) { + return account.network.request(Api.functions.messages.getExportedChatInvites(flags: 0, peer: inputPeer, adminId: nil, offsetLink: nil, limit: 100)) + |> map(Optional.init) + |> `catch` { _ -> Signal in + return .single(nil) + } + |> mapToSignal { result -> Signal<[ExportedInvitation]?, NoError> in + return account.postbox.transaction { transaction -> [ExportedInvitation]? in + if let result = result, case let .exportedChatInvites(_, apiInvites, users) = result { + var peers: [Peer] = [] + var peersMap: [PeerId: Peer] = [:] + for user in users { + let telegramUser = TelegramUser(user: user) + peers.append(telegramUser) + peersMap[telegramUser.id] = telegramUser + } + updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer in + return updated + }) + + var invites: [ExportedInvitation] = [] + for apiInvite in apiInvites { + if let invite = ExportedInvitation(apiExportedInvite: apiInvite) { + invites.append(invite) + } + } + return invites + } else { + return nil + } + } + } + } else { + return .single(nil) + } + } |> switchToLatest +} + +public enum EditPeerExportedInvitationError { + case generic +} + +public func editPeerExportedInvitation(account: Account, peerId: PeerId, link: String, expireDate: Int32?, usageLimit: Int32?) -> Signal { + return account.postbox.transaction { transaction -> Signal in + if let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) { + var flags: Int32 = 0 + if let _ = expireDate { + flags |= (1 << 0) + } + if let _ = usageLimit { + flags |= (1 << 1) + } + return account.network.request(Api.functions.messages.editExportedChatInvite(flags: flags, peer: inputPeer, link: link, expireDate: expireDate, usageLimit: usageLimit)) + |> mapError { _ in return EditPeerExportedInvitationError.generic } + |> map { result -> ExportedInvitation? in + if case let .exportedChatInvite(invite, recentImporters, users) = result { + var peers: [Peer] = [] + for user in users { + let telegramUser = TelegramUser(user: user) + peers.append(telegramUser) + } + updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer in + return updated + }) + return ExportedInvitation(apiExportedInvite: invite) + } else { + return nil + } + } + } else { + return .complete() + } + } + |> castError(EditPeerExportedInvitationError.self) + |> switchToLatest +} + +public enum RevokePeerExportedInvitationError { + case generic +} + +public func revokePeerExportedInvitation(account: Account, peerId: PeerId, link: String) -> Signal { + return account.postbox.transaction { transaction -> Signal in + if let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) { + let flags: Int32 = (1 << 2) + return account.network.request(Api.functions.messages.editExportedChatInvite(flags: flags, peer: inputPeer, link: link, expireDate: nil, usageLimit: nil)) + |> mapError { _ in return RevokePeerExportedInvitationError.generic } + |> ignoreValues + } else { + return .complete() + } + } + |> castError(RevokePeerExportedInvitationError.self) + |> switchToLatest +} diff --git a/submodules/TelegramCore/Sources/UpdateCachedPeerData.swift b/submodules/TelegramCore/Sources/UpdateCachedPeerData.swift index ba0857acb9..c495816b8f 100644 --- a/submodules/TelegramCore/Sources/UpdateCachedPeerData.swift +++ b/submodules/TelegramCore/Sources/UpdateCachedPeerData.swift @@ -513,7 +513,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPeerId: PeerI return previous.withUpdatedFlags(channelFlags) .withUpdatedAbout(about) .withUpdatedParticipantsSummary(CachedChannelParticipantsSummary(memberCount: participantsCount, adminCount: adminsCount, bannedCount: bannedCount, kickedCount: kickedCount)) - .withUpdatedExportedInvitation(ExportedInvitation(apiExportedInvite: apiExportedInvite)) + .withUpdatedExportedInvitation(apiExportedInvite.flatMap { ExportedInvitation(apiExportedInvite: $0) }) .withUpdatedBotInfos(botInfos) .withUpdatedPinnedMessageId(pinnedMessageId) .withUpdatedStickerPack(stickerPack)