From 98e376cdd700dff23a9dafb7005d8cdd2cd7a4c5 Mon Sep 17 00:00:00 2001 From: overtake Date: Thu, 9 Mar 2017 10:22:57 +0300 Subject: [PATCH 1/5] passcode --- .../ProcessSecretChatIncomingDecryptedOperations.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift b/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift index c1bc932ce6..4a96a37a2d 100644 --- a/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift +++ b/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift @@ -158,7 +158,8 @@ func processSecretChatIncomingDecryptedOperations(mediaBox: MediaBox, modifier: } else { if let layer = SecretChatSequenceBasedLayer(rawValue: parsedLayer.rawValue) { let role = updatedState.role - let fromSeqNo: Int32 = (sequenceState.topProcessedCanonicalIncomingOperationIndex + 1) * 2 + (role == .creator ? 1 : 1) + + let fromSeqNo: Int32 = (topProcessedCanonicalIncomingOperationIndex + 1) * 2 + (role == .creator ? 1 : 1) let toSeqNo: Int32 = (canonicalIncomingIndex - 1) * 2 + (role == .creator ? 1 : 0) updatedState = addSecretChatOutgoingOperation(modifier: modifier, peerId: peerId, operation: SecretChatOutgoingOperationContents.resendOperations(layer: layer, actionGloballyUniqueId: arc4random64(), fromSeqNo: fromSeqNo, toSeqNo: toSeqNo), state: updatedState) } else { From 678236b6bcbba0b67c828cf6bf67adcec8e642cf Mon Sep 17 00:00:00 2001 From: overtake Date: Fri, 10 Mar 2017 21:43:11 +0300 Subject: [PATCH 2/5] - no message --- TelegramCore.xcodeproj/project.pbxproj | 18 + TelegramCore/AccountViewTracker.swift | 4 +- TelegramCore/MacosLegacy.swift | 1647 +++++++++++++++++++++ TelegramCore/MemoryBufferExtensions.swift | 4 +- TelegramCore/SecretChatStateBridge.swift | 22 + TelegramCore/StoreMessage_Telegram.swift | 2 +- TelegramCore/TelegramSecretChat.swift | 2 +- 7 files changed, 1693 insertions(+), 6 deletions(-) create mode 100644 TelegramCore/MacosLegacy.swift create mode 100644 TelegramCore/SecretChatStateBridge.swift diff --git a/TelegramCore.xcodeproj/project.pbxproj b/TelegramCore.xcodeproj/project.pbxproj index b324721497..2e2b16b3bb 100644 --- a/TelegramCore.xcodeproj/project.pbxproj +++ b/TelegramCore.xcodeproj/project.pbxproj @@ -22,6 +22,9 @@ C251D7431E65E50500283EDE /* StickerSetInstallation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C251D7421E65E50500283EDE /* StickerSetInstallation.swift */; }; C251D7441E65E50500283EDE /* StickerSetInstallation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C251D7421E65E50500283EDE /* StickerSetInstallation.swift */; }; C26A37EF1E5E0C41006977AC /* ChannelParticipants.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BB7C591E5C8074001527C3 /* ChannelParticipants.swift */; }; + C27982511E72C97800262BFD /* MacosLegacy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C27982501E72C97800262BFD /* MacosLegacy.swift */; }; + C27982531E73077800262BFD /* SecretChatStateBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = C27982521E73077800262BFD /* SecretChatStateBridge.swift */; }; + C27982541E73078400262BFD /* SecretChatStateBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = C27982521E73077800262BFD /* SecretChatStateBridge.swift */; }; C2A315C01E2E776A00D89000 /* RequestStartBot.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01749581E1092BC0057C89A /* RequestStartBot.swift */; }; C2FD33E11E680E9E008D13D4 /* RequestUserPhotos.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2FD33E01E680E9E008D13D4 /* RequestUserPhotos.swift */; }; C2FD33E21E680E9E008D13D4 /* RequestUserPhotos.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2FD33E01E680E9E008D13D4 /* RequestUserPhotos.swift */; }; @@ -465,6 +468,8 @@ C239BE961E62EE1E00C2C453 /* LoadMessagesIfNecessary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadMessagesIfNecessary.swift; sourceTree = ""; }; C239BE9B1E630CA700C2C453 /* UpdatePinnedMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdatePinnedMessage.swift; sourceTree = ""; }; C251D7421E65E50500283EDE /* StickerSetInstallation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickerSetInstallation.swift; sourceTree = ""; }; + C27982501E72C97800262BFD /* MacosLegacy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MacosLegacy.swift; sourceTree = ""; }; + C27982521E73077800262BFD /* SecretChatStateBridge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecretChatStateBridge.swift; sourceTree = ""; }; C2FD33E01E680E9E008D13D4 /* RequestUserPhotos.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestUserPhotos.swift; sourceTree = ""; }; C2FD33E31E687BF1008D13D4 /* PeerPhotoUpdater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PeerPhotoUpdater.swift; sourceTree = ""; }; C2FD33EA1E696C78008D13D4 /* GroupsInCommon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupsInCommon.swift; sourceTree = ""; }; @@ -735,6 +740,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + C279824F1E72C96B00262BFD /* legacy */ = { + isa = PBXGroup; + children = ( + C27982501E72C97800262BFD /* MacosLegacy.swift */, + ); + name = legacy; + sourceTree = ""; + }; D01B27A01E394D7B0022A4C0 /* Settings */ = { isa = PBXGroup; children = ( @@ -1110,6 +1123,7 @@ D09D8C031D4FAB1D0081DBEC /* TelegramCore */ = { isa = PBXGroup; children = ( + C279824F1E72C96B00262BFD /* legacy */, D03B0C791D62153400955575 /* third-party */, D03B0CB71D62232000955575 /* Utils */, D03B0CCF1D62242200955575 /* Objects */, @@ -1205,6 +1219,7 @@ D0FA8BA91E1FB76E001E855B /* ManagedSecretChatOutgoingOperations.swift */, D019B1CB1E2E3B6A00F80DB3 /* SecretChatRekeySession.swift */, D00C7CEA1E37A8540080C3D5 /* SetSecretChatMessageAutoremoveTimeoutInteractively.swift */, + C27982521E73077800262BFD /* SecretChatStateBridge.swift */, ); name = "Secret Chats"; sourceTree = ""; @@ -1561,6 +1576,7 @@ D0BC38701E40853E0044D6FE /* UpdatePeers.swift in Sources */, D03B0CE21D62249B00955575 /* InlineBotMessageAttribute.swift in Sources */, D0AB0B9A1D666520002C78E7 /* ManagedSynchronizePeerReadStates.swift in Sources */, + C27982531E73077800262BFD /* SecretChatStateBridge.swift in Sources */, D03B0D5B1D631A6900955575 /* Buffer.swift in Sources */, D0B843891DA7AB96005F29E1 /* ExportedInvitation.swift in Sources */, D03B0E441D631E6600955575 /* NetworkLogging.m in Sources */, @@ -1605,6 +1621,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C27982541E73078400262BFD /* SecretChatStateBridge.swift in Sources */, D00DBBD81E64E41100DB5485 /* CreateSecretChat.swift in Sources */, C2FD33EC1E696C79008D13D4 /* GroupsInCommon.swift in Sources */, C239BE9D1E630CB300C2C453 /* UpdatePinnedMessage.swift in Sources */, @@ -1761,6 +1778,7 @@ D0B8442C1DAB91E0005F29E1 /* NBMetadataCoreMapper.m in Sources */, D0FA8BB71E223C16001E855B /* SecretApiLayer8.swift in Sources */, D073CE6A1DCBCF17007511FD /* ViewCountMessageAttribute.swift in Sources */, + C27982511E72C97800262BFD /* MacosLegacy.swift in Sources */, D0B418AB1D7E0597004562A4 /* MultipartFetch.swift in Sources */, D0B418B71D7E05A6004562A4 /* Phonebook.swift in Sources */, D03C53741DAD5CA9004C17B3 /* CachedChannelData.swift in Sources */, diff --git a/TelegramCore/AccountViewTracker.swift b/TelegramCore/AccountViewTracker.swift index ae9fa5cccd..c5dbf9b003 100644 --- a/TelegramCore/AccountViewTracker.swift +++ b/TelegramCore/AccountViewTracker.swift @@ -289,14 +289,14 @@ public final class AccountViewTracker { if let existingContext = self.cachedDataContexts[peerId] { context = existingContext context.referenceData = referenceData - if context.timestamp == nil || abs(CFAbsoluteTimeGetCurrent() - context.timestamp!) > 60.0 * 60.0 { + if context.timestamp == nil || abs(CFAbsoluteTimeGetCurrent() - context.timestamp!) > 60.0 * 5 { dataUpdated = true } } else { context = PeerCachedDataContext() context.referenceData = referenceData self.cachedDataContexts[peerId] = context - if context.referenceData == nil || context.timestamp == nil || abs(CFAbsoluteTimeGetCurrent() - context.timestamp!) > 60.0 * 60.0 { + if context.referenceData == nil || context.timestamp == nil || abs(CFAbsoluteTimeGetCurrent() - context.timestamp!) > 60.0 * 5 { context.timestamp = CFAbsoluteTimeGetCurrent() dataUpdated = true } diff --git a/TelegramCore/MacosLegacy.swift b/TelegramCore/MacosLegacy.swift new file mode 100644 index 0000000000..187085cf98 --- /dev/null +++ b/TelegramCore/MacosLegacy.swift @@ -0,0 +1,1647 @@ + +fileprivate final class FunctionDescription: CustomStringConvertible { + let generator: () -> String + init(_ generator: @escaping () -> String) { + self.generator = generator + } + + var description: String { + return self.generator() + } +} + +fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { + var dict: [Int32 : (BufferReader) -> Any?] = [:] + dict[-1471112230] = { return $0.readInt32() } + dict[570911930] = { return $0.readInt64() } + dict[571523412] = { return $0.readDouble() } + dict[-1255641564] = { return parseString($0) } + dict[590459437] = { return MacosLegacy.Photo.parse_photoEmpty($0) } + dict[-1836524247] = { return MacosLegacy.Photo.parse_photo($0) } + dict[-1160714821] = { return MacosLegacy.Peer.parse_peerChat($0) } + dict[2] = { return MacosLegacy.Peer.parse_peerSecret($0) } + dict[164646985] = { return MacosLegacy.UserStatus.parse_userStatusEmpty($0) } + dict[-306628279] = { return MacosLegacy.UserStatus.parse_userStatusOnline($0) } + dict[9203775] = { return MacosLegacy.UserStatus.parse_userStatusOffline($0) } + dict[-496024847] = { return MacosLegacy.UserStatus.parse_userStatusRecently($0) } + dict[129960444] = { return MacosLegacy.UserStatus.parse_userStatusLastWeek($0) } + dict[2011940674] = { return MacosLegacy.UserStatus.parse_userStatusLastMonth($0) } + dict[236446268] = { return MacosLegacy.PhotoSize.parse_photoSizeEmpty($0) } + dict[2009052699] = { return MacosLegacy.PhotoSize.parse_photoSize($0) } + dict[-374917894] = { return MacosLegacy.PhotoSize.parse_photoCachedSize($0) } + dict[2086234950] = { return MacosLegacy.FileLocation.parse_fileLocationUnavailable($0) } + dict[1406570614] = { return MacosLegacy.FileLocation.parse_fileLocation($0) } + dict[-350980120] = { return MacosLegacy.WebPage.parse_webPageEmpty($0) } + dict[-981018084] = { return MacosLegacy.WebPage.parse_webPagePending($0) } + dict[1594340540] = { return MacosLegacy.WebPage.parse_webPage($0) } + dict[-2054908813] = { return MacosLegacy.WebPage.parse_webPageNotModified($0) } + dict[1038967584] = { return MacosLegacy.MessageMedia.parse_messageMediaEmpty($0) } + dict[1032643901] = { return MacosLegacy.MessageMedia.parse_messageMediaPhoto($0) } + dict[1457575028] = { return MacosLegacy.MessageMedia.parse_messageMediaGeo($0) } + dict[1585262393] = { return MacosLegacy.MessageMedia.parse_messageMediaContact($0) } + dict[-1618676578] = { return MacosLegacy.MessageMedia.parse_messageMediaUnsupported($0) } + dict[-203411800] = { return MacosLegacy.MessageMedia.parse_messageMediaDocument($0) } + dict[-1557277184] = { return MacosLegacy.MessageMedia.parse_messageMediaWebPage($0) } + dict[1815593308] = { return MacosLegacy.DocumentAttribute.parse_documentAttributeImageSize($0) } + dict[297109817] = { return MacosLegacy.DocumentAttribute.parse_documentAttributeAnimated($0) } + dict[1662637586] = { return MacosLegacy.DocumentAttribute.parse_documentAttributeSticker($0) } + dict[1494273227] = { return MacosLegacy.DocumentAttribute.parse_documentAttributeVideo($0) } + dict[-1739392570] = { return MacosLegacy.DocumentAttribute.parse_documentAttributeAudio($0) } + dict[358154344] = { return MacosLegacy.DocumentAttribute.parse_documentAttributeFilename($0) } + dict[-1744710921] = { return MacosLegacy.DocumentAttribute.parse_documentAttributeHasStickers($0) } + dict[-4838507] = { return MacosLegacy.InputStickerSet.parse_inputStickerSetEmpty($0) } + dict[537022650] = { return MacosLegacy.User.parse_userEmpty($0) } + dict[-787638374] = { return MacosLegacy.User.parse_user($0) } + dict[4] = { return MacosLegacy.Message.parse_destructMessage($0) } + dict[286776671] = { return MacosLegacy.GeoPoint.parse_geoPointEmpty($0) } + dict[541710092] = { return MacosLegacy.GeoPoint.parse_geoPoint($0) } + dict[-1361650766] = { return MacosLegacy.MaskCoords.parse_maskCoords($0) } + dict[1326562017] = { return MacosLegacy.UserProfilePhoto.parse_userProfilePhotoEmpty($0) } + dict[-715532088] = { return MacosLegacy.UserProfilePhoto.parse_userProfilePhoto($0) } + dict[-94974410] = { return MacosLegacy.EncryptedChat.parse_encryptedChat($0) } + dict[922273905] = { return MacosLegacy.Document.parse_documentEmpty($0) } + dict[-2027738169] = { return MacosLegacy.Document.parse_document($0) } + return dict +}() + +public struct MacosLegacy { + public static func parse(_ buffer: Buffer) -> Any? { + let reader = BufferReader(buffer) + if let signature = reader.readInt32() { + return parse(reader, signature: signature) + } + return nil + } + + fileprivate static func parse(_ reader: BufferReader, signature: Int32) -> Any? { + if let parser = parsers[signature] { + return parser(reader) + } + else { + print("Type constructor \(String(signature, radix: 16, uppercase: false)) not found") + return nil + } + } + + fileprivate static func parseVector(_ reader: BufferReader, elementSignature: Int32, elementType: T.Type) -> [T]? { + if let count = reader.readInt32() { + var array = [T]() + var i: Int32 = 0 + while i < count { + var signature = elementSignature + if elementSignature == 0 { + if let unboxedSignature = reader.readInt32() { + signature = unboxedSignature + } + else { + return nil + } + } + if let item = MacosLegacy.parse(reader, signature: signature) as? T { + array.append(item) + } + else { + return nil + } + i += 1 + } + return array + } + return nil + } + + public static func serializeObject(_ object: Any, buffer: Buffer, boxed: Swift.Bool) -> Swift.Bool { + switch object { + case let _1 as MacosLegacy.Photo: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.Peer: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.UserStatus: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.PhotoSize: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.FileLocation: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.WebPage: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.MessageMedia: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.DocumentAttribute: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.InputStickerSet: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.User: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.Message: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.GeoPoint: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.MaskCoords: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.UserProfilePhoto: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.EncryptedChat: + return _1.serialize(buffer, boxed) + case let _1 as MacosLegacy.Document: + return _1.serialize(buffer, boxed) + default: + break + } + return false + } + + public enum Photo: CustomStringConvertible { + case photoEmpty(id: Int64) + case photo(flags: Int32, id: Int64, accessHash: Int64, date: Int32, sizes: [MacosLegacy.PhotoSize]) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .photoEmpty(let id): + if boxed { + buffer.appendInt32(590459437) + } + serializeInt64(id, buffer: buffer, boxed: false) + break + case .photo(let flags, let id, let accessHash, let date, let sizes): + if boxed { + buffer.appendInt32(-1836524247) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt64(id, buffer: buffer, boxed: false) + serializeInt64(accessHash, buffer: buffer, boxed: false) + serializeInt32(date, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(sizes.count)) + for item in sizes { + item.serialize(buffer, true) + } + break + } + return true + } + + fileprivate static func parse_photoEmpty(_ reader: BufferReader) -> Photo? { + var _1: Int64? + _1 = reader.readInt64() + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.Photo.photoEmpty(id: _1!) + } + else { + return nil + } + } + fileprivate static func parse_photo(_ reader: BufferReader) -> Photo? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: Int64? + _3 = reader.readInt64() + var _4: Int32? + _4 = reader.readInt32() + var _5: [MacosLegacy.PhotoSize]? + if let _ = reader.readInt32() { + _5 = MacosLegacy.parseVector(reader, elementSignature: 0, elementType: MacosLegacy.PhotoSize.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return MacosLegacy.Photo.photo(flags: _1!, id: _2!, accessHash: _3!, date: _4!, sizes: _5!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .photoEmpty(let id): + return "(photoEmpty id: \(id))" + case .photo(let flags, let id, let accessHash, let date, let sizes): + return "(photo flags: \(flags), id: \(id), accessHash: \(accessHash), date: \(date), sizes: \(sizes))" + } + } + } + } + + public enum Peer: CustomStringConvertible { + case peerChat(chatId: Int32) + case peerSecret(chatId: Int32) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .peerChat(let chatId): + if boxed { + buffer.appendInt32(-1160714821) + } + serializeInt32(chatId, buffer: buffer, boxed: false) + break + case .peerSecret(let chatId): + if boxed { + buffer.appendInt32(2) + } + serializeInt32(chatId, buffer: buffer, boxed: false) + break + } + return true + } + + fileprivate static func parse_peerChat(_ reader: BufferReader) -> Peer? { + var _1: Int32? + _1 = reader.readInt32() + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.Peer.peerChat(chatId: _1!) + } + else { + return nil + } + } + fileprivate static func parse_peerSecret(_ reader: BufferReader) -> Peer? { + var _1: Int32? + _1 = reader.readInt32() + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.Peer.peerSecret(chatId: _1!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .peerChat(let chatId): + return "(peerChat chatId: \(chatId))" + case .peerSecret(let chatId): + return "(peerSecret chatId: \(chatId))" + } + } + } + } + + public enum UserStatus: CustomStringConvertible { + case userStatusEmpty + case userStatusOnline(expires: Int32) + case userStatusOffline(wasOnline: Int32) + case userStatusRecently + case userStatusLastWeek + case userStatusLastMonth + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .userStatusEmpty: + if boxed { + buffer.appendInt32(164646985) + } + + break + case .userStatusOnline(let expires): + if boxed { + buffer.appendInt32(-306628279) + } + serializeInt32(expires, buffer: buffer, boxed: false) + break + case .userStatusOffline(let wasOnline): + if boxed { + buffer.appendInt32(9203775) + } + serializeInt32(wasOnline, buffer: buffer, boxed: false) + break + case .userStatusRecently: + if boxed { + buffer.appendInt32(-496024847) + } + + break + case .userStatusLastWeek: + if boxed { + buffer.appendInt32(129960444) + } + + break + case .userStatusLastMonth: + if boxed { + buffer.appendInt32(2011940674) + } + + break + } + return true + } + + fileprivate static func parse_userStatusEmpty(_ reader: BufferReader) -> UserStatus? { + return MacosLegacy.UserStatus.userStatusEmpty + } + fileprivate static func parse_userStatusOnline(_ reader: BufferReader) -> UserStatus? { + var _1: Int32? + _1 = reader.readInt32() + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.UserStatus.userStatusOnline(expires: _1!) + } + else { + return nil + } + } + fileprivate static func parse_userStatusOffline(_ reader: BufferReader) -> UserStatus? { + var _1: Int32? + _1 = reader.readInt32() + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.UserStatus.userStatusOffline(wasOnline: _1!) + } + else { + return nil + } + } + fileprivate static func parse_userStatusRecently(_ reader: BufferReader) -> UserStatus? { + return MacosLegacy.UserStatus.userStatusRecently + } + fileprivate static func parse_userStatusLastWeek(_ reader: BufferReader) -> UserStatus? { + return MacosLegacy.UserStatus.userStatusLastWeek + } + fileprivate static func parse_userStatusLastMonth(_ reader: BufferReader) -> UserStatus? { + return MacosLegacy.UserStatus.userStatusLastMonth + } + + public var description: String { + get { + switch self { + case .userStatusEmpty: + return "(userStatusEmpty)" + case .userStatusOnline(let expires): + return "(userStatusOnline expires: \(expires))" + case .userStatusOffline(let wasOnline): + return "(userStatusOffline wasOnline: \(wasOnline))" + case .userStatusRecently: + return "(userStatusRecently)" + case .userStatusLastWeek: + return "(userStatusLastWeek)" + case .userStatusLastMonth: + return "(userStatusLastMonth)" + } + } + } + } + + public enum PhotoSize: CustomStringConvertible { + case photoSizeEmpty(type: String) + case photoSize(type: String, location: MacosLegacy.FileLocation, w: Int32, h: Int32, size: Int32) + case photoCachedSize(type: String, location: MacosLegacy.FileLocation, w: Int32, h: Int32, bytes: Buffer) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .photoSizeEmpty(let type): + if boxed { + buffer.appendInt32(236446268) + } + serializeString(type, buffer: buffer, boxed: false) + break + case .photoSize(let type, let location, let w, let h, let size): + if boxed { + buffer.appendInt32(2009052699) + } + serializeString(type, buffer: buffer, boxed: false) + location.serialize(buffer, true) + serializeInt32(w, buffer: buffer, boxed: false) + serializeInt32(h, buffer: buffer, boxed: false) + serializeInt32(size, buffer: buffer, boxed: false) + break + case .photoCachedSize(let type, let location, let w, let h, let bytes): + if boxed { + buffer.appendInt32(-374917894) + } + serializeString(type, buffer: buffer, boxed: false) + location.serialize(buffer, true) + serializeInt32(w, buffer: buffer, boxed: false) + serializeInt32(h, buffer: buffer, boxed: false) + serializeBytes(bytes, buffer: buffer, boxed: false) + break + } + return true + } + + fileprivate static func parse_photoSizeEmpty(_ reader: BufferReader) -> PhotoSize? { + var _1: String? + _1 = parseString(reader) + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.PhotoSize.photoSizeEmpty(type: _1!) + } + else { + return nil + } + } + fileprivate static func parse_photoSize(_ reader: BufferReader) -> PhotoSize? { + var _1: String? + _1 = parseString(reader) + var _2: MacosLegacy.FileLocation? + if let signature = reader.readInt32() { + _2 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.FileLocation + } + var _3: Int32? + _3 = reader.readInt32() + var _4: Int32? + _4 = reader.readInt32() + var _5: Int32? + _5 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return MacosLegacy.PhotoSize.photoSize(type: _1!, location: _2!, w: _3!, h: _4!, size: _5!) + } + else { + return nil + } + } + fileprivate static func parse_photoCachedSize(_ reader: BufferReader) -> PhotoSize? { + var _1: String? + _1 = parseString(reader) + var _2: MacosLegacy.FileLocation? + if let signature = reader.readInt32() { + _2 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.FileLocation + } + var _3: Int32? + _3 = reader.readInt32() + var _4: Int32? + _4 = reader.readInt32() + var _5: Buffer? + _5 = parseBytes(reader) + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return MacosLegacy.PhotoSize.photoCachedSize(type: _1!, location: _2!, w: _3!, h: _4!, bytes: _5!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .photoSizeEmpty(let type): + return "(photoSizeEmpty type: \(type))" + case .photoSize(let type, let location, let w, let h, let size): + return "(photoSize type: \(type), location: \(location), w: \(w), h: \(h), size: \(size))" + case .photoCachedSize(let type, let location, let w, let h, let bytes): + return "(photoCachedSize type: \(type), location: \(location), w: \(w), h: \(h), bytes: \(bytes))" + } + } + } + } + + public enum FileLocation: CustomStringConvertible { + case fileLocationUnavailable(volumeId: Int64, localId: Int32, secret: Int64) + case fileLocation(dcId: Int32, volumeId: Int64, localId: Int32, secret: Int64) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .fileLocationUnavailable(let volumeId, let localId, let secret): + if boxed { + buffer.appendInt32(2086234950) + } + serializeInt64(volumeId, buffer: buffer, boxed: false) + serializeInt32(localId, buffer: buffer, boxed: false) + serializeInt64(secret, buffer: buffer, boxed: false) + break + case .fileLocation(let dcId, let volumeId, let localId, let secret): + if boxed { + buffer.appendInt32(1406570614) + } + serializeInt32(dcId, buffer: buffer, boxed: false) + serializeInt64(volumeId, buffer: buffer, boxed: false) + serializeInt32(localId, buffer: buffer, boxed: false) + serializeInt64(secret, buffer: buffer, boxed: false) + break + } + return true + } + + fileprivate static func parse_fileLocationUnavailable(_ reader: BufferReader) -> FileLocation? { + var _1: Int64? + _1 = reader.readInt64() + var _2: Int32? + _2 = reader.readInt32() + var _3: Int64? + _3 = reader.readInt64() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + if _c1 && _c2 && _c3 { + return MacosLegacy.FileLocation.fileLocationUnavailable(volumeId: _1!, localId: _2!, secret: _3!) + } + else { + return nil + } + } + fileprivate static func parse_fileLocation(_ reader: BufferReader) -> FileLocation? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: Int32? + _3 = reader.readInt32() + var _4: Int64? + _4 = reader.readInt64() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return MacosLegacy.FileLocation.fileLocation(dcId: _1!, volumeId: _2!, localId: _3!, secret: _4!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .fileLocationUnavailable(let volumeId, let localId, let secret): + return "(fileLocationUnavailable volumeId: \(volumeId), localId: \(localId), secret: \(secret))" + case .fileLocation(let dcId, let volumeId, let localId, let secret): + return "(fileLocation dcId: \(dcId), volumeId: \(volumeId), localId: \(localId), secret: \(secret))" + } + } + } + } + + public enum WebPage: CustomStringConvertible { + case webPageEmpty(id: Int64) + case webPagePending(id: Int64, date: Int32) + case webPage(flags: Int32, id: Int64, url: String, displayUrl: String, hash: Int32, type: String?, siteName: String?, title: String?, description: String?, photo: MacosLegacy.Photo?, embedUrl: String?, embedType: String?, embedWidth: Int32?, embedHeight: Int32?, duration: Int32?, author: String?, document: MacosLegacy.Document?) + case webPageNotModified + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .webPageEmpty(let id): + if boxed { + buffer.appendInt32(-350980120) + } + serializeInt64(id, buffer: buffer, boxed: false) + break + case .webPagePending(let id, let date): + if boxed { + buffer.appendInt32(-981018084) + } + serializeInt64(id, buffer: buffer, boxed: false) + serializeInt32(date, buffer: buffer, boxed: false) + break + case .webPage(let flags, let id, let url, let displayUrl, let hash, let type, let siteName, let title, let description, let photo, let embedUrl, let embedType, let embedWidth, let embedHeight, let duration, let author, let document): + if boxed { + buffer.appendInt32(1594340540) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt64(id, buffer: buffer, boxed: false) + serializeString(url, buffer: buffer, boxed: false) + serializeString(displayUrl, buffer: buffer, boxed: false) + serializeInt32(hash, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {serializeString(type!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 1) != 0 {serializeString(siteName!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 2) != 0 {serializeString(title!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 3) != 0 {serializeString(description!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 4) != 0 {photo!.serialize(buffer, true)} + if Int(flags) & Int(1 << 5) != 0 {serializeString(embedUrl!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 5) != 0 {serializeString(embedType!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 6) != 0 {serializeInt32(embedWidth!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 6) != 0 {serializeInt32(embedHeight!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 7) != 0 {serializeInt32(duration!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 8) != 0 {serializeString(author!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 9) != 0 {document!.serialize(buffer, true)} + break + case .webPageNotModified: + if boxed { + buffer.appendInt32(-2054908813) + } + + break + } + return true + } + + fileprivate static func parse_webPageEmpty(_ reader: BufferReader) -> WebPage? { + var _1: Int64? + _1 = reader.readInt64() + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.WebPage.webPageEmpty(id: _1!) + } + else { + return nil + } + } + fileprivate static func parse_webPagePending(_ reader: BufferReader) -> WebPage? { + var _1: Int64? + _1 = reader.readInt64() + var _2: Int32? + _2 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return MacosLegacy.WebPage.webPagePending(id: _1!, date: _2!) + } + else { + return nil + } + } + fileprivate static func parse_webPage(_ reader: BufferReader) -> WebPage? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: String? + _3 = parseString(reader) + var _4: String? + _4 = parseString(reader) + var _5: Int32? + _5 = reader.readInt32() + var _6: String? + if Int(_1!) & Int(1 << 0) != 0 {_6 = parseString(reader) } + var _7: String? + if Int(_1!) & Int(1 << 1) != 0 {_7 = parseString(reader) } + var _8: String? + if Int(_1!) & Int(1 << 2) != 0 {_8 = parseString(reader) } + var _9: String? + if Int(_1!) & Int(1 << 3) != 0 {_9 = parseString(reader) } + var _10: MacosLegacy.Photo? + if Int(_1!) & Int(1 << 4) != 0 {if let signature = reader.readInt32() { + _10 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.Photo + } } + var _11: String? + if Int(_1!) & Int(1 << 5) != 0 {_11 = parseString(reader) } + var _12: String? + if Int(_1!) & Int(1 << 5) != 0 {_12 = parseString(reader) } + var _13: Int32? + if Int(_1!) & Int(1 << 6) != 0 {_13 = reader.readInt32() } + var _14: Int32? + if Int(_1!) & Int(1 << 6) != 0 {_14 = reader.readInt32() } + var _15: Int32? + if Int(_1!) & Int(1 << 7) != 0 {_15 = reader.readInt32() } + var _16: String? + if Int(_1!) & Int(1 << 8) != 0 {_16 = parseString(reader) } + var _17: MacosLegacy.Document? + if Int(_1!) & Int(1 << 9) != 0 {if let signature = reader.readInt32() { + _17 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.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 << 0) == 0) || _6 != nil + let _c7 = (Int(_1!) & Int(1 << 1) == 0) || _7 != nil + let _c8 = (Int(_1!) & Int(1 << 2) == 0) || _8 != nil + let _c9 = (Int(_1!) & Int(1 << 3) == 0) || _9 != nil + let _c10 = (Int(_1!) & Int(1 << 4) == 0) || _10 != nil + let _c11 = (Int(_1!) & Int(1 << 5) == 0) || _11 != nil + let _c12 = (Int(_1!) & Int(1 << 5) == 0) || _12 != nil + let _c13 = (Int(_1!) & Int(1 << 6) == 0) || _13 != nil + let _c14 = (Int(_1!) & Int(1 << 6) == 0) || _14 != nil + let _c15 = (Int(_1!) & Int(1 << 7) == 0) || _15 != nil + let _c16 = (Int(_1!) & Int(1 << 8) == 0) || _16 != nil + let _c17 = (Int(_1!) & Int(1 << 9) == 0) || _17 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 && _c17 { + return MacosLegacy.WebPage.webPage(flags: _1!, id: _2!, url: _3!, displayUrl: _4!, hash: _5!, type: _6, siteName: _7, title: _8, description: _9, photo: _10, embedUrl: _11, embedType: _12, embedWidth: _13, embedHeight: _14, duration: _15, author: _16, document: _17) + } + else { + return nil + } + } + fileprivate static func parse_webPageNotModified(_ reader: BufferReader) -> WebPage? { + return MacosLegacy.WebPage.webPageNotModified + } + + public var description: String { + get { + switch self { + case .webPageEmpty(let id): + return "(webPageEmpty id: \(id))" + case .webPagePending(let id, let date): + return "(webPagePending id: \(id), date: \(date))" + case .webPage(let flags, let id, let url, let displayUrl, let hash, let type, let siteName, let title, let description, let photo, let embedUrl, let embedType, let embedWidth, let embedHeight, let duration, let author, let document): + return "(webPage flags: \(flags), id: \(id), url: \(url), displayUrl: \(displayUrl), hash: \(hash), type: \(type), siteName: \(siteName), title: \(title), description: \(description), photo: \(photo), embedUrl: \(embedUrl), embedType: \(embedType), embedWidth: \(embedWidth), embedHeight: \(embedHeight), duration: \(duration), author: \(author), document: \(document))" + case .webPageNotModified: + return "(webPageNotModified)" + } + } + } + } + + public enum MessageMedia: CustomStringConvertible { + case messageMediaEmpty + case messageMediaPhoto(photo: MacosLegacy.Photo, caption: String) + case messageMediaGeo(geo: MacosLegacy.GeoPoint) + case messageMediaContact(phoneNumber: String, firstName: String, lastName: String, userId: Int32) + case messageMediaUnsupported + case messageMediaDocument(document: MacosLegacy.Document, caption: String) + case messageMediaWebPage(webpage: MacosLegacy.WebPage) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .messageMediaEmpty: + if boxed { + buffer.appendInt32(1038967584) + } + + break + case .messageMediaPhoto(let photo, let caption): + if boxed { + buffer.appendInt32(1032643901) + } + photo.serialize(buffer, true) + serializeString(caption, buffer: buffer, boxed: false) + break + case .messageMediaGeo(let geo): + if boxed { + buffer.appendInt32(1457575028) + } + geo.serialize(buffer, true) + break + case .messageMediaContact(let phoneNumber, let firstName, let lastName, let userId): + if boxed { + buffer.appendInt32(1585262393) + } + serializeString(phoneNumber, buffer: buffer, boxed: false) + serializeString(firstName, buffer: buffer, boxed: false) + serializeString(lastName, buffer: buffer, boxed: false) + serializeInt32(userId, buffer: buffer, boxed: false) + break + case .messageMediaUnsupported: + if boxed { + buffer.appendInt32(-1618676578) + } + + break + case .messageMediaDocument(let document, let caption): + if boxed { + buffer.appendInt32(-203411800) + } + document.serialize(buffer, true) + serializeString(caption, buffer: buffer, boxed: false) + break + case .messageMediaWebPage(let webpage): + if boxed { + buffer.appendInt32(-1557277184) + } + webpage.serialize(buffer, true) + break + } + return true + } + + fileprivate static func parse_messageMediaEmpty(_ reader: BufferReader) -> MessageMedia? { + return MacosLegacy.MessageMedia.messageMediaEmpty + } + fileprivate static func parse_messageMediaPhoto(_ reader: BufferReader) -> MessageMedia? { + var _1: MacosLegacy.Photo? + if let signature = reader.readInt32() { + _1 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.Photo + } + var _2: String? + _2 = parseString(reader) + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return MacosLegacy.MessageMedia.messageMediaPhoto(photo: _1!, caption: _2!) + } + else { + return nil + } + } + fileprivate static func parse_messageMediaGeo(_ reader: BufferReader) -> MessageMedia? { + var _1: MacosLegacy.GeoPoint? + if let signature = reader.readInt32() { + _1 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.GeoPoint + } + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.MessageMedia.messageMediaGeo(geo: _1!) + } + else { + return nil + } + } + fileprivate static func parse_messageMediaContact(_ reader: BufferReader) -> MessageMedia? { + var _1: String? + _1 = parseString(reader) + var _2: String? + _2 = parseString(reader) + var _3: String? + _3 = parseString(reader) + var _4: Int32? + _4 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return MacosLegacy.MessageMedia.messageMediaContact(phoneNumber: _1!, firstName: _2!, lastName: _3!, userId: _4!) + } + else { + return nil + } + } + fileprivate static func parse_messageMediaUnsupported(_ reader: BufferReader) -> MessageMedia? { + return MacosLegacy.MessageMedia.messageMediaUnsupported + } + fileprivate static func parse_messageMediaDocument(_ reader: BufferReader) -> MessageMedia? { + var _1: MacosLegacy.Document? + if let signature = reader.readInt32() { + _1 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.Document + } + var _2: String? + _2 = parseString(reader) + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return MacosLegacy.MessageMedia.messageMediaDocument(document: _1!, caption: _2!) + } + else { + return nil + } + } + fileprivate static func parse_messageMediaWebPage(_ reader: BufferReader) -> MessageMedia? { + var _1: MacosLegacy.WebPage? + if let signature = reader.readInt32() { + _1 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.WebPage + } + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.MessageMedia.messageMediaWebPage(webpage: _1!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .messageMediaEmpty: + return "(messageMediaEmpty)" + case .messageMediaPhoto(let photo, let caption): + return "(messageMediaPhoto photo: \(photo), caption: \(caption))" + case .messageMediaGeo(let geo): + return "(messageMediaGeo geo: \(geo))" + case .messageMediaContact(let phoneNumber, let firstName, let lastName, let userId): + return "(messageMediaContact phoneNumber: \(phoneNumber), firstName: \(firstName), lastName: \(lastName), userId: \(userId))" + case .messageMediaUnsupported: + return "(messageMediaUnsupported)" + case .messageMediaDocument(let document, let caption): + return "(messageMediaDocument document: \(document), caption: \(caption))" + case .messageMediaWebPage(let webpage): + return "(messageMediaWebPage webpage: \(webpage))" + } + } + } + } + + public enum DocumentAttribute: CustomStringConvertible { + case documentAttributeImageSize(w: Int32, h: Int32) + case documentAttributeAnimated + case documentAttributeSticker(flags: Int32, alt: String, stickerset: MacosLegacy.InputStickerSet, maskCoords: MacosLegacy.MaskCoords?) + case documentAttributeVideo(duration: Int32, w: Int32, h: Int32) + case documentAttributeAudio(flags: Int32, duration: Int32, title: String?, performer: String?, waveform: Buffer?) + case documentAttributeFilename(fileName: String) + case documentAttributeHasStickers + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .documentAttributeImageSize(let w, let h): + if boxed { + buffer.appendInt32(1815593308) + } + serializeInt32(w, buffer: buffer, boxed: false) + serializeInt32(h, buffer: buffer, boxed: false) + break + case .documentAttributeAnimated: + if boxed { + buffer.appendInt32(297109817) + } + + break + case .documentAttributeSticker(let flags, let alt, let stickerset, let maskCoords): + if boxed { + buffer.appendInt32(1662637586) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeString(alt, buffer: buffer, boxed: false) + stickerset.serialize(buffer, true) + if Int(flags) & Int(1 << 0) != 0 {maskCoords!.serialize(buffer, true)} + break + case .documentAttributeVideo(let duration, let w, let h): + if boxed { + buffer.appendInt32(1494273227) + } + serializeInt32(duration, buffer: buffer, boxed: false) + serializeInt32(w, buffer: buffer, boxed: false) + serializeInt32(h, buffer: buffer, boxed: false) + break + case .documentAttributeAudio(let flags, let duration, let title, let performer, let waveform): + if boxed { + buffer.appendInt32(-1739392570) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(duration, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {serializeString(title!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 1) != 0 {serializeString(performer!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 2) != 0 {serializeBytes(waveform!, buffer: buffer, boxed: false)} + break + case .documentAttributeFilename(let fileName): + if boxed { + buffer.appendInt32(358154344) + } + serializeString(fileName, buffer: buffer, boxed: false) + break + case .documentAttributeHasStickers: + if boxed { + buffer.appendInt32(-1744710921) + } + + break + } + return true + } + + fileprivate static func parse_documentAttributeImageSize(_ reader: BufferReader) -> DocumentAttribute? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return MacosLegacy.DocumentAttribute.documentAttributeImageSize(w: _1!, h: _2!) + } + else { + return nil + } + } + fileprivate static func parse_documentAttributeAnimated(_ reader: BufferReader) -> DocumentAttribute? { + return MacosLegacy.DocumentAttribute.documentAttributeAnimated + } + fileprivate static func parse_documentAttributeSticker(_ reader: BufferReader) -> DocumentAttribute? { + var _1: Int32? + _1 = reader.readInt32() + var _2: String? + _2 = parseString(reader) + var _3: MacosLegacy.InputStickerSet? + if let signature = reader.readInt32() { + _3 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.InputStickerSet + } + var _4: MacosLegacy.MaskCoords? + if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { + _4 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.MaskCoords + } } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return MacosLegacy.DocumentAttribute.documentAttributeSticker(flags: _1!, alt: _2!, stickerset: _3!, maskCoords: _4) + } + else { + return nil + } + } + fileprivate static func parse_documentAttributeVideo(_ reader: BufferReader) -> DocumentAttribute? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: Int32? + _3 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + if _c1 && _c2 && _c3 { + return MacosLegacy.DocumentAttribute.documentAttributeVideo(duration: _1!, w: _2!, h: _3!) + } + else { + return nil + } + } + fileprivate static func parse_documentAttributeAudio(_ reader: BufferReader) -> DocumentAttribute? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: String? + if Int(_1!) & Int(1 << 0) != 0 {_3 = parseString(reader) } + var _4: String? + if Int(_1!) & Int(1 << 1) != 0 {_4 = parseString(reader) } + var _5: Buffer? + if Int(_1!) & Int(1 << 2) != 0 {_5 = parseBytes(reader) } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil + let _c4 = (Int(_1!) & Int(1 << 1) == 0) || _4 != nil + let _c5 = (Int(_1!) & Int(1 << 2) == 0) || _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return MacosLegacy.DocumentAttribute.documentAttributeAudio(flags: _1!, duration: _2!, title: _3, performer: _4, waveform: _5) + } + else { + return nil + } + } + fileprivate static func parse_documentAttributeFilename(_ reader: BufferReader) -> DocumentAttribute? { + var _1: String? + _1 = parseString(reader) + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.DocumentAttribute.documentAttributeFilename(fileName: _1!) + } + else { + return nil + } + } + fileprivate static func parse_documentAttributeHasStickers(_ reader: BufferReader) -> DocumentAttribute? { + return MacosLegacy.DocumentAttribute.documentAttributeHasStickers + } + + public var description: String { + get { + switch self { + case .documentAttributeImageSize(let w, let h): + return "(documentAttributeImageSize w: \(w), h: \(h))" + case .documentAttributeAnimated: + return "(documentAttributeAnimated)" + case .documentAttributeSticker(let flags, let alt, let stickerset, let maskCoords): + return "(documentAttributeSticker flags: \(flags), alt: \(alt), stickerset: \(stickerset), maskCoords: \(maskCoords))" + case .documentAttributeVideo(let duration, let w, let h): + return "(documentAttributeVideo duration: \(duration), w: \(w), h: \(h))" + case .documentAttributeAudio(let flags, let duration, let title, let performer, let waveform): + return "(documentAttributeAudio flags: \(flags), duration: \(duration), title: \(title), performer: \(performer), waveform: \(waveform))" + case .documentAttributeFilename(let fileName): + return "(documentAttributeFilename fileName: \(fileName))" + case .documentAttributeHasStickers: + return "(documentAttributeHasStickers)" + } + } + } + } + + public enum InputStickerSet: CustomStringConvertible { + case inputStickerSetEmpty + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .inputStickerSetEmpty: + if boxed { + buffer.appendInt32(-4838507) + } + + break + } + return true + } + + fileprivate static func parse_inputStickerSetEmpty(_ reader: BufferReader) -> InputStickerSet? { + return MacosLegacy.InputStickerSet.inputStickerSetEmpty + } + + public var description: String { + get { + switch self { + case .inputStickerSetEmpty: + return "(inputStickerSetEmpty)" + } + } + } + } + + public enum User: CustomStringConvertible { + case userEmpty(id: Int32) + case user(flags: Int32, id: Int32, accessHash: Int64?, firstName: String?, lastName: String?, username: String?, phone: String?, photo: MacosLegacy.UserProfilePhoto?, status: MacosLegacy.UserStatus?, botInfoVersion: Int32?, restrictionReason: String?, botInlinePlaceholder: String?) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .userEmpty(let id): + if boxed { + buffer.appendInt32(537022650) + } + serializeInt32(id, buffer: buffer, boxed: false) + break + case .user(let flags, let id, let accessHash, let firstName, let lastName, let username, let phone, let photo, let status, let botInfoVersion, let restrictionReason, let botInlinePlaceholder): + if boxed { + buffer.appendInt32(-787638374) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(id, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {serializeInt64(accessHash!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 1) != 0 {serializeString(firstName!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 2) != 0 {serializeString(lastName!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 3) != 0 {serializeString(username!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 4) != 0 {serializeString(phone!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 5) != 0 {photo!.serialize(buffer, true)} + if Int(flags) & Int(1 << 6) != 0 {status!.serialize(buffer, true)} + if Int(flags) & Int(1 << 14) != 0 {serializeInt32(botInfoVersion!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 18) != 0 {serializeString(restrictionReason!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 19) != 0 {serializeString(botInlinePlaceholder!, buffer: buffer, boxed: false)} + break + } + return true + } + + fileprivate static func parse_userEmpty(_ reader: BufferReader) -> User? { + var _1: Int32? + _1 = reader.readInt32() + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.User.userEmpty(id: _1!) + } + else { + return nil + } + } + fileprivate static func parse_user(_ reader: BufferReader) -> User? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: Int64? + if Int(_1!) & Int(1 << 0) != 0 {_3 = reader.readInt64() } + var _4: String? + if Int(_1!) & Int(1 << 1) != 0 {_4 = parseString(reader) } + var _5: String? + if Int(_1!) & Int(1 << 2) != 0 {_5 = parseString(reader) } + var _6: String? + if Int(_1!) & Int(1 << 3) != 0 {_6 = parseString(reader) } + var _7: String? + if Int(_1!) & Int(1 << 4) != 0 {_7 = parseString(reader) } + var _8: MacosLegacy.UserProfilePhoto? + if Int(_1!) & Int(1 << 5) != 0 {if let signature = reader.readInt32() { + _8 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.UserProfilePhoto + } } + var _9: MacosLegacy.UserStatus? + if Int(_1!) & Int(1 << 6) != 0 {if let signature = reader.readInt32() { + _9 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.UserStatus + } } + var _10: Int32? + if Int(_1!) & Int(1 << 14) != 0 {_10 = reader.readInt32() } + var _11: String? + if Int(_1!) & Int(1 << 18) != 0 {_11 = parseString(reader) } + var _12: String? + if Int(_1!) & Int(1 << 19) != 0 {_12 = parseString(reader) } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil + let _c4 = (Int(_1!) & Int(1 << 1) == 0) || _4 != nil + let _c5 = (Int(_1!) & Int(1 << 2) == 0) || _5 != nil + let _c6 = (Int(_1!) & Int(1 << 3) == 0) || _6 != nil + let _c7 = (Int(_1!) & Int(1 << 4) == 0) || _7 != nil + let _c8 = (Int(_1!) & Int(1 << 5) == 0) || _8 != nil + let _c9 = (Int(_1!) & Int(1 << 6) == 0) || _9 != nil + let _c10 = (Int(_1!) & Int(1 << 14) == 0) || _10 != nil + let _c11 = (Int(_1!) & Int(1 << 18) == 0) || _11 != nil + let _c12 = (Int(_1!) & Int(1 << 19) == 0) || _12 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 { + return MacosLegacy.User.user(flags: _1!, id: _2!, accessHash: _3, firstName: _4, lastName: _5, username: _6, phone: _7, photo: _8, status: _9, botInfoVersion: _10, restrictionReason: _11, botInlinePlaceholder: _12) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .userEmpty(let id): + return "(userEmpty id: \(id))" + case .user(let flags, let id, let accessHash, let firstName, let lastName, let username, let phone, let photo, let status, let botInfoVersion, let restrictionReason, let botInlinePlaceholder): + return "(user flags: \(flags), id: \(id), accessHash: \(accessHash), firstName: \(firstName), lastName: \(lastName), username: \(username), phone: \(phone), photo: \(photo), status: \(status), botInfoVersion: \(botInfoVersion), restrictionReason: \(restrictionReason), botInlinePlaceholder: \(botInlinePlaceholder))" + } + } + } + } + + public enum Message: CustomStringConvertible { + case destructMessage(flags: Int32, id: Int32, fromId: Int32, toId: MacosLegacy.Peer, date: Int32, message: String, media: MacosLegacy.MessageMedia, destructionTime: Int32, random: Int64, fakeId: Int32, ttlSeconds: Int32, outSeqNo: Int32, dstate: Int32) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .destructMessage(let flags, let id, let fromId, let toId, let date, let message, let media, let destructionTime, let random, let fakeId, let ttlSeconds, let outSeqNo, let dstate): + if boxed { + buffer.appendInt32(4) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(id, buffer: buffer, boxed: false) + serializeInt32(fromId, buffer: buffer, boxed: false) + toId.serialize(buffer, true) + serializeInt32(date, buffer: buffer, boxed: false) + serializeString(message, buffer: buffer, boxed: false) + media.serialize(buffer, true) + serializeInt32(destructionTime, buffer: buffer, boxed: false) + serializeInt64(random, buffer: buffer, boxed: false) + serializeInt32(fakeId, buffer: buffer, boxed: false) + serializeInt32(ttlSeconds, buffer: buffer, boxed: false) + serializeInt32(outSeqNo, buffer: buffer, boxed: false) + serializeInt32(dstate, buffer: buffer, boxed: false) + break + } + return true + } + + fileprivate static func parse_destructMessage(_ reader: BufferReader) -> Message? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: Int32? + _3 = reader.readInt32() + var _4: MacosLegacy.Peer? + if let signature = reader.readInt32() { + _4 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.Peer + } + var _5: Int32? + _5 = reader.readInt32() + var _6: String? + _6 = parseString(reader) + var _7: MacosLegacy.MessageMedia? + if let signature = reader.readInt32() { + _7 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.MessageMedia + } + var _8: Int32? + _8 = reader.readInt32() + var _9: Int64? + _9 = reader.readInt64() + var _10: Int32? + _10 = reader.readInt32() + var _11: Int32? + _11 = reader.readInt32() + var _12: Int32? + _12 = reader.readInt32() + var _13: Int32? + _13 = 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 + let _c8 = _8 != nil + let _c9 = _9 != nil + let _c10 = _10 != nil + let _c11 = _11 != nil + let _c12 = _12 != nil + let _c13 = _13 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 { + return MacosLegacy.Message.destructMessage(flags: _1!, id: _2!, fromId: _3!, toId: _4!, date: _5!, message: _6!, media: _7!, destructionTime: _8!, random: _9!, fakeId: _10!, ttlSeconds: _11!, outSeqNo: _12!, dstate: _13!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .destructMessage(let flags, let id, let fromId, let toId, let date, let message, let media, let destructionTime, let random, let fakeId, let ttlSeconds, let outSeqNo, let dstate): + return "(destructMessage flags: \(flags), id: \(id), fromId: \(fromId), toId: \(toId), date: \(date), message: \(message), media: \(media), destructionTime: \(destructionTime), random: \(random), fakeId: \(fakeId), ttlSeconds: \(ttlSeconds), outSeqNo: \(outSeqNo), dstate: \(dstate))" + } + } + } + } + + public enum GeoPoint: CustomStringConvertible { + case geoPointEmpty + case geoPoint(long: Double, lat: Double) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .geoPointEmpty: + if boxed { + buffer.appendInt32(286776671) + } + + break + case .geoPoint(let long, let lat): + if boxed { + buffer.appendInt32(541710092) + } + serializeDouble(long, buffer: buffer, boxed: false) + serializeDouble(lat, buffer: buffer, boxed: false) + break + } + return true + } + + fileprivate static func parse_geoPointEmpty(_ reader: BufferReader) -> GeoPoint? { + return MacosLegacy.GeoPoint.geoPointEmpty + } + fileprivate static func parse_geoPoint(_ reader: BufferReader) -> GeoPoint? { + var _1: Double? + _1 = reader.readDouble() + var _2: Double? + _2 = reader.readDouble() + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return MacosLegacy.GeoPoint.geoPoint(long: _1!, lat: _2!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .geoPointEmpty: + return "(geoPointEmpty)" + case .geoPoint(let long, let lat): + return "(geoPoint long: \(long), lat: \(lat))" + } + } + } + } + + public enum MaskCoords: CustomStringConvertible { + case maskCoords(n: Int32, x: Double, y: Double, zoom: Double) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .maskCoords(let n, let x, let y, let zoom): + if boxed { + buffer.appendInt32(-1361650766) + } + serializeInt32(n, buffer: buffer, boxed: false) + serializeDouble(x, buffer: buffer, boxed: false) + serializeDouble(y, buffer: buffer, boxed: false) + serializeDouble(zoom, buffer: buffer, boxed: false) + break + } + return true + } + + fileprivate static func parse_maskCoords(_ reader: BufferReader) -> MaskCoords? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Double? + _2 = reader.readDouble() + var _3: Double? + _3 = reader.readDouble() + var _4: Double? + _4 = reader.readDouble() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return MacosLegacy.MaskCoords.maskCoords(n: _1!, x: _2!, y: _3!, zoom: _4!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .maskCoords(let n, let x, let y, let zoom): + return "(maskCoords n: \(n), x: \(x), y: \(y), zoom: \(zoom))" + } + } + } + } + + public enum UserProfilePhoto: CustomStringConvertible { + case userProfilePhotoEmpty + case userProfilePhoto(photoId: Int64, photoSmall: MacosLegacy.FileLocation, photoBig: MacosLegacy.FileLocation) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .userProfilePhotoEmpty: + if boxed { + buffer.appendInt32(1326562017) + } + + break + case .userProfilePhoto(let photoId, let photoSmall, let photoBig): + if boxed { + buffer.appendInt32(-715532088) + } + serializeInt64(photoId, buffer: buffer, boxed: false) + photoSmall.serialize(buffer, true) + photoBig.serialize(buffer, true) + break + } + return true + } + + fileprivate static func parse_userProfilePhotoEmpty(_ reader: BufferReader) -> UserProfilePhoto? { + return MacosLegacy.UserProfilePhoto.userProfilePhotoEmpty + } + fileprivate static func parse_userProfilePhoto(_ reader: BufferReader) -> UserProfilePhoto? { + var _1: Int64? + _1 = reader.readInt64() + var _2: MacosLegacy.FileLocation? + if let signature = reader.readInt32() { + _2 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.FileLocation + } + var _3: MacosLegacy.FileLocation? + if let signature = reader.readInt32() { + _3 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.FileLocation + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + if _c1 && _c2 && _c3 { + return MacosLegacy.UserProfilePhoto.userProfilePhoto(photoId: _1!, photoSmall: _2!, photoBig: _3!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .userProfilePhotoEmpty: + return "(userProfilePhotoEmpty)" + case .userProfilePhoto(let photoId, let photoSmall, let photoBig): + return "(userProfilePhoto photoId: \(photoId), photoSmall: \(photoSmall), photoBig: \(photoBig))" + } + } + } + } + + public enum EncryptedChat: CustomStringConvertible { + case encryptedChat(id: Int32, accessHash: Int64, date: Int32, adminId: Int32, participantId: Int32, gAOrB: Buffer, keyFingerprint: Int64) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .encryptedChat(let id, let accessHash, let date, let adminId, let participantId, let gAOrB, let keyFingerprint): + if boxed { + buffer.appendInt32(-94974410) + } + serializeInt32(id, buffer: buffer, boxed: false) + serializeInt64(accessHash, buffer: buffer, boxed: false) + serializeInt32(date, buffer: buffer, boxed: false) + serializeInt32(adminId, buffer: buffer, boxed: false) + serializeInt32(participantId, buffer: buffer, boxed: false) + serializeBytes(gAOrB, buffer: buffer, boxed: false) + serializeInt64(keyFingerprint, buffer: buffer, boxed: false) + break + } + return true + } + + fileprivate static func parse_encryptedChat(_ reader: BufferReader) -> EncryptedChat? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: Int32? + _3 = reader.readInt32() + var _4: Int32? + _4 = reader.readInt32() + var _5: Int32? + _5 = reader.readInt32() + var _6: Buffer? + _6 = parseBytes(reader) + var _7: Int64? + _7 = reader.readInt64() + 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 MacosLegacy.EncryptedChat.encryptedChat(id: _1!, accessHash: _2!, date: _3!, adminId: _4!, participantId: _5!, gAOrB: _6!, keyFingerprint: _7!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .encryptedChat(let id, let accessHash, let date, let adminId, let participantId, let gAOrB, let keyFingerprint): + return "(encryptedChat id: \(id), accessHash: \(accessHash), date: \(date), adminId: \(adminId), participantId: \(participantId), gAOrB: \(gAOrB), keyFingerprint: \(keyFingerprint))" + } + } + } + } + + public enum Document: CustomStringConvertible { + case documentEmpty(id: Int64) + case document(id: Int64, accessHash: Int64, date: Int32, mimeType: String, size: Int32, thumb: MacosLegacy.PhotoSize, dcId: Int32, version: Int32, attributes: [MacosLegacy.DocumentAttribute]) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .documentEmpty(let id): + if boxed { + buffer.appendInt32(922273905) + } + serializeInt64(id, buffer: buffer, boxed: false) + break + case .document(let id, let accessHash, let date, let mimeType, let size, let thumb, let dcId, let version, let attributes): + if boxed { + buffer.appendInt32(-2027738169) + } + serializeInt64(id, buffer: buffer, boxed: false) + serializeInt64(accessHash, buffer: buffer, boxed: false) + serializeInt32(date, buffer: buffer, boxed: false) + serializeString(mimeType, buffer: buffer, boxed: false) + serializeInt32(size, buffer: buffer, boxed: false) + thumb.serialize(buffer, true) + serializeInt32(dcId, buffer: buffer, boxed: false) + serializeInt32(version, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(attributes.count)) + for item in attributes { + item.serialize(buffer, true) + } + break + } + return true + } + + fileprivate static func parse_documentEmpty(_ reader: BufferReader) -> Document? { + var _1: Int64? + _1 = reader.readInt64() + let _c1 = _1 != nil + if _c1 { + return MacosLegacy.Document.documentEmpty(id: _1!) + } + else { + return nil + } + } + fileprivate static func parse_document(_ reader: BufferReader) -> Document? { + var _1: Int64? + _1 = reader.readInt64() + var _2: Int64? + _2 = reader.readInt64() + var _3: Int32? + _3 = reader.readInt32() + var _4: String? + _4 = parseString(reader) + var _5: Int32? + _5 = reader.readInt32() + var _6: MacosLegacy.PhotoSize? + if let signature = reader.readInt32() { + _6 = MacosLegacy.parse(reader, signature: signature) as? MacosLegacy.PhotoSize + } + var _7: Int32? + _7 = reader.readInt32() + var _8: Int32? + _8 = reader.readInt32() + var _9: [MacosLegacy.DocumentAttribute]? + if let _ = reader.readInt32() { + _9 = MacosLegacy.parseVector(reader, elementSignature: 0, elementType: MacosLegacy.DocumentAttribute.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 + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 { + return MacosLegacy.Document.document(id: _1!, accessHash: _2!, date: _3!, mimeType: _4!, size: _5!, thumb: _6!, dcId: _7!, version: _8!, attributes: _9!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .documentEmpty(let id): + return "(documentEmpty id: \(id))" + case .document(let id, let accessHash, let date, let mimeType, let size, let thumb, let dcId, let version, let attributes): + return "(document id: \(id), accessHash: \(accessHash), date: \(date), mimeType: \(mimeType), size: \(size), thumb: \(thumb), dcId: \(dcId), version: \(version), attributes: \(attributes))" + } + } + } + } + + public struct functions { + + } + +} diff --git a/TelegramCore/MemoryBufferExtensions.swift b/TelegramCore/MemoryBufferExtensions.swift index 7f3bfda881..6dc8dbc7c9 100644 --- a/TelegramCore/MemoryBufferExtensions.swift +++ b/TelegramCore/MemoryBufferExtensions.swift @@ -5,8 +5,8 @@ import Foundation import Postbox #endif -extension MemoryBuffer { - convenience init(_ buffer: Buffer) { +public extension MemoryBuffer { + public convenience init(_ buffer: Buffer) { let memory = malloc(Int(buffer.size))! memcpy(memory, buffer.data, Int(buffer.size)) self.init(memory: memory, capacity: Int(buffer.size), length: Int(buffer.size), freeWhenDone: true) diff --git a/TelegramCore/SecretChatStateBridge.swift b/TelegramCore/SecretChatStateBridge.swift new file mode 100644 index 0000000000..d92f9e895f --- /dev/null +++ b/TelegramCore/SecretChatStateBridge.swift @@ -0,0 +1,22 @@ +import Foundation +#if os(macOS) + import PostboxMac +#else + import Postbox +#endif + +public enum SecretChatBridgeRole: Int32 { + case creator + case participant +} + +public struct SecretChatStateBridge { + public let role:SecretChatBridgeRole + public init(role: SecretChatBridgeRole) { + self.role = role + } + + public var state: PeerChatState { + return SecretChatState(role: SecretChatRole(rawValue: role.rawValue)!, embeddedState: .terminated, keychain: SecretChatKeychain(keys: []), keyFingerprint: nil, messageAutoremoveTimeout: nil) + } +} diff --git a/TelegramCore/StoreMessage_Telegram.swift b/TelegramCore/StoreMessage_Telegram.swift index af5222d355..13df80c1a0 100644 --- a/TelegramCore/StoreMessage_Telegram.swift +++ b/TelegramCore/StoreMessage_Telegram.swift @@ -5,7 +5,7 @@ import Foundation import Postbox #endif -func tagsForStoreMessage(media: [Media], textEntities: [MessageTextEntity]?) -> MessageTags { +public func tagsForStoreMessage(media: [Media], textEntities: [MessageTextEntity]?) -> MessageTags { var tags = MessageTags() for attachment in media { if let _ = attachment as? TelegramMediaImage { diff --git a/TelegramCore/TelegramSecretChat.swift b/TelegramCore/TelegramSecretChat.swift index 741cf67341..379cdb4266 100644 --- a/TelegramCore/TelegramSecretChat.swift +++ b/TelegramCore/TelegramSecretChat.swift @@ -20,7 +20,7 @@ public final class TelegramSecretChat: Peer { public let associatedPeerIds: [PeerId]? public let notificationSettingsPeerId: PeerId? - init(id: PeerId, creationDate: Int32, regularPeerId: PeerId, accessHash: Int64, embeddedState: SecretChatEmbeddedPeerState, messageAutoremoveTimeout: Int32?) { + public init(id: PeerId, creationDate: Int32, regularPeerId: PeerId, accessHash: Int64, embeddedState: SecretChatEmbeddedPeerState, messageAutoremoveTimeout: Int32?) { self.id = id self.regularPeerId = regularPeerId self.accessHash = accessHash From f99074c62df755f4088880ba8d446f58edb3bcf4 Mon Sep 17 00:00:00 2001 From: overtake Date: Sun, 12 Mar 2017 19:04:13 +0300 Subject: [PATCH 3/5] for migration --- TelegramCore/AutoremoveTimeoutMessageAttribute.swift | 2 +- TelegramCore/SecretChatStateBridge.swift | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/TelegramCore/AutoremoveTimeoutMessageAttribute.swift b/TelegramCore/AutoremoveTimeoutMessageAttribute.swift index 0bde572c3f..fff20501f4 100644 --- a/TelegramCore/AutoremoveTimeoutMessageAttribute.swift +++ b/TelegramCore/AutoremoveTimeoutMessageAttribute.swift @@ -15,7 +15,7 @@ public class AutoremoveTimeoutMessageAttribute: MessageAttribute { public var associatedMessageIds: [MessageId] = [] - init(timeout: Int32, countdownBeginTime: Int32?) { + public init(timeout: Int32, countdownBeginTime: Int32?) { self.timeout = timeout self.countdownBeginTime = countdownBeginTime } diff --git a/TelegramCore/SecretChatStateBridge.swift b/TelegramCore/SecretChatStateBridge.swift index d92f9e895f..a27d66b264 100644 --- a/TelegramCore/SecretChatStateBridge.swift +++ b/TelegramCore/SecretChatStateBridge.swift @@ -19,4 +19,11 @@ public struct SecretChatStateBridge { public var state: PeerChatState { return SecretChatState(role: SecretChatRole(rawValue: role.rawValue)!, embeddedState: .terminated, keychain: SecretChatKeychain(keys: []), keyFingerprint: nil, messageAutoremoveTimeout: nil) } + + +} + + +public func terminateLegacySecretChat(modifier: Modifier, peerId: PeerId, state: SecretChatStateBridge) -> PeerChatState { + return addSecretChatOutgoingOperation(modifier: modifier, peerId: peerId, operation: SecretChatOutgoingOperationContents.terminate, state: state.state as! SecretChatState).withUpdatedEmbeddedState(.terminated) } From edd14a8f418099adc4c5b1901a33b4e69f301d2e Mon Sep 17 00:00:00 2001 From: overtake Date: Mon, 13 Mar 2017 19:43:35 +0300 Subject: [PATCH 4/5] no message --- TelegramCore/Account.swift | 3 +++ TelegramCore/EnqueueMessage.swift | 9 ++++++++- TelegramCore/StoreMessage_Telegram.swift | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/TelegramCore/Account.swift b/TelegramCore/Account.swift index e9f91b02f1..1313a58774 100644 --- a/TelegramCore/Account.swift +++ b/TelegramCore/Account.swift @@ -204,6 +204,7 @@ private var declaredEncodables: Void = { declareEncodable(GlobalNotificationSettings.self, f: { GlobalNotificationSettings(decoder: $0) }) declareEncodable(CloudChatRemoveChatOperation.self, f: { CloudChatRemoveChatOperation(decoder: $0) }) declareEncodable(SynchronizePinnedChatsOperation.self, f: { SynchronizePinnedChatsOperation(decoder: $0) }) + declareEncodable(SynchronizeConsumeMessageContentsOperation.self, f: { SynchronizeConsumeMessageContentsOperation(decoder: $0) }) declareEncodable(RecentMediaItem.self, f: { RecentMediaItem(decoder: $0) }) declareEncodable(RecentPeerItem.self, f: { RecentPeerItem(decoder: $0) }) declareEncodable(LoggedOutAccountAttribute.self, f: { LoggedOutAccountAttribute(decoder: $0) }) @@ -529,6 +530,8 @@ public class Account { self.managedOperationsDisposable.add(managedRecentGifs(postbox: self.postbox, network: self.network).start()) self.managedOperationsDisposable.add(managedRecentlyUsedInlineBots(postbox: self.postbox, network: self.network).start()) self.managedOperationsDisposable.add(managedLocalTypingActivities(activities: self.localInputActivityManager.allActivities(), postbox: self.postbox, network: self.network).start()) + self.managedOperationsDisposable.add(managedSynchronizeConsumeMessageContentOperations(postbox: self.postbox, network: self.network, stateManager : self.stateManager).start()) + let updatedPresence = self.shouldKeepOnlinePresence.get() |> distinctUntilChanged diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index b7c99926c8..6a6418fe47 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -189,7 +189,14 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa } } - storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(media: mediaList, textEntities: entitiesAttribute?.entities), forwardInfo: nil, authorId: account.peerId, text: text, attributes: attributes, media: mediaList)) + let authorId:PeerId? + if let peer = peer as? TelegramChannel, case let .broadcast(info) = peer.info, !info.flags.contains(.messagesShouldHaveSignatures) { + authorId = nil + } else { + authorId = account.peerId + } + + storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(media: mediaList, textEntities: entitiesAttribute?.entities), forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: mediaList)) case let .forward(source): if let sourceMessage = modifier.getMessage(source), let author = sourceMessage.author { if let peer = peer as? TelegramSecretChat { diff --git a/TelegramCore/StoreMessage_Telegram.swift b/TelegramCore/StoreMessage_Telegram.swift index 13df80c1a0..9eadbdf038 100644 --- a/TelegramCore/StoreMessage_Telegram.swift +++ b/TelegramCore/StoreMessage_Telegram.swift @@ -345,10 +345,11 @@ extension StoreMessage { } } - if let file = media as? TelegramMediaFile { + for case let file as TelegramMediaFile in medias { if peerId.namespace == Namespaces.Peer.CloudUser || peerId.namespace == Namespaces.Peer.CloudGroup { if file.isVoice { - attributes.append(ConsumableContentMessageAttribute(consumed: (flags & (1 << 5)) != 0)) + attributes.append(ConsumableContentMessageAttribute(consumed: (flags & (1 << 5)) == 0)) + break } } } From 3ca08f7aae8e4c108730926be5954d371b4d5ef7 Mon Sep 17 00:00:00 2001 From: overtake Date: Tue, 14 Mar 2017 17:14:49 +0300 Subject: [PATCH 5/5] forward messages fro channel with unsigned messages --- TelegramCore/EnqueueMessage.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index 6a6418fe47..0ee421d686 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -198,7 +198,7 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(media: mediaList, textEntities: entitiesAttribute?.entities), forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: mediaList)) case let .forward(source): - if let sourceMessage = modifier.getMessage(source), let author = sourceMessage.author { + if let sourceMessage = modifier.getMessage(source), let author = sourceMessage.author ?? sourceMessage.peers[sourceMessage.id.peerId] { if let peer = peer as? TelegramSecretChat { var isAction = false for media in sourceMessage.media {