diff --git a/TelegramCore.xcodeproj/project.pbxproj b/TelegramCore.xcodeproj/project.pbxproj index 4f9e26ebda..cce4390154 100644 --- a/TelegramCore.xcodeproj/project.pbxproj +++ b/TelegramCore.xcodeproj/project.pbxproj @@ -268,6 +268,13 @@ D0528E661E65C82400E2FEF5 /* UpdateContactName.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0528E641E65C82400E2FEF5 /* UpdateContactName.swift */; }; D0528E6A1E65DD2100E2FEF5 /* WebpagePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0528E691E65DD2100E2FEF5 /* WebpagePreview.swift */; }; D0528E6B1E65DD2100E2FEF5 /* WebpagePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0528E691E65DD2100E2FEF5 /* WebpagePreview.swift */; }; + D053B3FB1F1651FA00E2D58A /* MonotonicTime.h in Headers */ = {isa = PBXBuildFile; fileRef = D053B3F91F1651FA00E2D58A /* MonotonicTime.h */; }; + D053B3FC1F1651FA00E2D58A /* MonotonicTime.m in Sources */ = {isa = PBXBuildFile; fileRef = D053B3FA1F1651FA00E2D58A /* MonotonicTime.m */; }; + D053B3FE1F16534400E2D58A /* MonotonicTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053B3FD1F16534400E2D58A /* MonotonicTime.swift */; }; + D053B4181F18DE4F00E2D58A /* AuthorSignatureMessageAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053B4171F18DE4F00E2D58A /* AuthorSignatureMessageAttribute.swift */; }; + D053B4191F18DE5000E2D58A /* AuthorSignatureMessageAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053B4171F18DE4F00E2D58A /* AuthorSignatureMessageAttribute.swift */; }; + D053B41B1F18DEF500E2D58A /* TelegramMediaExpiredContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053B41A1F18DEF500E2D58A /* TelegramMediaExpiredContent.swift */; }; + D053B41C1F18DEF500E2D58A /* TelegramMediaExpiredContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D053B41A1F18DEF500E2D58A /* TelegramMediaExpiredContent.swift */; }; D05452071E7B5093006EEF19 /* LoadedStickerPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05452061E7B5093006EEF19 /* LoadedStickerPack.swift */; }; D05452081E7B5093006EEF19 /* LoadedStickerPack.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05452061E7B5093006EEF19 /* LoadedStickerPack.swift */; }; D0561DE31E5737FC00E6B9E9 /* UpdatePeerInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0561DE21E5737FC00E6B9E9 /* UpdatePeerInfo.swift */; }; @@ -670,7 +677,7 @@ D03B0E571D631EB900955575 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; }; D03B0E591D63215200955575 /* TelegramCore.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = TelegramCore.xcconfig; path = TelegramCore/Config/TelegramCore.xcconfig; sourceTree = ""; }; D03B0E5B1D63240700955575 /* TelegramCoreIncludes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TelegramCoreIncludes.h; sourceTree = ""; }; - D03B0E5D1D6327F600955575 /* SSignalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SSignalKit.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug-iphonesimulator/SSignalKit.framework"; sourceTree = ""; }; + D03B0E5D1D6327F600955575 /* SSignalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SSignalKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D03B0E5F1D6327FF00955575 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; D03B0E611D63281A00955575 /* libavcodec.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libavcodec.a; path = "third-party/FFmpeg-iOS/lib/libavcodec.a"; sourceTree = ""; }; D03B0E621D63281A00955575 /* libavformat.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libavformat.a; path = "third-party/FFmpeg-iOS/lib/libavformat.a"; sourceTree = ""; }; @@ -702,6 +709,11 @@ D0528E5F1E65B94E00E2FEF5 /* SingleMessageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleMessageView.swift; sourceTree = ""; }; D0528E641E65C82400E2FEF5 /* UpdateContactName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateContactName.swift; sourceTree = ""; }; D0528E691E65DD2100E2FEF5 /* WebpagePreview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebpagePreview.swift; sourceTree = ""; }; + D053B3F91F1651FA00E2D58A /* MonotonicTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MonotonicTime.h; sourceTree = ""; }; + D053B3FA1F1651FA00E2D58A /* MonotonicTime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MonotonicTime.m; sourceTree = ""; }; + D053B3FD1F16534400E2D58A /* MonotonicTime.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MonotonicTime.swift; sourceTree = ""; }; + D053B4171F18DE4F00E2D58A /* AuthorSignatureMessageAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthorSignatureMessageAttribute.swift; sourceTree = ""; }; + D053B41A1F18DEF500E2D58A /* TelegramMediaExpiredContent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TelegramMediaExpiredContent.swift; sourceTree = ""; }; D05452061E7B5093006EEF19 /* LoadedStickerPack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadedStickerPack.swift; sourceTree = ""; }; D0561DE21E5737FC00E6B9E9 /* UpdatePeerInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdatePeerInfo.swift; sourceTree = ""; }; D0561DE91E5754FA00E6B9E9 /* ChannelAdmins.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChannelAdmins.swift; sourceTree = ""; }; @@ -714,11 +726,11 @@ D0613FC91E60440600202CDB /* InvitationLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InvitationLinks.swift; sourceTree = ""; }; D0613FCE1E60520700202CDB /* ChannelMembers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChannelMembers.swift; sourceTree = ""; }; D0613FD61E606B3B00202CDB /* ConvertGroupToSupergroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConvertGroupToSupergroup.swift; sourceTree = ""; }; - D06706641D512ADB00DED3E3 /* AsyncDisplayKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AsyncDisplayKit.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug-iphonesimulator/AsyncDisplayKit.framework"; sourceTree = ""; }; - D06706651D512ADB00DED3E3 /* Display.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Display.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug-iphonesimulator/Display.framework"; sourceTree = ""; }; - D06706671D512ADB00DED3E3 /* Postbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Postbox.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug-iphonesimulator/Postbox.framework"; sourceTree = ""; }; - D06706681D512ADB00DED3E3 /* SwiftSignalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftSignalKit.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug-iphonesimulator/SwiftSignalKit.framework"; sourceTree = ""; }; - D067066E1D512AEB00DED3E3 /* MtProtoKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MtProtoKit.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug-iphonesimulator/MtProtoKit.framework"; sourceTree = ""; }; + D06706641D512ADB00DED3E3 /* AsyncDisplayKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = AsyncDisplayKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + D06706651D512ADB00DED3E3 /* Display.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Display.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + D06706671D512ADB00DED3E3 /* Postbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Postbox.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + D06706681D512ADB00DED3E3 /* SwiftSignalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SwiftSignalKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + D067066E1D512AEB00DED3E3 /* MtProtoKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = MtProtoKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D073CE5C1DCB97F6007511FD /* ForwardSourceInfoAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ForwardSourceInfoAttribute.swift; sourceTree = ""; }; D073CE5F1DCB9D14007511FD /* OutgoingMessageInfoAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OutgoingMessageInfoAttribute.swift; sourceTree = ""; }; D0754D291EEE10FC00884F6E /* BotPaymentForm.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BotPaymentForm.swift; sourceTree = ""; }; @@ -754,14 +766,14 @@ D0AB0B931D662ECE002C78E7 /* ManagedMessageHistoryHoles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedMessageHistoryHoles.swift; sourceTree = ""; }; D0AB0B951D662F0B002C78E7 /* ManagedChatListHoles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedChatListHoles.swift; sourceTree = ""; }; D0AB0B991D666520002C78E7 /* ManagedSynchronizePeerReadStates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedSynchronizePeerReadStates.swift; sourceTree = ""; }; - D0AC49491D7097A400AA55DA /* SSignalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SSignalKit.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug-iphoneos/SSignalKit.framework"; sourceTree = ""; }; + D0AC49491D7097A400AA55DA /* SSignalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SSignalKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D0B417C01D7DCEEF004562A4 /* ApiGroupOrChannel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApiGroupOrChannel.swift; sourceTree = ""; }; D0B418671D7E03D5004562A4 /* TelegramCoreMac.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TelegramCoreMac.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D0B418691D7E03D5004562A4 /* TelegramCoreMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TelegramCoreMac.h; sourceTree = ""; }; D0B4186A1D7E03D5004562A4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - D0B418701D7E0409004562A4 /* PostboxMac.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PostboxMac.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug/PostboxMac.framework"; sourceTree = ""; }; - D0B418711D7E0409004562A4 /* SwiftSignalKitMac.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftSignalKitMac.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug/SwiftSignalKitMac.framework"; sourceTree = ""; }; - D0B4187E1D7E054E004562A4 /* MtProtoKitMac.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MtProtoKitMac.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug/MtProtoKitMac.framework"; sourceTree = ""; }; + D0B418701D7E0409004562A4 /* PostboxMac.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = PostboxMac.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + D0B418711D7E0409004562A4 /* SwiftSignalKitMac.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SwiftSignalKitMac.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + D0B4187E1D7E054E004562A4 /* MtProtoKitMac.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = MtProtoKitMac.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D0B477721EBF54A20033A0AB /* RecentCalls.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecentCalls.swift; sourceTree = ""; }; D0B843801DA6EDAE005F29E1 /* CachedUserData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CachedUserData.swift; sourceTree = ""; }; D0B843821DA6EDB8005F29E1 /* CachedGroupData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CachedGroupData.swift; sourceTree = ""; }; @@ -813,7 +825,7 @@ D0C48F381E8138DF0075317D /* ArchivedStickerPacksInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArchivedStickerPacksInfo.swift; sourceTree = ""; }; D0C48F3B1E8142EF0075317D /* LoadedPeerFromMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadedPeerFromMessage.swift; sourceTree = ""; }; D0C50E331E93A86600F62E39 /* CallSessionManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallSessionManager.swift; sourceTree = ""; }; - D0CAF2E91D75EC600011F558 /* MtProtoKitDynamic.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MtProtoKitDynamic.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Telegram-iOS-diblohvjozhgaifjcniwdlixlilx/Build/Products/Debug-iphonesimulator/MtProtoKitDynamic.framework"; sourceTree = ""; }; + D0CAF2E91D75EC600011F558 /* MtProtoKitDynamic.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = MtProtoKitDynamic.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D0D748011E7AE98B00F4B1F6 /* StickerPackInteractiveOperations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickerPackInteractiveOperations.swift; sourceTree = ""; }; D0DC354D1DE368F7000195EB /* RequestChatContextResults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestChatContextResults.swift; sourceTree = ""; }; D0DC354F1DE36900000195EB /* ChatContextResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatContextResult.swift; sourceTree = ""; }; @@ -995,6 +1007,7 @@ D04CAA591E83310D0047E51F /* MD5.swift */, D042C6821E8D9DF800C863B0 /* Unixtime.swift */, D01C7F031EFC1C49008305F1 /* DeviceContact.swift */, + D053B3FD1F16534400E2D58A /* MonotonicTime.swift */, ); name = Utils; sourceTree = ""; @@ -1061,6 +1074,7 @@ D03B0CE51D6224A700955575 /* ReplyMessageAttribute.swift */, D03B0CE31D62249F00955575 /* TextEntitiesMessageAttribute.swift */, D03B0CE11D62249B00955575 /* InlineBotMessageAttribute.swift */, + D053B4171F18DE4F00E2D58A /* AuthorSignatureMessageAttribute.swift */, D073CE5C1DCB97F6007511FD /* ForwardSourceInfoAttribute.swift */, D073CE5F1DCB9D14007511FD /* OutgoingMessageInfoAttribute.swift */, D0F7AB2B1DCE889D009AD9A1 /* EditedMessageAttribute.swift */, @@ -1085,6 +1099,7 @@ D03B0CF11D62250800955575 /* TelegramMediaMap.swift */, D03B0CF31D62250800955575 /* TelegramMediaWebpage.swift */, D00D343B1E6EC9770057B307 /* TelegramMediaGame.swift */, + D053B41A1F18DEF500E2D58A /* TelegramMediaExpiredContent.swift */, D07827CA1E02F5B200071108 /* RichText.swift */, D07827C81E02F59C00071108 /* InstantPage.swift */, C2E064671ECEEF0A00387BB8 /* TelegramMediaInvoice.swift */, @@ -1233,6 +1248,8 @@ D03B0E5B1D63240700955575 /* TelegramCoreIncludes.h */, D03B0E411D631E6600955575 /* NetworkLogging.h */, D03B0E421D631E6600955575 /* NetworkLogging.m */, + D053B3F91F1651FA00E2D58A /* MonotonicTime.h */, + D053B3FA1F1651FA00E2D58A /* MonotonicTime.m */, ); name = "Supporting Files"; sourceTree = ""; @@ -1468,6 +1485,7 @@ D0B843B41DA7FF30005F29E1 /* NBMetadataCore.h in Headers */, D0B843C41DA7FF30005F29E1 /* NBPhoneNumber.h in Headers */, D0B843B31DA7FF30005F29E1 /* NBAsYouTypeFormatter.h in Headers */, + D053B3FB1F1651FA00E2D58A /* MonotonicTime.h in Headers */, D0B843C81DA7FF30005F29E1 /* NBPhoneNumberDesc.h in Headers */, D0B843CA1DA7FF30005F29E1 /* NBPhoneNumberUtil.h in Headers */, D0B843BA1DA7FF30005F29E1 /* NBMetadataCoreTestMapper.h in Headers */, @@ -1660,6 +1678,7 @@ D0B843B91DA7FF30005F29E1 /* NBMetadataCoreTest.m in Sources */, D09A2FE61D7CD4940018FB72 /* TelegramChannel.swift in Sources */, D03B0D0E1D62255C00955575 /* UpdateGroup.swift in Sources */, + D053B4181F18DE4F00E2D58A /* AuthorSignatureMessageAttribute.swift in Sources */, D0F3A89F1E82C65400B4C64C /* SynchronizeChatInputStateOperation.swift in Sources */, D01AC9231DD5E9A200E8160F /* ApplyUpdateMessage.swift in Sources */, D03B0CF71D62250800955575 /* TelegramMediaImage.swift in Sources */, @@ -1669,6 +1688,7 @@ C205FEA81EB3B75900455808 /* ExportMessageLink.swift in Sources */, D0E305AA1E5BA02D00D7A3A2 /* ChannelBlacklist.swift in Sources */, C22EE61B1E67418000334C38 /* ToggleChannelSignatures.swift in Sources */, + D053B3FC1F1651FA00E2D58A /* MonotonicTime.m in Sources */, D073CE601DCB9D14007511FD /* OutgoingMessageInfoAttribute.swift in Sources */, D0AAD1A81E32602500D5B9DE /* AutoremoveTimeoutMessageAttribute.swift in Sources */, C2366C831E4F3EAA0097CCFF /* GroupReturnAndLeft.swift in Sources */, @@ -1722,6 +1742,7 @@ C2E0646D1ECF171D00387BB8 /* TelegramMediaWebDocument.swift in Sources */, D0B843811DA6EDAE005F29E1 /* CachedUserData.swift in Sources */, D049EAD51E43D98500A2CD3A /* RecentMediaItem.swift in Sources */, + D053B3FE1F16534400E2D58A /* MonotonicTime.swift in Sources */, D0C50E341E93A86600F62E39 /* CallSessionManager.swift in Sources */, D00D34421E6EDD2E0057B307 /* ManagedSynchronizeConsumeMessageContentsOperations.swift in Sources */, D099D7491EEF418D00A3128C /* HistoryViewChannelStateValidation.swift in Sources */, @@ -1764,6 +1785,7 @@ D03B0CD61D62245300955575 /* TelegramUser.swift in Sources */, D019B1CC1E2E3B6A00F80DB3 /* SecretChatRekeySession.swift in Sources */, D03B0CD91D62245B00955575 /* PeerUtils.swift in Sources */, + D053B41B1F18DEF500E2D58A /* TelegramMediaExpiredContent.swift in Sources */, D03B0CE41D62249F00955575 /* TextEntitiesMessageAttribute.swift in Sources */, D0FA35081EA632E400E56FFA /* CollectCacheUsageStats.swift in Sources */, D049EAEB1E44B71B00A2CD3A /* RecentlySearchedPeerIds.swift in Sources */, @@ -2118,6 +2140,7 @@ D050F2641E4A5AEB00988324 /* ManagedSynchronizePinnedChatsOperations.swift in Sources */, D0575AF21E9FFA5D006F2541 /* SynchronizeSavedGifsOperation.swift in Sources */, D0528E661E65C82400E2FEF5 /* UpdateContactName.swift in Sources */, + D053B4191F18DE5000E2D58A /* AuthorSignatureMessageAttribute.swift in Sources */, D0F7B1E81E045C87007EB8A5 /* PeerParticipants.swift in Sources */, D0C48F3A1E8138DF0075317D /* ArchivedStickerPacksInfo.swift in Sources */, D049EAD61E43D98500A2CD3A /* RecentMediaItem.swift in Sources */, @@ -2148,6 +2171,7 @@ D08CAA7E1ED77EE90000FDA8 /* LocalizationSettings.swift in Sources */, D0448CA01E27F5EB005A61A7 /* Random.swift in Sources */, C251D7441E65E50500283EDE /* StickerSetInstallation.swift in Sources */, + D053B41C1F18DEF500E2D58A /* TelegramMediaExpiredContent.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2162,7 +2186,7 @@ /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ - C22069BE1E8EB4A200E82730 /* AppStore */ = { + C22069BE1E8EB4A200E82730 /* Release Hockeyapp */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2206,9 +2230,9 @@ VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; - name = AppStore; + name = "Release Hockeyapp"; }; - C22069BF1E8EB4A200E82730 /* AppStore */ = { + C22069BF1E8EB4A200E82730 /* Release Hockeyapp */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2241,9 +2265,9 @@ SWIFT_VERSION = 3.0; USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/third-party/FFmpeg-iOS/include"; }; - name = AppStore; + name = "Release Hockeyapp"; }; - C22069C01E8EB4A200E82730 /* AppStore */ = { + C22069C01E8EB4A200E82730 /* Release Hockeyapp */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2252,10 +2276,11 @@ PRODUCT_BUNDLE_IDENTIFIER = org.telegram.Telegram.TelegramCoreTests; PRODUCT_NAME = "$(TARGET_NAME)"; }; - name = AppStore; + name = "Release Hockeyapp"; }; - C22069C11E8EB4A200E82730 /* AppStore */ = { + C22069C11E8EB4A200E82730 /* Release Hockeyapp */ = { isa = XCBuildConfiguration; + baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_WARN_INFINITE_RECURSION = YES; @@ -2279,9 +2304,9 @@ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; }; - name = AppStore; + name = "Release Hockeyapp"; }; - D06706551D51162400DED3E3 /* Hockeyapp */ = { + D06706551D51162400DED3E3 /* Release AppStore */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2325,9 +2350,9 @@ VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; - name = Hockeyapp; + name = "Release AppStore"; }; - D06706561D51162400DED3E3 /* Hockeyapp */ = { + D06706561D51162400DED3E3 /* Release AppStore */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2360,9 +2385,9 @@ SWIFT_VERSION = 3.0; USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/third-party/FFmpeg-iOS/include"; }; - name = Hockeyapp; + name = "Release AppStore"; }; - D06706571D51162400DED3E3 /* Hockeyapp */ = { + D06706571D51162400DED3E3 /* Release AppStore */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2371,9 +2396,9 @@ PRODUCT_BUNDLE_IDENTIFIER = org.telegram.Telegram.TelegramCoreTests; PRODUCT_NAME = "$(TARGET_NAME)"; }; - name = Hockeyapp; + name = "Release AppStore"; }; - D09D8C131D4FAB1D0081DBEC /* Debug */ = { + D09D8C131D4FAB1D0081DBEC /* Debug Hockeyapp */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2423,9 +2448,9 @@ VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; - name = Debug; + name = "Debug Hockeyapp"; }; - D09D8C141D4FAB1D0081DBEC /* Release */ = { + D09D8C141D4FAB1D0081DBEC /* Debug AppStore */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2462,6 +2487,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; + ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/third-party/FFmpeg-iOS/include"; @@ -2469,9 +2495,9 @@ VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; - name = Release; + name = "Debug AppStore"; }; - D09D8C161D4FAB1D0081DBEC /* Debug */ = { + D09D8C161D4FAB1D0081DBEC /* Debug Hockeyapp */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2504,9 +2530,9 @@ SWIFT_VERSION = 3.0; USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/third-party/FFmpeg-iOS/include"; }; - name = Debug; + name = "Debug Hockeyapp"; }; - D09D8C171D4FAB1D0081DBEC /* Release */ = { + D09D8C171D4FAB1D0081DBEC /* Debug AppStore */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2515,12 +2541,13 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; - COPY_PHASE_STRIP = YES; + COPY_PHASE_STRIP = NO; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = X834Q8SBVP; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = 0; INFOPLIST_FILE = TelegramCore/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -2534,14 +2561,14 @@ PRODUCT_BUNDLE_IDENTIFIER = org.telegram.TelegramCore; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_REFLECTION_METADATA_LEVEL = none; SWIFT_VERSION = 3.0; USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/third-party/FFmpeg-iOS/include"; }; - name = Release; + name = "Debug AppStore"; }; - D09D8C191D4FAB1D0081DBEC /* Debug */ = { + D09D8C191D4FAB1D0081DBEC /* Debug Hockeyapp */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2550,9 +2577,9 @@ PRODUCT_BUNDLE_IDENTIFIER = org.telegram.Telegram.TelegramCoreTests; PRODUCT_NAME = "$(TARGET_NAME)"; }; - name = Debug; + name = "Debug Hockeyapp"; }; - D09D8C1A1D4FAB1D0081DBEC /* Release */ = { + D09D8C1A1D4FAB1D0081DBEC /* Debug AppStore */ = { isa = XCBuildConfiguration; baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { @@ -2561,10 +2588,11 @@ PRODUCT_BUNDLE_IDENTIFIER = org.telegram.Telegram.TelegramCoreTests; PRODUCT_NAME = "$(TARGET_NAME)"; }; - name = Release; + name = "Debug AppStore"; }; - D0B4186D1D7E03D5004562A4 /* Debug */ = { + D0B4186D1D7E03D5004562A4 /* Debug Hockeyapp */ = { isa = XCBuildConfiguration; + baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_WARN_INFINITE_RECURSION = YES; @@ -2590,10 +2618,39 @@ SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 3.0; }; - name = Debug; + name = "Debug Hockeyapp"; }; - D0B4186E1D7E03D5004562A4 /* Release */ = { + D0B4186E1D7E03D5004562A4 /* Debug AppStore */ = { isa = XCBuildConfiguration; + baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVES = YES; + CODE_SIGN_IDENTITY = "-"; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = TelegramCoreMac/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.11; + PRODUCT_BUNDLE_IDENTIFIER = org.telegram.Telegram.TelegramCoreMac; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; + }; + name = "Debug AppStore"; + }; + D0B4186F1D7E03D5004562A4 /* Release AppStore */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = D03B0E591D63215200955575 /* TelegramCore.xcconfig */; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_WARN_INFINITE_RECURSION = YES; @@ -2617,34 +2674,7 @@ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; }; - name = Release; - }; - D0B4186F1D7E03D5004562A4 /* Hockeyapp */ = { - isa = XCBuildConfiguration; - buildSettings = { - APPLICATION_EXTENSION_API_ONLY = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_SUSPICIOUS_MOVES = YES; - CODE_SIGN_IDENTITY = "-"; - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - INFOPLIST_FILE = TelegramCoreMac/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.11; - PRODUCT_BUNDLE_IDENTIFIER = org.telegram.Telegram.TelegramCoreMac; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SKIP_INSTALL = YES; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; - }; - name = Hockeyapp; + name = "Release AppStore"; }; /* End XCBuildConfiguration section */ @@ -2652,46 +2682,46 @@ D09D8BFB1D4FAB1D0081DBEC /* Build configuration list for PBXProject "TelegramCore" */ = { isa = XCConfigurationList; buildConfigurations = ( - D09D8C131D4FAB1D0081DBEC /* Debug */, - D09D8C141D4FAB1D0081DBEC /* Release */, - C22069BE1E8EB4A200E82730 /* AppStore */, - D06706551D51162400DED3E3 /* Hockeyapp */, + D09D8C131D4FAB1D0081DBEC /* Debug Hockeyapp */, + D09D8C141D4FAB1D0081DBEC /* Debug AppStore */, + C22069BE1E8EB4A200E82730 /* Release Hockeyapp */, + D06706551D51162400DED3E3 /* Release AppStore */, ); defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; + defaultConfigurationName = "Debug AppStore"; }; D09D8C151D4FAB1D0081DBEC /* Build configuration list for PBXNativeTarget "TelegramCore" */ = { isa = XCConfigurationList; buildConfigurations = ( - D09D8C161D4FAB1D0081DBEC /* Debug */, - D09D8C171D4FAB1D0081DBEC /* Release */, - C22069BF1E8EB4A200E82730 /* AppStore */, - D06706561D51162400DED3E3 /* Hockeyapp */, + D09D8C161D4FAB1D0081DBEC /* Debug Hockeyapp */, + D09D8C171D4FAB1D0081DBEC /* Debug AppStore */, + C22069BF1E8EB4A200E82730 /* Release Hockeyapp */, + D06706561D51162400DED3E3 /* Release AppStore */, ); defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; + defaultConfigurationName = "Debug AppStore"; }; D09D8C181D4FAB1D0081DBEC /* Build configuration list for PBXNativeTarget "TelegramCoreTests" */ = { isa = XCConfigurationList; buildConfigurations = ( - D09D8C191D4FAB1D0081DBEC /* Debug */, - D09D8C1A1D4FAB1D0081DBEC /* Release */, - C22069C01E8EB4A200E82730 /* AppStore */, - D06706571D51162400DED3E3 /* Hockeyapp */, + D09D8C191D4FAB1D0081DBEC /* Debug Hockeyapp */, + D09D8C1A1D4FAB1D0081DBEC /* Debug AppStore */, + C22069C01E8EB4A200E82730 /* Release Hockeyapp */, + D06706571D51162400DED3E3 /* Release AppStore */, ); defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; + defaultConfigurationName = "Debug AppStore"; }; D0B4186C1D7E03D5004562A4 /* Build configuration list for PBXNativeTarget "TelegramCoreMac" */ = { isa = XCConfigurationList; buildConfigurations = ( - D0B4186D1D7E03D5004562A4 /* Debug */, - D0B4186E1D7E03D5004562A4 /* Release */, - C22069C11E8EB4A200E82730 /* AppStore */, - D0B4186F1D7E03D5004562A4 /* Hockeyapp */, + D0B4186D1D7E03D5004562A4 /* Debug Hockeyapp */, + D0B4186E1D7E03D5004562A4 /* Debug AppStore */, + C22069C11E8EB4A200E82730 /* Release Hockeyapp */, + D0B4186F1D7E03D5004562A4 /* Release AppStore */, ); defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; + defaultConfigurationName = "Debug AppStore"; }; /* End XCConfigurationList section */ }; diff --git a/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist b/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist index f16687c82a..bbe7c497fe 100644 --- a/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/TelegramCore.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ TelegramCore.xcscheme orderHint - 2 + 3 TelegramCoreMac.xcscheme orderHint - 5 + 6 SuppressBuildableAutocreation diff --git a/TelegramCore/Account.swift b/TelegramCore/Account.swift index 301dfe78d3..1f7e7912ae 100644 --- a/TelegramCore/Account.swift +++ b/TelegramCore/Account.swift @@ -237,6 +237,9 @@ private var declaredEncodables: Void = { declareEncodable(CachedSecretChatData.self, f: { CachedSecretChatData(decoder: $0) }) declareEncodable(ManagedDeviceContactsMetaInfo.self, f: { ManagedDeviceContactsMetaInfo(decoder: $0) }) declareEncodable(ManagedDeviceContactEntryContents.self, f: { ManagedDeviceContactEntryContents(decoder: $0) }) + declareEncodable(TemporaryTwoStepPasswordToken.self, f: { TemporaryTwoStepPasswordToken(decoder: $0) }) + declareEncodable(AuthorSignatureMessageAttribute.self, f: { AuthorSignatureMessageAttribute(decoder: $0) }) + declareEncodable(TelegramMediaExpiredContent.self, f: { TelegramMediaExpiredContent(decoder: $0) }) return }() @@ -498,7 +501,10 @@ public class Account { self.pendingMessageManager = PendingMessageManager(network: network, postbox: postbox, stateManager: self.stateManager) self.network.loggedOut = { [weak self] in - self?._loggedOut.set(true) + if let strongSelf = self { + strongSelf._loggedOut.set(true) + strongSelf.callSessionManager.dropAll() + } } let networkStateSignal = combineLatest(self.stateManager.isUpdating, network.connectionStatus) diff --git a/TelegramCore/AccountStateManagementUtils.swift b/TelegramCore/AccountStateManagementUtils.swift index a20d4acac9..b4e61da274 100644 --- a/TelegramCore/AccountStateManagementUtils.swift +++ b/TelegramCore/AccountStateManagementUtils.swift @@ -778,13 +778,16 @@ private func finalStateWithUpdates(account: Account, state: AccountMutableState, var messageText = text var medias: [Media] = [] - let (mediaText, mediaValue) = textAndMediaFromApiMedia(media, peerId) + let (mediaText, mediaValue, expirationTimer) = textMediaAndExpirationTimerFromApiMedia(media, peerId) if let mediaText = mediaText { messageText = mediaText } if let mediaValue = mediaValue { medias.append(mediaValue) } + if let expirationTimer = expirationTimer { + attributes.append(AutoremoveTimeoutMessageAttribute(timeout: expirationTimer, countdownBeginTime: nil)) + } let message = StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: nil, timestamp: date, flags: [.Incoming], tags: [], globalTags: [], forwardInfo: nil, authorId: peerId, text: messageText, attributes: attributes, media: []) updatedState.addMessages([message], location: .UpperHistoryBlock) @@ -1603,7 +1606,7 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, modifier: Modif modifier.updateMessage(id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } var attributes = currentMessage.attributes loop: for j in 0 ..< attributes.count { diff --git a/TelegramCore/AccountViewTracker.swift b/TelegramCore/AccountViewTracker.swift index 37bffe8615..274ff13e8d 100644 --- a/TelegramCore/AccountViewTracker.swift +++ b/TelegramCore/AccountViewTracker.swift @@ -370,7 +370,7 @@ public final class AccountViewTracker { modifier.updateMessage(messageIds[i], update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } var attributes = currentMessage.attributes loop: for j in 0 ..< attributes.count { diff --git a/TelegramCore/Api.swift b/TelegramCore/Api.swift index 36e4a76c89..fc6a026630 100644 --- a/TelegramCore/Api.swift +++ b/TelegramCore/Api.swift @@ -198,9 +198,10 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1425052898] = { return Api.Update.parse_updatePhoneCall($0) } dict[281165899] = { return Api.Update.parse_updateLangPackTooLong($0) } dict[1442983757] = { return Api.Update.parse_updateLangPack($0) } + dict[1558266229] = { return Api.PopularContact.parse_popularContact($0) } dict[367766557] = { return Api.ChannelParticipant.parse_channelParticipant($0) } - dict[-471670279] = { return Api.ChannelParticipant.parse_channelParticipantCreator($0) } dict[-1557620115] = { return Api.ChannelParticipant.parse_channelParticipantSelf($0) } + dict[-471670279] = { return Api.ChannelParticipant.parse_channelParticipantCreator($0) } dict[-1473271656] = { return Api.ChannelParticipant.parse_channelParticipantAdmin($0) } dict[573315206] = { return Api.ChannelParticipant.parse_channelParticipantBanned($0) } dict[471043349] = { return Api.contacts.Blocked.parse_blocked($0) } @@ -255,6 +256,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[104314861] = { return Api.TopPeerCategory.parse_topPeerCategoryCorrespondents($0) } dict[-1122524854] = { return Api.TopPeerCategory.parse_topPeerCategoryGroups($0) } dict[371037736] = { return Api.TopPeerCategory.parse_topPeerCategoryChannels($0) } + dict[511092620] = { return Api.TopPeerCategory.parse_topPeerCategoryPhoneCalls($0) } dict[-1219778094] = { return Api.contacts.Contacts.parse_contactsNotModified($0) } dict[1871416498] = { return Api.contacts.Contacts.parse_contacts($0) } dict[-1798033689] = { return Api.ChannelMessagesFilter.parse_channelMessagesFilterEmpty($0) } @@ -265,12 +267,9 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[410618194] = { return Api.InputDocument.parse_inputDocument($0) } dict[2131196633] = { return Api.contacts.ResolvedPeer.parse_resolvedPeer($0) } dict[-1771768449] = { return Api.InputMedia.parse_inputMediaEmpty($0) } - dict[1661770481] = { return Api.InputMedia.parse_inputMediaUploadedPhoto($0) } dict[-373312269] = { return Api.InputMedia.parse_inputMediaPhoto($0) } dict[-104578748] = { return Api.InputMedia.parse_inputMediaGeoPoint($0) } dict[-1494984313] = { return Api.InputMedia.parse_inputMediaContact($0) } - dict[-797904407] = { return Api.InputMedia.parse_inputMediaUploadedDocument($0) } - dict[1356369070] = { return Api.InputMedia.parse_inputMediaUploadedThumbDocument($0) } dict[444068508] = { return Api.InputMedia.parse_inputMediaDocument($0) } dict[673687578] = { return Api.InputMedia.parse_inputMediaVenue($0) } dict[1212395773] = { return Api.InputMedia.parse_inputMediaGifExternal($0) } @@ -278,6 +277,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-437690244] = { return Api.InputMedia.parse_inputMediaDocumentExternal($0) } dict[-750828557] = { return Api.InputMedia.parse_inputMediaGame($0) } dict[-1844103547] = { return Api.InputMedia.parse_inputMediaInvoice($0) } + dict[792191537] = { return Api.InputMedia.parse_inputMediaUploadedPhoto($0) } + dict[-476700163] = { return Api.InputMedia.parse_inputMediaUploadedDocument($0) } dict[2134579434] = { return Api.InputPeer.parse_inputPeerEmpty($0) } dict[2107670217] = { return Api.InputPeer.parse_inputPeerSelf($0) } dict[396093539] = { return Api.InputPeer.parse_inputPeerChat($0) } @@ -346,6 +347,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1218642516] = { return Api.ReplyMarkup.parse_replyInlineMarkup($0) } dict[1493171408] = { return Api.HighScore.parse_highScore($0) } dict[-305282981] = { return Api.TopPeer.parse_topPeer($0) } + dict[2012136335] = { return Api.CdnFileHash.parse_cdnFileHash($0) } dict[986597452] = { return Api.contacts.Link.parse_link($0) } dict[1444661369] = { return Api.ContactBlocked.parse_contactBlocked($0) } dict[-2128698738] = { return Api.auth.CheckedPhone.parse_checkedPhone($0) } @@ -355,7 +357,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1908433218] = { return Api.Page.parse_pagePart($0) } dict[1433323434] = { return Api.Page.parse_pageFull($0) } dict[157948117] = { return Api.upload.File.parse_file($0) } - dict[352864346] = { return Api.upload.File.parse_fileCdnRedirect($0) } + dict[-363659686] = { return Api.upload.File.parse_fileCdnRedirect($0) } dict[182649427] = { return Api.MessageRange.parse_messageRange($0) } dict[946083368] = { return Api.messages.StickerSetInstallResult.parse_stickerSetInstallResultSuccess($0) } dict[904138920] = { return Api.messages.StickerSetInstallResult.parse_stickerSetInstallResultArchive($0) } @@ -390,15 +392,15 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1957577280] = { return Api.Updates.parse_updates($0) } dict[301019932] = { return Api.Updates.parse_updateShortSentMessage($0) } dict[1038967584] = { return Api.MessageMedia.parse_messageMediaEmpty($0) } - dict[1032643901] = { return Api.MessageMedia.parse_messageMediaPhoto($0) } dict[1457575028] = { return Api.MessageMedia.parse_messageMediaGeo($0) } dict[1585262393] = { return Api.MessageMedia.parse_messageMediaContact($0) } dict[-1618676578] = { return Api.MessageMedia.parse_messageMediaUnsupported($0) } - dict[-203411800] = { return Api.MessageMedia.parse_messageMediaDocument($0) } dict[-1557277184] = { return Api.MessageMedia.parse_messageMediaWebPage($0) } dict[2031269663] = { return Api.MessageMedia.parse_messageMediaVenue($0) } dict[-38694904] = { return Api.MessageMedia.parse_messageMediaGame($0) } dict[-2074799289] = { return Api.MessageMedia.parse_messageMediaInvoice($0) } + dict[-1256047857] = { return Api.MessageMedia.parse_messageMediaPhoto($0) } + dict[2084836563] = { return Api.MessageMedia.parse_messageMediaDocument($0) } dict[-842892769] = { return Api.PaymentSavedCredentials.parse_paymentSavedCredentialsCard($0) } dict[1450380236] = { return Api.Null.parse_null($0) } dict[1923290508] = { return Api.auth.CodeType.parse_codeTypeSms($0) } @@ -427,8 +429,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[537022650] = { return Api.User.parse_userEmpty($0) } dict[773059779] = { return Api.User.parse_user($0) } dict[-2082087340] = { return Api.Message.parse_messageEmpty($0) } - dict[-1063525281] = { return Api.Message.parse_message($0) } dict[-1642487306] = { return Api.Message.parse_messageService($0) } + dict[-1864508399] = { return Api.Message.parse_message($0) } dict[186120336] = { return Api.messages.RecentStickers.parse_recentStickersNotModified($0) } dict[1558317424] = { return Api.messages.RecentStickers.parse_recentStickers($0) } dict[342061462] = { return Api.InputFileLocation.parse_inputFileLocation($0) } @@ -456,7 +458,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1910892683] = { return Api.NearestDc.parse_nearestDc($0) } dict[-1916114267] = { return Api.photos.Photos.parse_photos($0) } dict[352657236] = { return Api.photos.Photos.parse_photosSlice($0) } - dict[-1387117803] = { return Api.contacts.ImportedContacts.parse_importedContacts($0) } + dict[2010127419] = { return Api.contacts.ImportedContacts.parse_importedContacts($0) } dict[-1678949555] = { return Api.InputWebDocument.parse_inputWebDocument($0) } dict[-326966976] = { return Api.phone.PhoneCall.parse_phoneCall($0) } dict[995769920] = { return Api.ChannelAdminLogEvent.parse_channelAdminLogEvent($0) } @@ -466,7 +468,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1816636575] = { return Api.LangPackString.parse_langPackStringPluralized($0) } dict[695856818] = { return Api.LangPackString.parse_langPackStringDeleted($0) } dict[-1036396922] = { return Api.InputWebFileLocation.parse_inputWebFileLocation($0) } - dict[-947462709] = { return Api.MessageFwdHeader.parse_messageFwdHeader($0) } + dict[-85986132] = { return Api.MessageFwdHeader.parse_messageFwdHeader($0) } dict[398898678] = { return Api.help.Support.parse_support($0) } dict[1474492012] = { return Api.MessagesFilter.parse_inputMessagesFilterEmpty($0) } dict[-1777752804] = { return Api.MessagesFilter.parse_inputMessagesFilterPhotos($0) } @@ -715,6 +717,8 @@ public struct Api { return _1.serialize(buffer, boxed) case let _1 as Api.Update: return _1.serialize(buffer, boxed) + case let _1 as Api.PopularContact: + return _1.serialize(buffer, boxed) case let _1 as Api.ChannelParticipant: return _1.serialize(buffer, boxed) case let _1 as Api.contacts.Blocked: @@ -827,6 +831,8 @@ public struct Api { return _1.serialize(buffer, boxed) case let _1 as Api.TopPeer: return _1.serialize(buffer, boxed) + case let _1 as Api.CdnFileHash: + return _1.serialize(buffer, boxed) case let _1 as Api.contacts.Link: return _1.serialize(buffer, boxed) case let _1 as Api.ContactBlocked: @@ -7049,10 +7055,51 @@ public struct Api { } } + public enum PopularContact: CustomStringConvertible { + case popularContact(clientId: Int64, importers: Int32) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .popularContact(let clientId, let importers): + if boxed { + buffer.appendInt32(1558266229) + } + serializeInt64(clientId, buffer: buffer, boxed: false) + serializeInt32(importers, buffer: buffer, boxed: false) + break + } + return true + } + + fileprivate static func parse_popularContact(_ reader: BufferReader) -> PopularContact? { + var _1: Int64? + _1 = reader.readInt64() + var _2: Int32? + _2 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.PopularContact.popularContact(clientId: _1!, importers: _2!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .popularContact(let clientId, let importers): + return "(popularContact clientId: \(clientId), importers: \(importers))" + } + } + } + } + public enum ChannelParticipant: CustomStringConvertible { case channelParticipant(userId: Int32, date: Int32) - case channelParticipantCreator(userId: Int32) case channelParticipantSelf(userId: Int32, inviterId: Int32, date: Int32) + case channelParticipantCreator(userId: Int32) case channelParticipantAdmin(flags: Int32, userId: Int32, inviterId: Int32, promotedBy: Int32, date: Int32, adminRights: Api.ChannelAdminRights) case channelParticipantBanned(flags: Int32, userId: Int32, kickedBy: Int32, date: Int32, bannedRights: Api.ChannelBannedRights) @@ -7065,12 +7112,6 @@ public struct Api { serializeInt32(userId, buffer: buffer, boxed: false) serializeInt32(date, buffer: buffer, boxed: false) break - case .channelParticipantCreator(let userId): - if boxed { - buffer.appendInt32(-471670279) - } - serializeInt32(userId, buffer: buffer, boxed: false) - break case .channelParticipantSelf(let userId, let inviterId, let date): if boxed { buffer.appendInt32(-1557620115) @@ -7079,6 +7120,12 @@ public struct Api { serializeInt32(inviterId, buffer: buffer, boxed: false) serializeInt32(date, buffer: buffer, boxed: false) break + case .channelParticipantCreator(let userId): + if boxed { + buffer.appendInt32(-471670279) + } + serializeInt32(userId, buffer: buffer, boxed: false) + break case .channelParticipantAdmin(let flags, let userId, let inviterId, let promotedBy, let date, let adminRights): if boxed { buffer.appendInt32(-1473271656) @@ -7118,17 +7165,6 @@ public struct Api { return nil } } - fileprivate static func parse_channelParticipantCreator(_ reader: BufferReader) -> ChannelParticipant? { - var _1: Int32? - _1 = reader.readInt32() - let _c1 = _1 != nil - if _c1 { - return Api.ChannelParticipant.channelParticipantCreator(userId: _1!) - } - else { - return nil - } - } fileprivate static func parse_channelParticipantSelf(_ reader: BufferReader) -> ChannelParticipant? { var _1: Int32? _1 = reader.readInt32() @@ -7146,6 +7182,17 @@ public struct Api { return nil } } + fileprivate static func parse_channelParticipantCreator(_ reader: BufferReader) -> ChannelParticipant? { + var _1: Int32? + _1 = reader.readInt32() + let _c1 = _1 != nil + if _c1 { + return Api.ChannelParticipant.channelParticipantCreator(userId: _1!) + } + else { + return nil + } + } fileprivate static func parse_channelParticipantAdmin(_ reader: BufferReader) -> ChannelParticipant? { var _1: Int32? _1 = reader.readInt32() @@ -7205,10 +7252,10 @@ public struct Api { switch self { case .channelParticipant(let userId, let date): return "(channelParticipant userId: \(userId), date: \(date))" - case .channelParticipantCreator(let userId): - return "(channelParticipantCreator userId: \(userId))" case .channelParticipantSelf(let userId, let inviterId, let date): return "(channelParticipantSelf userId: \(userId), inviterId: \(inviterId), date: \(date))" + case .channelParticipantCreator(let userId): + return "(channelParticipantCreator userId: \(userId))" case .channelParticipantAdmin(let flags, let userId, let inviterId, let promotedBy, let date, let adminRights): return "(channelParticipantAdmin flags: \(flags), userId: \(userId), inviterId: \(inviterId), promotedBy: \(promotedBy), date: \(date), adminRights: \(adminRights))" case .channelParticipantBanned(let flags, let userId, let kickedBy, let date, let bannedRights): @@ -8558,6 +8605,7 @@ public struct Api { case topPeerCategoryCorrespondents case topPeerCategoryGroups case topPeerCategoryChannels + case topPeerCategoryPhoneCalls public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { switch self { @@ -8590,6 +8638,12 @@ public struct Api { buffer.appendInt32(371037736) } + break + case .topPeerCategoryPhoneCalls: + if boxed { + buffer.appendInt32(511092620) + } + break } return true @@ -8610,6 +8664,9 @@ public struct Api { fileprivate static func parse_topPeerCategoryChannels(_ reader: BufferReader) -> TopPeerCategory? { return Api.TopPeerCategory.topPeerCategoryChannels } + fileprivate static func parse_topPeerCategoryPhoneCalls(_ reader: BufferReader) -> TopPeerCategory? { + return Api.TopPeerCategory.topPeerCategoryPhoneCalls + } public var description: String { get { @@ -8624,6 +8681,8 @@ public struct Api { return "(topPeerCategoryGroups)" case .topPeerCategoryChannels: return "(topPeerCategoryChannels)" + case .topPeerCategoryPhoneCalls: + return "(topPeerCategoryPhoneCalls)" } } } @@ -8743,12 +8802,9 @@ public struct Api { public enum InputMedia: CustomStringConvertible { case inputMediaEmpty - case inputMediaUploadedPhoto(flags: Int32, file: Api.InputFile, caption: String, stickers: [Api.InputDocument]?) case inputMediaPhoto(id: Api.InputPhoto, caption: String) case inputMediaGeoPoint(geoPoint: Api.InputGeoPoint) case inputMediaContact(phoneNumber: String, firstName: String, lastName: String) - case inputMediaUploadedDocument(flags: Int32, file: Api.InputFile, mimeType: String, attributes: [Api.DocumentAttribute], caption: String, stickers: [Api.InputDocument]?) - case inputMediaUploadedThumbDocument(flags: Int32, file: Api.InputFile, thumb: Api.InputFile, mimeType: String, attributes: [Api.DocumentAttribute], caption: String, stickers: [Api.InputDocument]?) case inputMediaDocument(id: Api.InputDocument, caption: String) case inputMediaVenue(geoPoint: Api.InputGeoPoint, title: String, address: String, provider: String, venueId: String) case inputMediaGifExternal(url: String, q: String) @@ -8756,6 +8812,8 @@ public struct Api { case inputMediaDocumentExternal(url: String, caption: String) case inputMediaGame(id: Api.InputGame) case inputMediaInvoice(flags: Int32, title: String, description: String, photo: Api.InputWebDocument?, invoice: Api.Invoice, payload: Buffer, provider: String, startParam: String) + case inputMediaUploadedPhoto(flags: Int32, file: Api.InputFile, caption: String, stickers: [Api.InputDocument]?, ttlSeconds: Int32?) + case inputMediaUploadedDocument(flags: Int32, file: Api.InputFile, thumb: Api.InputFile?, mimeType: String, attributes: [Api.DocumentAttribute], caption: String, stickers: [Api.InputDocument]?, ttlSeconds: Int32?) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { switch self { @@ -8764,19 +8822,6 @@ public struct Api { buffer.appendInt32(-1771768449) } - break - case .inputMediaUploadedPhoto(let flags, let file, let caption, let stickers): - if boxed { - buffer.appendInt32(1661770481) - } - serializeInt32(flags, buffer: buffer, boxed: false) - file.serialize(buffer, true) - serializeString(caption, buffer: buffer, boxed: false) - if Int(flags) & Int(1 << 0) != 0 {buffer.appendInt32(481674261) - buffer.appendInt32(Int32(stickers!.count)) - for item in stickers! { - item.serialize(buffer, true) - }} break case .inputMediaPhoto(let id, let caption): if boxed { @@ -8799,45 +8844,6 @@ public struct Api { serializeString(firstName, buffer: buffer, boxed: false) serializeString(lastName, buffer: buffer, boxed: false) break - case .inputMediaUploadedDocument(let flags, let file, let mimeType, let attributes, let caption, let stickers): - if boxed { - buffer.appendInt32(-797904407) - } - serializeInt32(flags, buffer: buffer, boxed: false) - file.serialize(buffer, true) - serializeString(mimeType, buffer: buffer, boxed: false) - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(attributes.count)) - for item in attributes { - item.serialize(buffer, true) - } - serializeString(caption, buffer: buffer, boxed: false) - if Int(flags) & Int(1 << 0) != 0 {buffer.appendInt32(481674261) - buffer.appendInt32(Int32(stickers!.count)) - for item in stickers! { - item.serialize(buffer, true) - }} - break - case .inputMediaUploadedThumbDocument(let flags, let file, let thumb, let mimeType, let attributes, let caption, let stickers): - if boxed { - buffer.appendInt32(1356369070) - } - serializeInt32(flags, buffer: buffer, boxed: false) - file.serialize(buffer, true) - thumb.serialize(buffer, true) - serializeString(mimeType, buffer: buffer, boxed: false) - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(attributes.count)) - for item in attributes { - item.serialize(buffer, true) - } - serializeString(caption, buffer: buffer, boxed: false) - if Int(flags) & Int(1 << 0) != 0 {buffer.appendInt32(481674261) - buffer.appendInt32(Int32(stickers!.count)) - for item in stickers! { - item.serialize(buffer, true) - }} - break case .inputMediaDocument(let id, let caption): if boxed { buffer.appendInt32(444068508) @@ -8895,6 +8901,41 @@ public struct Api { serializeString(provider, buffer: buffer, boxed: false) serializeString(startParam, buffer: buffer, boxed: false) break + case .inputMediaUploadedPhoto(let flags, let file, let caption, let stickers, let ttlSeconds): + if boxed { + buffer.appendInt32(792191537) + } + serializeInt32(flags, buffer: buffer, boxed: false) + file.serialize(buffer, true) + serializeString(caption, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {buffer.appendInt32(481674261) + buffer.appendInt32(Int32(stickers!.count)) + for item in stickers! { + item.serialize(buffer, true) + }} + if Int(flags) & Int(1 << 1) != 0 {serializeInt32(ttlSeconds!, buffer: buffer, boxed: false)} + break + case .inputMediaUploadedDocument(let flags, let file, let thumb, let mimeType, let attributes, let caption, let stickers, let ttlSeconds): + if boxed { + buffer.appendInt32(-476700163) + } + serializeInt32(flags, buffer: buffer, boxed: false) + file.serialize(buffer, true) + if Int(flags) & Int(1 << 2) != 0 {thumb!.serialize(buffer, true)} + serializeString(mimeType, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(attributes.count)) + for item in attributes { + item.serialize(buffer, true) + } + serializeString(caption, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {buffer.appendInt32(481674261) + buffer.appendInt32(Int32(stickers!.count)) + for item in stickers! { + item.serialize(buffer, true) + }} + if Int(flags) & Int(1 << 1) != 0 {serializeInt32(ttlSeconds!, buffer: buffer, boxed: false)} + break } return true } @@ -8902,30 +8943,6 @@ public struct Api { fileprivate static func parse_inputMediaEmpty(_ reader: BufferReader) -> InputMedia? { return Api.InputMedia.inputMediaEmpty } - fileprivate static func parse_inputMediaUploadedPhoto(_ reader: BufferReader) -> InputMedia? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Api.InputFile? - if let signature = reader.readInt32() { - _2 = Api.parse(reader, signature: signature) as? Api.InputFile - } - var _3: String? - _3 = parseString(reader) - var _4: [Api.InputDocument]? - if Int(_1!) & Int(1 << 0) != 0 {if let _ = reader.readInt32() { - _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.InputDocument.self) - } } - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = _3 != nil - let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil - if _c1 && _c2 && _c3 && _c4 { - return Api.InputMedia.inputMediaUploadedPhoto(flags: _1!, file: _2!, caption: _3!, stickers: _4) - } - else { - return nil - } - } fileprivate static func parse_inputMediaPhoto(_ reader: BufferReader) -> InputMedia? { var _1: Api.InputPhoto? if let signature = reader.readInt32() { @@ -8972,75 +8989,6 @@ public struct Api { return nil } } - fileprivate static func parse_inputMediaUploadedDocument(_ reader: BufferReader) -> InputMedia? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Api.InputFile? - if let signature = reader.readInt32() { - _2 = Api.parse(reader, signature: signature) as? Api.InputFile - } - var _3: String? - _3 = parseString(reader) - var _4: [Api.DocumentAttribute]? - if let _ = reader.readInt32() { - _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.DocumentAttribute.self) - } - var _5: String? - _5 = parseString(reader) - var _6: [Api.InputDocument]? - if Int(_1!) & Int(1 << 0) != 0 {if let _ = reader.readInt32() { - _6 = Api.parseVector(reader, elementSignature: 0, elementType: Api.InputDocument.self) - } } - 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 - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 { - return Api.InputMedia.inputMediaUploadedDocument(flags: _1!, file: _2!, mimeType: _3!, attributes: _4!, caption: _5!, stickers: _6) - } - else { - return nil - } - } - fileprivate static func parse_inputMediaUploadedThumbDocument(_ reader: BufferReader) -> InputMedia? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Api.InputFile? - if let signature = reader.readInt32() { - _2 = Api.parse(reader, signature: signature) as? Api.InputFile - } - var _3: Api.InputFile? - if let signature = reader.readInt32() { - _3 = Api.parse(reader, signature: signature) as? Api.InputFile - } - var _4: String? - _4 = parseString(reader) - var _5: [Api.DocumentAttribute]? - if let _ = reader.readInt32() { - _5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.DocumentAttribute.self) - } - var _6: String? - _6 = parseString(reader) - var _7: [Api.InputDocument]? - if Int(_1!) & Int(1 << 0) != 0 {if let _ = reader.readInt32() { - _7 = Api.parseVector(reader, elementSignature: 0, elementType: Api.InputDocument.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 = (Int(_1!) & Int(1 << 0) == 0) || _7 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 { - return Api.InputMedia.inputMediaUploadedThumbDocument(flags: _1!, file: _2!, thumb: _3!, mimeType: _4!, attributes: _5!, caption: _6!, stickers: _7) - } - else { - return nil - } - } fileprivate static func parse_inputMediaDocument(_ reader: BufferReader) -> InputMedia? { var _1: Api.InputDocument? if let signature = reader.readInt32() { @@ -9173,24 +9121,85 @@ public struct Api { return nil } } + fileprivate static func parse_inputMediaUploadedPhoto(_ reader: BufferReader) -> InputMedia? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.InputFile? + if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.InputFile + } + var _3: String? + _3 = parseString(reader) + var _4: [Api.InputDocument]? + if Int(_1!) & Int(1 << 0) != 0 {if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.InputDocument.self) + } } + var _5: Int32? + if Int(_1!) & Int(1 << 1) != 0 {_5 = reader.readInt32() } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil + let _c5 = (Int(_1!) & Int(1 << 1) == 0) || _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return Api.InputMedia.inputMediaUploadedPhoto(flags: _1!, file: _2!, caption: _3!, stickers: _4, ttlSeconds: _5) + } + else { + return nil + } + } + fileprivate static func parse_inputMediaUploadedDocument(_ reader: BufferReader) -> InputMedia? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.InputFile? + if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.InputFile + } + var _3: Api.InputFile? + if Int(_1!) & Int(1 << 2) != 0 {if let signature = reader.readInt32() { + _3 = Api.parse(reader, signature: signature) as? Api.InputFile + } } + var _4: String? + _4 = parseString(reader) + var _5: [Api.DocumentAttribute]? + if let _ = reader.readInt32() { + _5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.DocumentAttribute.self) + } + var _6: String? + _6 = parseString(reader) + var _7: [Api.InputDocument]? + if Int(_1!) & Int(1 << 0) != 0 {if let _ = reader.readInt32() { + _7 = Api.parseVector(reader, elementSignature: 0, elementType: Api.InputDocument.self) + } } + var _8: Int32? + if Int(_1!) & Int(1 << 1) != 0 {_8 = reader.readInt32() } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = (Int(_1!) & Int(1 << 2) == 0) || _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + let _c6 = _6 != nil + let _c7 = (Int(_1!) & Int(1 << 0) == 0) || _7 != nil + let _c8 = (Int(_1!) & Int(1 << 1) == 0) || _8 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 { + return Api.InputMedia.inputMediaUploadedDocument(flags: _1!, file: _2!, thumb: _3, mimeType: _4!, attributes: _5!, caption: _6!, stickers: _7, ttlSeconds: _8) + } + else { + return nil + } + } public var description: String { get { switch self { case .inputMediaEmpty: return "(inputMediaEmpty)" - case .inputMediaUploadedPhoto(let flags, let file, let caption, let stickers): - return "(inputMediaUploadedPhoto flags: \(flags), file: \(file), caption: \(caption), stickers: \(stickers))" case .inputMediaPhoto(let id, let caption): return "(inputMediaPhoto id: \(id), caption: \(caption))" case .inputMediaGeoPoint(let geoPoint): return "(inputMediaGeoPoint geoPoint: \(geoPoint))" case .inputMediaContact(let phoneNumber, let firstName, let lastName): return "(inputMediaContact phoneNumber: \(phoneNumber), firstName: \(firstName), lastName: \(lastName))" - case .inputMediaUploadedDocument(let flags, let file, let mimeType, let attributes, let caption, let stickers): - return "(inputMediaUploadedDocument flags: \(flags), file: \(file), mimeType: \(mimeType), attributes: \(attributes), caption: \(caption), stickers: \(stickers))" - case .inputMediaUploadedThumbDocument(let flags, let file, let thumb, let mimeType, let attributes, let caption, let stickers): - return "(inputMediaUploadedThumbDocument flags: \(flags), file: \(file), thumb: \(thumb), mimeType: \(mimeType), attributes: \(attributes), caption: \(caption), stickers: \(stickers))" case .inputMediaDocument(let id, let caption): return "(inputMediaDocument id: \(id), caption: \(caption))" case .inputMediaVenue(let geoPoint, let title, let address, let provider, let venueId): @@ -9205,6 +9214,10 @@ public struct Api { return "(inputMediaGame id: \(id))" case .inputMediaInvoice(let flags, let title, let description, let photo, let invoice, let payload, let provider, let startParam): return "(inputMediaInvoice flags: \(flags), title: \(title), description: \(description), photo: \(photo), invoice: \(invoice), payload: \(payload), provider: \(provider), startParam: \(startParam))" + case .inputMediaUploadedPhoto(let flags, let file, let caption, let stickers, let ttlSeconds): + return "(inputMediaUploadedPhoto flags: \(flags), file: \(file), caption: \(caption), stickers: \(stickers), ttlSeconds: \(ttlSeconds))" + case .inputMediaUploadedDocument(let flags, let file, let thumb, let mimeType, let attributes, let caption, let stickers, let ttlSeconds): + return "(inputMediaUploadedDocument flags: \(flags), file: \(file), thumb: \(thumb), mimeType: \(mimeType), attributes: \(attributes), caption: \(caption), stickers: \(stickers), ttlSeconds: \(ttlSeconds))" } } } @@ -10694,6 +10707,51 @@ public struct Api { } } + public enum CdnFileHash: CustomStringConvertible { + case cdnFileHash(offset: Int32, limit: Int32, hash: Buffer) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { + switch self { + case .cdnFileHash(let offset, let limit, let hash): + if boxed { + buffer.appendInt32(2012136335) + } + serializeInt32(offset, buffer: buffer, boxed: false) + serializeInt32(limit, buffer: buffer, boxed: false) + serializeBytes(hash, buffer: buffer, boxed: false) + break + } + return true + } + + fileprivate static func parse_cdnFileHash(_ reader: BufferReader) -> CdnFileHash? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: Buffer? + _3 = parseBytes(reader) + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + if _c1 && _c2 && _c3 { + return Api.CdnFileHash.cdnFileHash(offset: _1!, limit: _2!, hash: _3!) + } + else { + return nil + } + } + + public var description: String { + get { + switch self { + case .cdnFileHash(let offset, let limit, let hash): + return "(cdnFileHash offset: \(offset), limit: \(limit), hash: \(hash))" + } + } + } + } + public enum ContactBlocked: CustomStringConvertible { case contactBlocked(userId: Int32, date: Int32) @@ -12091,15 +12149,15 @@ public struct Api { public enum MessageMedia: CustomStringConvertible { case messageMediaEmpty - case messageMediaPhoto(photo: Api.Photo, caption: String) case messageMediaGeo(geo: Api.GeoPoint) case messageMediaContact(phoneNumber: String, firstName: String, lastName: String, userId: Int32) case messageMediaUnsupported - case messageMediaDocument(document: Api.Document, caption: String) case messageMediaWebPage(webpage: Api.WebPage) case messageMediaVenue(geo: Api.GeoPoint, title: String, address: String, provider: String, venueId: String) case messageMediaGame(game: Api.Game) case messageMediaInvoice(flags: Int32, title: String, description: String, photo: Api.WebDocument?, receiptMsgId: Int32?, currency: String, totalAmount: Int64, startParam: String) + case messageMediaPhoto(flags: Int32, photo: Api.Photo?, caption: String?, ttlSeconds: Int32?) + case messageMediaDocument(flags: Int32, document: Api.Document?, caption: String?, ttlSeconds: Int32?) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { switch self { @@ -12108,13 +12166,6 @@ public struct Api { 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 { @@ -12136,13 +12187,6 @@ public struct Api { 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 { @@ -12179,6 +12223,24 @@ public struct Api { serializeInt64(totalAmount, buffer: buffer, boxed: false) serializeString(startParam, buffer: buffer, boxed: false) break + case .messageMediaPhoto(let flags, let photo, let caption, let ttlSeconds): + if boxed { + buffer.appendInt32(-1256047857) + } + serializeInt32(flags, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {photo!.serialize(buffer, true)} + if Int(flags) & Int(1 << 1) != 0 {serializeString(caption!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 2) != 0 {serializeInt32(ttlSeconds!, buffer: buffer, boxed: false)} + break + case .messageMediaDocument(let flags, let document, let caption, let ttlSeconds): + if boxed { + buffer.appendInt32(2084836563) + } + serializeInt32(flags, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {document!.serialize(buffer, true)} + if Int(flags) & Int(1 << 1) != 0 {serializeString(caption!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 2) != 0 {serializeInt32(ttlSeconds!, buffer: buffer, boxed: false)} + break } return true } @@ -12186,22 +12248,6 @@ public struct Api { fileprivate static func parse_messageMediaEmpty(_ reader: BufferReader) -> MessageMedia? { return Api.MessageMedia.messageMediaEmpty } - fileprivate static func parse_messageMediaPhoto(_ reader: BufferReader) -> MessageMedia? { - var _1: Api.Photo? - if let signature = reader.readInt32() { - _1 = Api.parse(reader, signature: signature) as? Api.Photo - } - var _2: String? - _2 = parseString(reader) - let _c1 = _1 != nil - let _c2 = _2 != nil - if _c1 && _c2 { - return Api.MessageMedia.messageMediaPhoto(photo: _1!, caption: _2!) - } - else { - return nil - } - } fileprivate static func parse_messageMediaGeo(_ reader: BufferReader) -> MessageMedia? { var _1: Api.GeoPoint? if let signature = reader.readInt32() { @@ -12238,22 +12284,6 @@ public struct Api { fileprivate static func parse_messageMediaUnsupported(_ reader: BufferReader) -> MessageMedia? { return Api.MessageMedia.messageMediaUnsupported } - fileprivate static func parse_messageMediaDocument(_ reader: BufferReader) -> MessageMedia? { - var _1: Api.Document? - if let signature = reader.readInt32() { - _1 = Api.parse(reader, signature: signature) as? Api.Document - } - var _2: String? - _2 = parseString(reader) - let _c1 = _1 != nil - let _c2 = _2 != nil - if _c1 && _c2 { - return Api.MessageMedia.messageMediaDocument(document: _1!, caption: _2!) - } - else { - return nil - } - } fileprivate static func parse_messageMediaWebPage(_ reader: BufferReader) -> MessageMedia? { var _1: Api.WebPage? if let signature = reader.readInt32() { @@ -12339,22 +12369,62 @@ public struct Api { return nil } } + fileprivate static func parse_messageMediaPhoto(_ reader: BufferReader) -> MessageMedia? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.Photo? + if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.Photo + } } + var _3: String? + if Int(_1!) & Int(1 << 1) != 0 {_3 = parseString(reader) } + var _4: Int32? + if Int(_1!) & Int(1 << 2) != 0 {_4 = reader.readInt32() } + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil + let _c3 = (Int(_1!) & Int(1 << 1) == 0) || _3 != nil + let _c4 = (Int(_1!) & Int(1 << 2) == 0) || _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.MessageMedia.messageMediaPhoto(flags: _1!, photo: _2, caption: _3, ttlSeconds: _4) + } + else { + return nil + } + } + fileprivate static func parse_messageMediaDocument(_ reader: BufferReader) -> MessageMedia? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.Document? + if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.Document + } } + var _3: String? + if Int(_1!) & Int(1 << 1) != 0 {_3 = parseString(reader) } + var _4: Int32? + if Int(_1!) & Int(1 << 2) != 0 {_4 = reader.readInt32() } + let _c1 = _1 != nil + let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil + let _c3 = (Int(_1!) & Int(1 << 1) == 0) || _3 != nil + let _c4 = (Int(_1!) & Int(1 << 2) == 0) || _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.MessageMedia.messageMediaDocument(flags: _1!, document: _2, caption: _3, ttlSeconds: _4) + } + 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))" case .messageMediaVenue(let geo, let title, let address, let provider, let venueId): @@ -12363,6 +12433,10 @@ public struct Api { return "(messageMediaGame game: \(game))" case .messageMediaInvoice(let flags, let title, let description, let photo, let receiptMsgId, let currency, let totalAmount, let startParam): return "(messageMediaInvoice flags: \(flags), title: \(title), description: \(description), photo: \(photo), receiptMsgId: \(receiptMsgId), currency: \(currency), totalAmount: \(totalAmount), startParam: \(startParam))" + case .messageMediaPhoto(let flags, let photo, let caption, let ttlSeconds): + return "(messageMediaPhoto flags: \(flags), photo: \(photo), caption: \(caption), ttlSeconds: \(ttlSeconds))" + case .messageMediaDocument(let flags, let document, let caption, let ttlSeconds): + return "(messageMediaDocument flags: \(flags), document: \(document), caption: \(caption), ttlSeconds: \(ttlSeconds))" } } } @@ -13008,8 +13082,8 @@ public struct Api { public enum Message: CustomStringConvertible { case messageEmpty(id: Int32) - case message(flags: Int32, id: Int32, fromId: Int32?, toId: Api.Peer, fwdFrom: Api.MessageFwdHeader?, viaBotId: Int32?, replyToMsgId: Int32?, date: Int32, message: String, media: Api.MessageMedia?, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?, views: Int32?, editDate: Int32?) case messageService(flags: Int32, id: Int32, fromId: Int32?, toId: Api.Peer, replyToMsgId: Int32?, date: Int32, action: Api.MessageAction) + case message(flags: Int32, id: Int32, fromId: Int32?, toId: Api.Peer, fwdFrom: Api.MessageFwdHeader?, viaBotId: Int32?, replyToMsgId: Int32?, date: Int32, message: String, media: Api.MessageMedia?, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?, views: Int32?, editDate: Int32?, postAuthor: String?) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { switch self { @@ -13019,9 +13093,21 @@ public struct Api { } serializeInt32(id, buffer: buffer, boxed: false) break - case .message(let flags, let id, let fromId, let toId, let fwdFrom, let viaBotId, let replyToMsgId, let date, let message, let media, let replyMarkup, let entities, let views, let editDate): + case .messageService(let flags, let id, let fromId, let toId, let replyToMsgId, let date, let action): if boxed { - buffer.appendInt32(-1063525281) + buffer.appendInt32(-1642487306) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(id, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 8) != 0 {serializeInt32(fromId!, buffer: buffer, boxed: false)} + toId.serialize(buffer, true) + if Int(flags) & Int(1 << 3) != 0 {serializeInt32(replyToMsgId!, buffer: buffer, boxed: false)} + serializeInt32(date, buffer: buffer, boxed: false) + action.serialize(buffer, true) + break + case .message(let flags, let id, let fromId, let toId, let fwdFrom, let viaBotId, let replyToMsgId, let date, let message, let media, let replyMarkup, let entities, let views, let editDate, let postAuthor): + if boxed { + buffer.appendInt32(-1864508399) } serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(id, buffer: buffer, boxed: false) @@ -13041,18 +13127,7 @@ public struct Api { }} if Int(flags) & Int(1 << 10) != 0 {serializeInt32(views!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 15) != 0 {serializeInt32(editDate!, buffer: buffer, boxed: false)} - break - case .messageService(let flags, let id, let fromId, let toId, let replyToMsgId, let date, let action): - if boxed { - buffer.appendInt32(-1642487306) - } - serializeInt32(flags, buffer: buffer, boxed: false) - serializeInt32(id, buffer: buffer, boxed: false) - if Int(flags) & Int(1 << 8) != 0 {serializeInt32(fromId!, buffer: buffer, boxed: false)} - toId.serialize(buffer, true) - if Int(flags) & Int(1 << 3) != 0 {serializeInt32(replyToMsgId!, buffer: buffer, boxed: false)} - serializeInt32(date, buffer: buffer, boxed: false) - action.serialize(buffer, true) + if Int(flags) & Int(1 << 16) != 0 {serializeString(postAuthor!, buffer: buffer, boxed: false)} break } return true @@ -13069,6 +13144,39 @@ public struct Api { return nil } } + fileprivate static func parse_messageService(_ reader: BufferReader) -> Message? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: Int32? + if Int(_1!) & Int(1 << 8) != 0 {_3 = reader.readInt32() } + var _4: Api.Peer? + if let signature = reader.readInt32() { + _4 = Api.parse(reader, signature: signature) as? Api.Peer + } + var _5: Int32? + if Int(_1!) & Int(1 << 3) != 0 {_5 = reader.readInt32() } + var _6: Int32? + _6 = reader.readInt32() + var _7: Api.MessageAction? + if let signature = reader.readInt32() { + _7 = Api.parse(reader, signature: signature) as? Api.MessageAction + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = (Int(_1!) & Int(1 << 8) == 0) || _3 != nil + let _c4 = _4 != nil + let _c5 = (Int(_1!) & Int(1 << 3) == 0) || _5 != nil + let _c6 = _6 != nil + let _c7 = _7 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 { + return Api.Message.messageService(flags: _1!, id: _2!, fromId: _3, toId: _4!, replyToMsgId: _5, date: _6!, action: _7!) + } + else { + return nil + } + } fileprivate static func parse_message(_ reader: BufferReader) -> Message? { var _1: Int32? _1 = reader.readInt32() @@ -13108,6 +13216,8 @@ public struct Api { if Int(_1!) & Int(1 << 10) != 0 {_13 = reader.readInt32() } var _14: Int32? if Int(_1!) & Int(1 << 15) != 0 {_14 = reader.readInt32() } + var _15: String? + if Int(_1!) & Int(1 << 16) != 0 {_15 = parseString(reader) } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = (Int(_1!) & Int(1 << 8) == 0) || _3 != nil @@ -13122,41 +13232,9 @@ public struct Api { let _c12 = (Int(_1!) & Int(1 << 7) == 0) || _12 != nil let _c13 = (Int(_1!) & Int(1 << 10) == 0) || _13 != nil let _c14 = (Int(_1!) & Int(1 << 15) == 0) || _14 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 { - return Api.Message.message(flags: _1!, id: _2!, fromId: _3, toId: _4!, fwdFrom: _5, viaBotId: _6, replyToMsgId: _7, date: _8!, message: _9!, media: _10, replyMarkup: _11, entities: _12, views: _13, editDate: _14) - } - else { - return nil - } - } - fileprivate static func parse_messageService(_ reader: BufferReader) -> Message? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Int32? - _2 = reader.readInt32() - var _3: Int32? - if Int(_1!) & Int(1 << 8) != 0 {_3 = reader.readInt32() } - var _4: Api.Peer? - if let signature = reader.readInt32() { - _4 = Api.parse(reader, signature: signature) as? Api.Peer - } - var _5: Int32? - if Int(_1!) & Int(1 << 3) != 0 {_5 = reader.readInt32() } - var _6: Int32? - _6 = reader.readInt32() - var _7: Api.MessageAction? - if let signature = reader.readInt32() { - _7 = Api.parse(reader, signature: signature) as? Api.MessageAction - } - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = (Int(_1!) & Int(1 << 8) == 0) || _3 != nil - let _c4 = _4 != nil - let _c5 = (Int(_1!) & Int(1 << 3) == 0) || _5 != nil - let _c6 = _6 != nil - let _c7 = _7 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 { - return Api.Message.messageService(flags: _1!, id: _2!, fromId: _3, toId: _4!, replyToMsgId: _5, date: _6!, action: _7!) + let _c15 = (Int(_1!) & Int(1 << 16) == 0) || _15 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 { + return Api.Message.message(flags: _1!, id: _2!, fromId: _3, toId: _4!, fwdFrom: _5, viaBotId: _6, replyToMsgId: _7, date: _8!, message: _9!, media: _10, replyMarkup: _11, entities: _12, views: _13, editDate: _14, postAuthor: _15) } else { return nil @@ -13168,10 +13246,10 @@ public struct Api { switch self { case .messageEmpty(let id): return "(messageEmpty id: \(id))" - case .message(let flags, let id, let fromId, let toId, let fwdFrom, let viaBotId, let replyToMsgId, let date, let message, let media, let replyMarkup, let entities, let views, let editDate): - return "(message flags: \(flags), id: \(id), fromId: \(fromId), toId: \(toId), fwdFrom: \(fwdFrom), viaBotId: \(viaBotId), replyToMsgId: \(replyToMsgId), date: \(date), message: \(message), media: \(media), replyMarkup: \(replyMarkup), entities: \(entities), views: \(views), editDate: \(editDate))" case .messageService(let flags, let id, let fromId, let toId, let replyToMsgId, let date, let action): return "(messageService flags: \(flags), id: \(id), fromId: \(fromId), toId: \(toId), replyToMsgId: \(replyToMsgId), date: \(date), action: \(action))" + case .message(let flags, let id, let fromId, let toId, let fwdFrom, let viaBotId, let replyToMsgId, let date, let message, let media, let replyMarkup, let entities, let views, let editDate, let postAuthor): + return "(message flags: \(flags), id: \(id), fromId: \(fromId), toId: \(toId), fwdFrom: \(fwdFrom), viaBotId: \(viaBotId), replyToMsgId: \(replyToMsgId), date: \(date), message: \(message), media: \(media), replyMarkup: \(replyMarkup), entities: \(entities), views: \(views), editDate: \(editDate), postAuthor: \(postAuthor))" } } } @@ -14171,19 +14249,20 @@ public struct Api { } public enum MessageFwdHeader: CustomStringConvertible { - case messageFwdHeader(flags: Int32, fromId: Int32?, date: Int32, channelId: Int32?, channelPost: Int32?) + case messageFwdHeader(flags: Int32, fromId: Int32?, date: Int32, channelId: Int32?, channelPost: Int32?, postAuthor: String?) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { switch self { - case .messageFwdHeader(let flags, let fromId, let date, let channelId, let channelPost): + case .messageFwdHeader(let flags, let fromId, let date, let channelId, let channelPost, let postAuthor): if boxed { - buffer.appendInt32(-947462709) + buffer.appendInt32(-85986132) } serializeInt32(flags, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 0) != 0 {serializeInt32(fromId!, buffer: buffer, boxed: false)} serializeInt32(date, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 1) != 0 {serializeInt32(channelId!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 2) != 0 {serializeInt32(channelPost!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 3) != 0 {serializeString(postAuthor!, buffer: buffer, boxed: false)} break } return true @@ -14200,13 +14279,16 @@ public struct Api { if Int(_1!) & Int(1 << 1) != 0 {_4 = reader.readInt32() } var _5: Int32? if Int(_1!) & Int(1 << 2) != 0 {_5 = reader.readInt32() } + var _6: String? + if Int(_1!) & Int(1 << 3) != 0 {_6 = parseString(reader) } let _c1 = _1 != nil let _c2 = (Int(_1!) & Int(1 << 0) == 0) || _2 != nil let _c3 = _3 != nil let _c4 = (Int(_1!) & Int(1 << 1) == 0) || _4 != nil let _c5 = (Int(_1!) & Int(1 << 2) == 0) || _5 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 { - return Api.MessageFwdHeader.messageFwdHeader(flags: _1!, fromId: _2, date: _3!, channelId: _4, channelPost: _5) + let _c6 = (Int(_1!) & Int(1 << 3) == 0) || _6 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 { + return Api.MessageFwdHeader.messageFwdHeader(flags: _1!, fromId: _2, date: _3!, channelId: _4, channelPost: _5, postAuthor: _6) } else { return nil @@ -14216,8 +14298,8 @@ public struct Api { public var description: String { get { switch self { - case .messageFwdHeader(let flags, let fromId, let date, let channelId, let channelPost): - return "(messageFwdHeader flags: \(flags), fromId: \(fromId), date: \(date), channelId: \(channelId), channelPost: \(channelPost))" + case .messageFwdHeader(let flags, let fromId, let date, let channelId, let channelPost, let postAuthor): + return "(messageFwdHeader flags: \(flags), fromId: \(fromId), date: \(date), channelId: \(channelId), channelPost: \(channelPost), postAuthor: \(postAuthor))" } } } @@ -18262,13 +18344,13 @@ public struct Api { } public enum ImportedContacts: CustomStringConvertible { - case importedContacts(imported: [Api.ImportedContact], retryContacts: [Int64], users: [Api.User]) + case importedContacts(imported: [Api.ImportedContact], popularInvites: [Api.PopularContact], retryContacts: [Int64], users: [Api.User]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { switch self { - case .importedContacts(let imported, let retryContacts, let users): + case .importedContacts(let imported, let popularInvites, let retryContacts, let users): if boxed { - buffer.appendInt32(-1387117803) + buffer.appendInt32(2010127419) } buffer.appendInt32(481674261) buffer.appendInt32(Int32(imported.count)) @@ -18276,6 +18358,11 @@ public struct Api { item.serialize(buffer, true) } buffer.appendInt32(481674261) + buffer.appendInt32(Int32(popularInvites.count)) + for item in popularInvites { + item.serialize(buffer, true) + } + buffer.appendInt32(481674261) buffer.appendInt32(Int32(retryContacts.count)) for item in retryContacts { serializeInt64(item, buffer: buffer, boxed: false) @@ -18295,19 +18382,24 @@ public struct Api { if let _ = reader.readInt32() { _1 = Api.parseVector(reader, elementSignature: 0, elementType: Api.ImportedContact.self) } - var _2: [Int64]? + var _2: [Api.PopularContact]? if let _ = reader.readInt32() { - _2 = Api.parseVector(reader, elementSignature: 570911930, elementType: Int64.self) + _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.PopularContact.self) } - var _3: [Api.User]? + var _3: [Int64]? if let _ = reader.readInt32() { - _3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) + _3 = Api.parseVector(reader, elementSignature: 570911930, elementType: Int64.self) + } + var _4: [Api.User]? + if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = _3 != nil - if _c1 && _c2 && _c3 { - return Api.contacts.ImportedContacts.importedContacts(imported: _1!, retryContacts: _2!, users: _3!) + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.contacts.ImportedContacts.importedContacts(imported: _1!, popularInvites: _2!, retryContacts: _3!, users: _4!) } else { return nil @@ -18317,8 +18409,8 @@ public struct Api { public var description: String { get { switch self { - case .importedContacts(let imported, let retryContacts, let users): - return "(contacts.importedContacts imported: \(imported), retryContacts: \(retryContacts), users: \(users))" + case .importedContacts(let imported, let popularInvites, let retryContacts, let users): + return "(contacts.importedContacts imported: \(imported), popularInvites: \(popularInvites), retryContacts: \(retryContacts), users: \(users))" } } } @@ -19150,7 +19242,7 @@ public struct Api { public enum File: CustomStringConvertible { case file(type: Api.storage.FileType, mtime: Int32, bytes: Buffer) - case fileCdnRedirect(dcId: Int32, fileToken: Buffer, encryptionKey: Buffer, encryptionIv: Buffer) + case fileCdnRedirect(dcId: Int32, fileToken: Buffer, encryptionKey: Buffer, encryptionIv: Buffer, cdnFileHashes: [Api.CdnFileHash]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) -> Swift.Bool { switch self { @@ -19162,14 +19254,19 @@ public struct Api { serializeInt32(mtime, buffer: buffer, boxed: false) serializeBytes(bytes, buffer: buffer, boxed: false) break - case .fileCdnRedirect(let dcId, let fileToken, let encryptionKey, let encryptionIv): + case .fileCdnRedirect(let dcId, let fileToken, let encryptionKey, let encryptionIv, let cdnFileHashes): if boxed { - buffer.appendInt32(352864346) + buffer.appendInt32(-363659686) } serializeInt32(dcId, buffer: buffer, boxed: false) serializeBytes(fileToken, buffer: buffer, boxed: false) serializeBytes(encryptionKey, buffer: buffer, boxed: false) serializeBytes(encryptionIv, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(cdnFileHashes.count)) + for item in cdnFileHashes { + item.serialize(buffer, true) + } break } return true @@ -19203,12 +19300,17 @@ public struct Api { _3 = parseBytes(reader) var _4: Buffer? _4 = parseBytes(reader) + var _5: [Api.CdnFileHash]? + if let _ = reader.readInt32() { + _5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.CdnFileHash.self) + } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = _3 != nil let _c4 = _4 != nil - if _c1 && _c2 && _c3 && _c4 { - return Api.upload.File.fileCdnRedirect(dcId: _1!, fileToken: _2!, encryptionKey: _3!, encryptionIv: _4!) + let _c5 = _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return Api.upload.File.fileCdnRedirect(dcId: _1!, fileToken: _2!, encryptionKey: _3!, encryptionIv: _4!, cdnFileHashes: _5!) } else { return nil @@ -19220,8 +19322,8 @@ public struct Api { switch self { case .file(let type, let mtime, let bytes): return "(upload.file type: \(type), mtime: \(mtime), bytes: \(bytes))" - case .fileCdnRedirect(let dcId, let fileToken, let encryptionKey, let encryptionIv): - return "(upload.fileCdnRedirect dcId: \(dcId), fileToken: \(fileToken), encryptionKey: \(encryptionKey), encryptionIv: \(encryptionIv))" + case .fileCdnRedirect(let dcId, let fileToken, let encryptionKey, let encryptionIv, let cdnFileHashes): + return "(upload.fileCdnRedirect dcId: \(dcId), fileToken: \(fileToken), encryptionKey: \(encryptionKey), encryptionIv: \(encryptionIv), cdnFileHashes: \(cdnFileHashes))" } } } @@ -19929,7 +20031,7 @@ public struct Api { public struct functions { public struct messages { - public static func getMessages(id id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Messages?) { + public static func getMessages(id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Messages?) { let buffer = Buffer() buffer.appendInt32(1109588596) buffer.appendInt32(481674261) @@ -19947,7 +20049,7 @@ public struct Api { }) } - public static func getDialogs(flags flags: Int32, offsetDate: Int32, offsetId: Int32, offsetPeer: Api.InputPeer, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Dialogs?) { + public static func getDialogs(flags: Int32, offsetDate: Int32, offsetId: Int32, offsetPeer: Api.InputPeer, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Dialogs?) { let buffer = Buffer() buffer.appendInt32(421243333) serializeInt32(flags, buffer: buffer, boxed: false) @@ -19965,7 +20067,7 @@ public struct Api { }) } - public static func getHistory(peer peer: Api.InputPeer, offsetId: Int32, offsetDate: Int32, addOffset: Int32, limit: Int32, maxId: Int32, minId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Messages?) { + public static func getHistory(peer: Api.InputPeer, offsetId: Int32, offsetDate: Int32, addOffset: Int32, limit: Int32, maxId: Int32, minId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Messages?) { let buffer = Buffer() buffer.appendInt32(-1347868602) peer.serialize(buffer, true) @@ -19985,7 +20087,7 @@ public struct Api { }) } - public static func readHistory(peer peer: Api.InputPeer, maxId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedMessages?) { + public static func readHistory(peer: Api.InputPeer, maxId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedMessages?) { let buffer = Buffer() buffer.appendInt32(238054714) peer.serialize(buffer, true) @@ -20000,7 +20102,7 @@ public struct Api { }) } - public static func deleteHistory(flags flags: Int32, peer: Api.InputPeer, maxId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedHistory?) { + public static func deleteHistory(flags: Int32, peer: Api.InputPeer, maxId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedHistory?) { let buffer = Buffer() buffer.appendInt32(469850889) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20016,7 +20118,7 @@ public struct Api { }) } - public static func deleteMessages(flags flags: Int32, id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedMessages?) { + public static func deleteMessages(flags: Int32, id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedMessages?) { let buffer = Buffer() buffer.appendInt32(-443640366) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20035,7 +20137,7 @@ public struct Api { }) } - public static func receivedMessages(maxId maxId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.ReceivedNotifyMessage]?) { + public static func receivedMessages(maxId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.ReceivedNotifyMessage]?) { let buffer = Buffer() buffer.appendInt32(94983360) serializeInt32(maxId, buffer: buffer, boxed: false) @@ -20049,7 +20151,7 @@ public struct Api { }) } - public static func setTyping(peer peer: Api.InputPeer, action: Api.SendMessageAction) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func setTyping(peer: Api.InputPeer, action: Api.SendMessageAction) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-1551737264) peer.serialize(buffer, true) @@ -20064,7 +20166,7 @@ public struct Api { }) } - public static func sendMessage(flags flags: Int32, peer: Api.InputPeer, replyToMsgId: Int32?, message: String, randomId: Int64, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func sendMessage(flags: Int32, peer: Api.InputPeer, replyToMsgId: Int32?, message: String, randomId: Int64, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-91733382) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20088,7 +20190,7 @@ public struct Api { }) } - public static func sendMedia(flags flags: Int32, peer: Api.InputPeer, replyToMsgId: Int32?, media: Api.InputMedia, randomId: Int64, replyMarkup: Api.ReplyMarkup?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func sendMedia(flags: Int32, peer: Api.InputPeer, replyToMsgId: Int32?, media: Api.InputMedia, randomId: Int64, replyMarkup: Api.ReplyMarkup?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-923703407) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20107,7 +20209,7 @@ public struct Api { }) } - public static func forwardMessages(flags flags: Int32, fromPeer: Api.InputPeer, id: [Int32], randomId: [Int64], toPeer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func forwardMessages(flags: Int32, fromPeer: Api.InputPeer, id: [Int32], randomId: [Int64], toPeer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(1888354709) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20133,7 +20235,7 @@ public struct Api { }) } - public static func reportSpam(peer peer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func reportSpam(peer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-820669733) peer.serialize(buffer, true) @@ -20147,7 +20249,7 @@ public struct Api { }) } - public static func hideReportSpam(peer peer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func hideReportSpam(peer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-1460572005) peer.serialize(buffer, true) @@ -20161,7 +20263,7 @@ public struct Api { }) } - public static func getPeerSettings(peer peer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.PeerSettings?) { + public static func getPeerSettings(peer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.PeerSettings?) { let buffer = Buffer() buffer.appendInt32(913498268) peer.serialize(buffer, true) @@ -20175,7 +20277,7 @@ public struct Api { }) } - public static func getChats(id id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Chats?) { + public static func getChats(id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Chats?) { let buffer = Buffer() buffer.appendInt32(1013621127) buffer.appendInt32(481674261) @@ -20193,7 +20295,7 @@ public struct Api { }) } - public static func getFullChat(chatId chatId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.ChatFull?) { + public static func getFullChat(chatId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.ChatFull?) { let buffer = Buffer() buffer.appendInt32(998448230) serializeInt32(chatId, buffer: buffer, boxed: false) @@ -20207,7 +20309,7 @@ public struct Api { }) } - public static func editChatTitle(chatId chatId: Int32, title: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func editChatTitle(chatId: Int32, title: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-599447467) serializeInt32(chatId, buffer: buffer, boxed: false) @@ -20222,7 +20324,7 @@ public struct Api { }) } - public static func editChatPhoto(chatId chatId: Int32, photo: Api.InputChatPhoto) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func editChatPhoto(chatId: Int32, photo: Api.InputChatPhoto) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-900957736) serializeInt32(chatId, buffer: buffer, boxed: false) @@ -20237,7 +20339,7 @@ public struct Api { }) } - public static func addChatUser(chatId chatId: Int32, userId: Api.InputUser, fwdLimit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func addChatUser(chatId: Int32, userId: Api.InputUser, fwdLimit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-106911223) serializeInt32(chatId, buffer: buffer, boxed: false) @@ -20253,7 +20355,7 @@ public struct Api { }) } - public static func deleteChatUser(chatId chatId: Int32, userId: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func deleteChatUser(chatId: Int32, userId: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-530505962) serializeInt32(chatId, buffer: buffer, boxed: false) @@ -20268,7 +20370,7 @@ public struct Api { }) } - public static func createChat(users users: [Api.InputUser], title: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func createChat(users: [Api.InputUser], title: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(164303470) buffer.appendInt32(481674261) @@ -20287,7 +20389,7 @@ public struct Api { }) } - public static func forwardMessage(peer peer: Api.InputPeer, id: Int32, randomId: Int64) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func forwardMessage(peer: Api.InputPeer, id: Int32, randomId: Int64) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(865483769) peer.serialize(buffer, true) @@ -20303,7 +20405,7 @@ public struct Api { }) } - public static func getDhConfig(version version: Int32, randomLength: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.DhConfig?) { + public static func getDhConfig(version: Int32, randomLength: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.DhConfig?) { let buffer = Buffer() buffer.appendInt32(651135312) serializeInt32(version, buffer: buffer, boxed: false) @@ -20318,7 +20420,7 @@ public struct Api { }) } - public static func requestEncryption(userId userId: Api.InputUser, randomId: Int32, gA: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.EncryptedChat?) { + public static func requestEncryption(userId: Api.InputUser, randomId: Int32, gA: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.EncryptedChat?) { let buffer = Buffer() buffer.appendInt32(-162681021) userId.serialize(buffer, true) @@ -20334,7 +20436,7 @@ public struct Api { }) } - public static func acceptEncryption(peer peer: Api.InputEncryptedChat, gB: Buffer, keyFingerprint: Int64) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.EncryptedChat?) { + public static func acceptEncryption(peer: Api.InputEncryptedChat, gB: Buffer, keyFingerprint: Int64) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.EncryptedChat?) { let buffer = Buffer() buffer.appendInt32(1035731989) peer.serialize(buffer, true) @@ -20350,7 +20452,7 @@ public struct Api { }) } - public static func discardEncryption(chatId chatId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func discardEncryption(chatId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-304536635) serializeInt32(chatId, buffer: buffer, boxed: false) @@ -20364,7 +20466,7 @@ public struct Api { }) } - public static func setEncryptedTyping(peer peer: Api.InputEncryptedChat, typing: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func setEncryptedTyping(peer: Api.InputEncryptedChat, typing: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(2031374829) peer.serialize(buffer, true) @@ -20379,7 +20481,7 @@ public struct Api { }) } - public static func readEncryptedHistory(peer peer: Api.InputEncryptedChat, maxDate: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func readEncryptedHistory(peer: Api.InputEncryptedChat, maxDate: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(2135648522) peer.serialize(buffer, true) @@ -20394,7 +20496,7 @@ public struct Api { }) } - public static func sendEncrypted(peer peer: Api.InputEncryptedChat, randomId: Int64, data: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.SentEncryptedMessage?) { + public static func sendEncrypted(peer: Api.InputEncryptedChat, randomId: Int64, data: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.SentEncryptedMessage?) { let buffer = Buffer() buffer.appendInt32(-1451792525) peer.serialize(buffer, true) @@ -20410,7 +20512,7 @@ public struct Api { }) } - public static func sendEncryptedFile(peer peer: Api.InputEncryptedChat, randomId: Int64, data: Buffer, file: Api.InputEncryptedFile) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.SentEncryptedMessage?) { + public static func sendEncryptedFile(peer: Api.InputEncryptedChat, randomId: Int64, data: Buffer, file: Api.InputEncryptedFile) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.SentEncryptedMessage?) { let buffer = Buffer() buffer.appendInt32(-1701831834) peer.serialize(buffer, true) @@ -20427,7 +20529,7 @@ public struct Api { }) } - public static func sendEncryptedService(peer peer: Api.InputEncryptedChat, randomId: Int64, data: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.SentEncryptedMessage?) { + public static func sendEncryptedService(peer: Api.InputEncryptedChat, randomId: Int64, data: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.SentEncryptedMessage?) { let buffer = Buffer() buffer.appendInt32(852769188) peer.serialize(buffer, true) @@ -20443,7 +20545,7 @@ public struct Api { }) } - public static func receivedQueue(maxQts maxQts: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> [Int64]?) { + public static func receivedQueue(maxQts: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> [Int64]?) { let buffer = Buffer() buffer.appendInt32(1436924774) serializeInt32(maxQts, buffer: buffer, boxed: false) @@ -20457,7 +20559,7 @@ public struct Api { }) } - public static func reportEncryptedSpam(peer peer: Api.InputEncryptedChat) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func reportEncryptedSpam(peer: Api.InputEncryptedChat) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(1259113487) peer.serialize(buffer, true) @@ -20471,7 +20573,7 @@ public struct Api { }) } - public static func readMessageContents(id id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedMessages?) { + public static func readMessageContents(id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedMessages?) { let buffer = Buffer() buffer.appendInt32(916930423) buffer.appendInt32(481674261) @@ -20489,7 +20591,7 @@ public struct Api { }) } - public static func getAllStickers(hash hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AllStickers?) { + public static func getAllStickers(hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AllStickers?) { let buffer = Buffer() buffer.appendInt32(479598769) serializeInt32(hash, buffer: buffer, boxed: false) @@ -20503,7 +20605,7 @@ public struct Api { }) } - public static func getWebPagePreview(message message: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.MessageMedia?) { + public static func getWebPagePreview(message: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.MessageMedia?) { let buffer = Buffer() buffer.appendInt32(623001124) serializeString(message, buffer: buffer, boxed: false) @@ -20517,7 +20619,7 @@ public struct Api { }) } - public static func exportChatInvite(chatId chatId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.ExportedChatInvite?) { + public static func exportChatInvite(chatId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.ExportedChatInvite?) { let buffer = Buffer() buffer.appendInt32(2106086025) serializeInt32(chatId, buffer: buffer, boxed: false) @@ -20531,7 +20633,7 @@ public struct Api { }) } - public static func checkChatInvite(hash hash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.ChatInvite?) { + public static func checkChatInvite(hash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.ChatInvite?) { let buffer = Buffer() buffer.appendInt32(1051570619) serializeString(hash, buffer: buffer, boxed: false) @@ -20545,7 +20647,7 @@ public struct Api { }) } - public static func importChatInvite(hash hash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func importChatInvite(hash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(1817183516) serializeString(hash, buffer: buffer, boxed: false) @@ -20559,7 +20661,7 @@ public struct Api { }) } - public static func getStickerSet(stickerset stickerset: Api.InputStickerSet) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.StickerSet?) { + public static func getStickerSet(stickerset: Api.InputStickerSet) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.StickerSet?) { let buffer = Buffer() buffer.appendInt32(639215886) stickerset.serialize(buffer, true) @@ -20573,7 +20675,7 @@ public struct Api { }) } - public static func installStickerSet(stickerset stickerset: Api.InputStickerSet, archived: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.StickerSetInstallResult?) { + public static func installStickerSet(stickerset: Api.InputStickerSet, archived: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.StickerSetInstallResult?) { let buffer = Buffer() buffer.appendInt32(-946871200) stickerset.serialize(buffer, true) @@ -20588,7 +20690,7 @@ public struct Api { }) } - public static func uninstallStickerSet(stickerset stickerset: Api.InputStickerSet) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func uninstallStickerSet(stickerset: Api.InputStickerSet) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-110209570) stickerset.serialize(buffer, true) @@ -20602,7 +20704,7 @@ public struct Api { }) } - public static func startBot(bot bot: Api.InputUser, peer: Api.InputPeer, randomId: Int64, startParam: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func startBot(bot: Api.InputUser, peer: Api.InputPeer, randomId: Int64, startParam: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-421563528) bot.serialize(buffer, true) @@ -20619,7 +20721,7 @@ public struct Api { }) } - public static func getMessagesViews(peer peer: Api.InputPeer, id: [Int32], increment: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> [Int32]?) { + public static func getMessagesViews(peer: Api.InputPeer, id: [Int32], increment: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> [Int32]?) { let buffer = Buffer() buffer.appendInt32(-993483427) peer.serialize(buffer, true) @@ -20639,7 +20741,7 @@ public struct Api { }) } - public static func toggleChatAdmins(chatId chatId: Int32, enabled: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func toggleChatAdmins(chatId: Int32, enabled: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-326379039) serializeInt32(chatId, buffer: buffer, boxed: false) @@ -20654,7 +20756,7 @@ public struct Api { }) } - public static func editChatAdmin(chatId chatId: Int32, userId: Api.InputUser, isAdmin: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func editChatAdmin(chatId: Int32, userId: Api.InputUser, isAdmin: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-1444503762) serializeInt32(chatId, buffer: buffer, boxed: false) @@ -20670,7 +20772,7 @@ public struct Api { }) } - public static func migrateChat(chatId chatId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func migrateChat(chatId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(363051235) serializeInt32(chatId, buffer: buffer, boxed: false) @@ -20684,7 +20786,7 @@ public struct Api { }) } - public static func searchGlobal(q q: String, offsetDate: Int32, offsetPeer: Api.InputPeer, offsetId: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Messages?) { + public static func searchGlobal(q: String, offsetDate: Int32, offsetPeer: Api.InputPeer, offsetId: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Messages?) { let buffer = Buffer() buffer.appendInt32(-1640190800) serializeString(q, buffer: buffer, boxed: false) @@ -20702,7 +20804,7 @@ public struct Api { }) } - public static func reorderStickerSets(flags flags: Int32, order: [Int64]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func reorderStickerSets(flags: Int32, order: [Int64]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(2016638777) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20721,7 +20823,7 @@ public struct Api { }) } - public static func getDocumentByHash(sha256 sha256: Buffer, size: Int32, mimeType: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Document?) { + public static func getDocumentByHash(sha256: Buffer, size: Int32, mimeType: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Document?) { let buffer = Buffer() buffer.appendInt32(864953444) serializeBytes(sha256, buffer: buffer, boxed: false) @@ -20737,7 +20839,7 @@ public struct Api { }) } - public static func searchGifs(q q: String, offset: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.FoundGifs?) { + public static func searchGifs(q: String, offset: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.FoundGifs?) { let buffer = Buffer() buffer.appendInt32(-1080395925) serializeString(q, buffer: buffer, boxed: false) @@ -20752,7 +20854,7 @@ public struct Api { }) } - public static func getSavedGifs(hash hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.SavedGifs?) { + public static func getSavedGifs(hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.SavedGifs?) { let buffer = Buffer() buffer.appendInt32(-2084618926) serializeInt32(hash, buffer: buffer, boxed: false) @@ -20766,7 +20868,7 @@ public struct Api { }) } - public static func saveGif(id id: Api.InputDocument, unsave: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func saveGif(id: Api.InputDocument, unsave: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(846868683) id.serialize(buffer, true) @@ -20781,7 +20883,7 @@ public struct Api { }) } - public static func getInlineBotResults(flags flags: Int32, bot: Api.InputUser, peer: Api.InputPeer, geoPoint: Api.InputGeoPoint?, query: String, offset: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.BotResults?) { + public static func getInlineBotResults(flags: Int32, bot: Api.InputUser, peer: Api.InputPeer, geoPoint: Api.InputGeoPoint?, query: String, offset: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.BotResults?) { let buffer = Buffer() buffer.appendInt32(1364105629) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20800,7 +20902,7 @@ public struct Api { }) } - public static func setInlineBotResults(flags flags: Int32, queryId: Int64, results: [Api.InputBotInlineResult], cacheTime: Int32, nextOffset: String?, switchPm: Api.InlineBotSwitchPM?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func setInlineBotResults(flags: Int32, queryId: Int64, results: [Api.InputBotInlineResult], cacheTime: Int32, nextOffset: String?, switchPm: Api.InlineBotSwitchPM?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-346119674) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20823,7 +20925,7 @@ public struct Api { }) } - public static func sendInlineBotResult(flags flags: Int32, peer: Api.InputPeer, replyToMsgId: Int32?, randomId: Int64, queryId: Int64, id: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func sendInlineBotResult(flags: Int32, peer: Api.InputPeer, replyToMsgId: Int32?, randomId: Int64, queryId: Int64, id: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-1318189314) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20842,7 +20944,7 @@ public struct Api { }) } - public static func getMessageEditData(peer peer: Api.InputPeer, id: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.MessageEditData?) { + public static func getMessageEditData(peer: Api.InputPeer, id: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.MessageEditData?) { let buffer = Buffer() buffer.appendInt32(-39416522) peer.serialize(buffer, true) @@ -20857,7 +20959,7 @@ public struct Api { }) } - public static func editMessage(flags flags: Int32, peer: Api.InputPeer, id: Int32, message: String?, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func editMessage(flags: Int32, peer: Api.InputPeer, id: Int32, message: String?, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-829299510) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20880,7 +20982,7 @@ public struct Api { }) } - public static func editInlineBotMessage(flags flags: Int32, id: Api.InputBotInlineMessageID, message: String?, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func editInlineBotMessage(flags: Int32, id: Api.InputBotInlineMessageID, message: String?, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(319564933) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20902,7 +21004,7 @@ public struct Api { }) } - public static func getBotCallbackAnswer(flags flags: Int32, peer: Api.InputPeer, msgId: Int32, data: Buffer?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.BotCallbackAnswer?) { + public static func getBotCallbackAnswer(flags: Int32, peer: Api.InputPeer, msgId: Int32, data: Buffer?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.BotCallbackAnswer?) { let buffer = Buffer() buffer.appendInt32(-2130010132) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20919,7 +21021,7 @@ public struct Api { }) } - public static func setBotCallbackAnswer(flags flags: Int32, queryId: Int64, message: String?, url: String?, cacheTime: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func setBotCallbackAnswer(flags: Int32, queryId: Int64, message: String?, url: String?, cacheTime: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-712043766) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20937,7 +21039,7 @@ public struct Api { }) } - public static func getPeerDialogs(peers peers: [Api.InputPeer]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.PeerDialogs?) { + public static func getPeerDialogs(peers: [Api.InputPeer]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.PeerDialogs?) { let buffer = Buffer() buffer.appendInt32(764901049) buffer.appendInt32(481674261) @@ -20955,7 +21057,7 @@ public struct Api { }) } - public static func saveDraft(flags flags: Int32, replyToMsgId: Int32?, peer: Api.InputPeer, message: String, entities: [Api.MessageEntity]?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func saveDraft(flags: Int32, replyToMsgId: Int32?, peer: Api.InputPeer, message: String, entities: [Api.MessageEntity]?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-1137057461) serializeInt32(flags, buffer: buffer, boxed: false) @@ -20991,7 +21093,7 @@ public struct Api { }) } - public static func getFeaturedStickers(hash hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.FeaturedStickers?) { + public static func getFeaturedStickers(hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.FeaturedStickers?) { let buffer = Buffer() buffer.appendInt32(766298703) serializeInt32(hash, buffer: buffer, boxed: false) @@ -21005,7 +21107,7 @@ public struct Api { }) } - public static func readFeaturedStickers(id id: [Int64]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func readFeaturedStickers(id: [Int64]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(1527873830) buffer.appendInt32(481674261) @@ -21023,7 +21125,7 @@ public struct Api { }) } - public static func getRecentStickers(flags flags: Int32, hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.RecentStickers?) { + public static func getRecentStickers(flags: Int32, hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.RecentStickers?) { let buffer = Buffer() buffer.appendInt32(1587647177) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21038,7 +21140,7 @@ public struct Api { }) } - public static func saveRecentSticker(flags flags: Int32, id: Api.InputDocument, unsave: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func saveRecentSticker(flags: Int32, id: Api.InputDocument, unsave: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(958863608) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21054,7 +21156,7 @@ public struct Api { }) } - public static func clearRecentStickers(flags flags: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func clearRecentStickers(flags: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-1986437075) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21068,7 +21170,7 @@ public struct Api { }) } - public static func getArchivedStickers(flags flags: Int32, offsetId: Int64, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.ArchivedStickers?) { + public static func getArchivedStickers(flags: Int32, offsetId: Int64, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.ArchivedStickers?) { let buffer = Buffer() buffer.appendInt32(1475442322) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21084,7 +21186,7 @@ public struct Api { }) } - public static func getMaskStickers(hash hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AllStickers?) { + public static func getMaskStickers(hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AllStickers?) { let buffer = Buffer() buffer.appendInt32(1706608543) serializeInt32(hash, buffer: buffer, boxed: false) @@ -21098,7 +21200,7 @@ public struct Api { }) } - public static func getAttachedStickers(media media: Api.InputStickeredMedia) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.StickerSetCovered]?) { + public static func getAttachedStickers(media: Api.InputStickeredMedia) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.StickerSetCovered]?) { let buffer = Buffer() buffer.appendInt32(-866424884) media.serialize(buffer, true) @@ -21112,7 +21214,7 @@ public struct Api { }) } - public static func setGameScore(flags flags: Int32, peer: Api.InputPeer, id: Int32, userId: Api.InputUser, score: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func setGameScore(flags: Int32, peer: Api.InputPeer, id: Int32, userId: Api.InputUser, score: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-1896289088) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21130,7 +21232,7 @@ public struct Api { }) } - public static func setInlineGameScore(flags flags: Int32, id: Api.InputBotInlineMessageID, userId: Api.InputUser, score: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func setInlineGameScore(flags: Int32, id: Api.InputBotInlineMessageID, userId: Api.InputUser, score: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(363700068) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21147,7 +21249,7 @@ public struct Api { }) } - public static func getGameHighScores(peer peer: Api.InputPeer, id: Int32, userId: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.HighScores?) { + public static func getGameHighScores(peer: Api.InputPeer, id: Int32, userId: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.HighScores?) { let buffer = Buffer() buffer.appendInt32(-400399203) peer.serialize(buffer, true) @@ -21163,7 +21265,7 @@ public struct Api { }) } - public static func getInlineGameHighScores(id id: Api.InputBotInlineMessageID, userId: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.HighScores?) { + public static func getInlineGameHighScores(id: Api.InputBotInlineMessageID, userId: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.HighScores?) { let buffer = Buffer() buffer.appendInt32(258170395) id.serialize(buffer, true) @@ -21178,7 +21280,7 @@ public struct Api { }) } - public static func getCommonChats(userId userId: Api.InputUser, maxId: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Chats?) { + public static func getCommonChats(userId: Api.InputUser, maxId: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Chats?) { let buffer = Buffer() buffer.appendInt32(218777796) userId.serialize(buffer, true) @@ -21194,7 +21296,7 @@ public struct Api { }) } - public static func getAllChats(exceptIds exceptIds: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Chats?) { + public static func getAllChats(exceptIds: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Chats?) { let buffer = Buffer() buffer.appendInt32(-341307408) buffer.appendInt32(481674261) @@ -21212,7 +21314,7 @@ public struct Api { }) } - public static func getWebPage(url url: String, hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.WebPage?) { + public static func getWebPage(url: String, hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.WebPage?) { let buffer = Buffer() buffer.appendInt32(852135825) serializeString(url, buffer: buffer, boxed: false) @@ -21227,7 +21329,7 @@ public struct Api { }) } - public static func toggleDialogPin(flags flags: Int32, peer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func toggleDialogPin(flags: Int32, peer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(847887978) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21242,7 +21344,7 @@ public struct Api { }) } - public static func reorderPinnedDialogs(flags flags: Int32, order: [Api.InputPeer]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func reorderPinnedDialogs(flags: Int32, order: [Api.InputPeer]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-1784678844) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21275,7 +21377,7 @@ public struct Api { }) } - public static func setBotShippingResults(flags flags: Int32, queryId: Int64, error: String?, shippingOptions: [Api.ShippingOption]?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func setBotShippingResults(flags: Int32, queryId: Int64, error: String?, shippingOptions: [Api.ShippingOption]?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-436833542) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21296,7 +21398,7 @@ public struct Api { }) } - public static func setBotPrecheckoutResults(flags flags: Int32, queryId: Int64, error: String?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func setBotPrecheckoutResults(flags: Int32, queryId: Int64, error: String?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(163765653) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21312,7 +21414,7 @@ public struct Api { }) } - public static func search(flags flags: Int32, peer: Api.InputPeer, q: String, fromId: Api.InputUser?, filter: Api.MessagesFilter, minDate: Int32, maxDate: Int32, offset: Int32, maxId: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Messages?) { + public static func search(flags: Int32, peer: Api.InputPeer, q: String, fromId: Api.InputUser?, filter: Api.MessagesFilter, minDate: Int32, maxDate: Int32, offset: Int32, maxId: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Messages?) { let buffer = Buffer() buffer.appendInt32(-225926539) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21336,7 +21438,7 @@ public struct Api { } } public struct channels { - public static func readHistory(channel channel: Api.InputChannel, maxId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func readHistory(channel: Api.InputChannel, maxId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-871347913) channel.serialize(buffer, true) @@ -21351,7 +21453,7 @@ public struct Api { }) } - public static func deleteMessages(channel channel: Api.InputChannel, id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedMessages?) { + public static func deleteMessages(channel: Api.InputChannel, id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedMessages?) { let buffer = Buffer() buffer.appendInt32(-2067661490) channel.serialize(buffer, true) @@ -21370,7 +21472,7 @@ public struct Api { }) } - public static func deleteUserHistory(channel channel: Api.InputChannel, userId: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedHistory?) { + public static func deleteUserHistory(channel: Api.InputChannel, userId: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.AffectedHistory?) { let buffer = Buffer() buffer.appendInt32(-787622117) channel.serialize(buffer, true) @@ -21385,7 +21487,7 @@ public struct Api { }) } - public static func reportSpam(channel channel: Api.InputChannel, userId: Api.InputUser, id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func reportSpam(channel: Api.InputChannel, userId: Api.InputUser, id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-32999408) channel.serialize(buffer, true) @@ -21405,7 +21507,7 @@ public struct Api { }) } - public static func getMessages(channel channel: Api.InputChannel, id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Messages?) { + public static func getMessages(channel: Api.InputChannel, id: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Messages?) { let buffer = Buffer() buffer.appendInt32(-1814580409) channel.serialize(buffer, true) @@ -21424,7 +21526,7 @@ public struct Api { }) } - public static func getParticipants(channel channel: Api.InputChannel, filter: Api.ChannelParticipantsFilter, offset: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.channels.ChannelParticipants?) { + public static func getParticipants(channel: Api.InputChannel, filter: Api.ChannelParticipantsFilter, offset: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.channels.ChannelParticipants?) { let buffer = Buffer() buffer.appendInt32(618237842) channel.serialize(buffer, true) @@ -21441,7 +21543,7 @@ public struct Api { }) } - public static func getParticipant(channel channel: Api.InputChannel, userId: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.channels.ChannelParticipant?) { + public static func getParticipant(channel: Api.InputChannel, userId: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.channels.ChannelParticipant?) { let buffer = Buffer() buffer.appendInt32(1416484774) channel.serialize(buffer, true) @@ -21456,7 +21558,7 @@ public struct Api { }) } - public static func getChannels(id id: [Api.InputChannel]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Chats?) { + public static func getChannels(id: [Api.InputChannel]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.Chats?) { let buffer = Buffer() buffer.appendInt32(176122811) buffer.appendInt32(481674261) @@ -21474,7 +21576,7 @@ public struct Api { }) } - public static func getFullChannel(channel channel: Api.InputChannel) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.ChatFull?) { + public static func getFullChannel(channel: Api.InputChannel) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.messages.ChatFull?) { let buffer = Buffer() buffer.appendInt32(141781513) channel.serialize(buffer, true) @@ -21488,7 +21590,7 @@ public struct Api { }) } - public static func createChannel(flags flags: Int32, title: String, about: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func createChannel(flags: Int32, title: String, about: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-192332417) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21504,7 +21606,7 @@ public struct Api { }) } - public static func editAbout(channel channel: Api.InputChannel, about: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func editAbout(channel: Api.InputChannel, about: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(333610782) channel.serialize(buffer, true) @@ -21519,7 +21621,7 @@ public struct Api { }) } - public static func editTitle(channel channel: Api.InputChannel, title: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func editTitle(channel: Api.InputChannel, title: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(1450044624) channel.serialize(buffer, true) @@ -21534,7 +21636,7 @@ public struct Api { }) } - public static func editPhoto(channel channel: Api.InputChannel, photo: Api.InputChatPhoto) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func editPhoto(channel: Api.InputChannel, photo: Api.InputChatPhoto) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-248621111) channel.serialize(buffer, true) @@ -21549,7 +21651,7 @@ public struct Api { }) } - public static func checkUsername(channel channel: Api.InputChannel, username: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func checkUsername(channel: Api.InputChannel, username: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(283557164) channel.serialize(buffer, true) @@ -21564,7 +21666,7 @@ public struct Api { }) } - public static func updateUsername(channel channel: Api.InputChannel, username: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func updateUsername(channel: Api.InputChannel, username: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(890549214) channel.serialize(buffer, true) @@ -21579,7 +21681,7 @@ public struct Api { }) } - public static func joinChannel(channel channel: Api.InputChannel) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func joinChannel(channel: Api.InputChannel) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(615851205) channel.serialize(buffer, true) @@ -21593,7 +21695,7 @@ public struct Api { }) } - public static func leaveChannel(channel channel: Api.InputChannel) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func leaveChannel(channel: Api.InputChannel) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-130635115) channel.serialize(buffer, true) @@ -21607,7 +21709,7 @@ public struct Api { }) } - public static func inviteToChannel(channel channel: Api.InputChannel, users: [Api.InputUser]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func inviteToChannel(channel: Api.InputChannel, users: [Api.InputUser]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(429865580) channel.serialize(buffer, true) @@ -21626,7 +21728,7 @@ public struct Api { }) } - public static func kickFromChannel(channel channel: Api.InputChannel, userId: Api.InputUser, kicked: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func kickFromChannel(channel: Api.InputChannel, userId: Api.InputUser, kicked: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-1502421484) channel.serialize(buffer, true) @@ -21642,7 +21744,7 @@ public struct Api { }) } - public static func exportInvite(channel channel: Api.InputChannel) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.ExportedChatInvite?) { + public static func exportInvite(channel: Api.InputChannel) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.ExportedChatInvite?) { let buffer = Buffer() buffer.appendInt32(-950663035) channel.serialize(buffer, true) @@ -21656,7 +21758,7 @@ public struct Api { }) } - public static func deleteChannel(channel channel: Api.InputChannel) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func deleteChannel(channel: Api.InputChannel) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-1072619549) channel.serialize(buffer, true) @@ -21670,7 +21772,7 @@ public struct Api { }) } - public static func toggleInvites(channel channel: Api.InputChannel, enabled: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func toggleInvites(channel: Api.InputChannel, enabled: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(1231065863) channel.serialize(buffer, true) @@ -21685,7 +21787,7 @@ public struct Api { }) } - public static func exportMessageLink(channel channel: Api.InputChannel, id: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.ExportedMessageLink?) { + public static func exportMessageLink(channel: Api.InputChannel, id: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.ExportedMessageLink?) { let buffer = Buffer() buffer.appendInt32(-934882771) channel.serialize(buffer, true) @@ -21700,7 +21802,7 @@ public struct Api { }) } - public static func toggleSignatures(channel channel: Api.InputChannel, enabled: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func toggleSignatures(channel: Api.InputChannel, enabled: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(527021574) channel.serialize(buffer, true) @@ -21715,7 +21817,7 @@ public struct Api { }) } - public static func updatePinnedMessage(flags flags: Int32, channel: Api.InputChannel, id: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func updatePinnedMessage(flags: Int32, channel: Api.InputChannel, id: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-1490162350) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21745,7 +21847,7 @@ public struct Api { }) } - public static func editAdmin(channel channel: Api.InputChannel, userId: Api.InputUser, adminRights: Api.ChannelAdminRights) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func editAdmin(channel: Api.InputChannel, userId: Api.InputUser, adminRights: Api.ChannelAdminRights) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(548962836) channel.serialize(buffer, true) @@ -21761,7 +21863,7 @@ public struct Api { }) } - public static func editBanned(channel channel: Api.InputChannel, userId: Api.InputUser, bannedRights: Api.ChannelBannedRights) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func editBanned(channel: Api.InputChannel, userId: Api.InputUser, bannedRights: Api.ChannelBannedRights) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-1076292147) channel.serialize(buffer, true) @@ -21777,7 +21879,7 @@ public struct Api { }) } - public static func getAdminLog(flags flags: Int32, channel: Api.InputChannel, q: String, eventsFilter: Api.ChannelAdminLogEventsFilter?, admins: [Api.InputUser]?, maxId: Int64, minId: Int64, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.channels.AdminLogResults?) { + public static func getAdminLog(flags: Int32, channel: Api.InputChannel, q: String, eventsFilter: Api.ChannelAdminLogEventsFilter?, admins: [Api.InputUser]?, maxId: Int64, minId: Int64, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.channels.AdminLogResults?) { let buffer = Buffer() buffer.appendInt32(870184064) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21803,7 +21905,7 @@ public struct Api { } } public struct payments { - public static func getPaymentForm(msgId msgId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.payments.PaymentForm?) { + public static func getPaymentForm(msgId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.payments.PaymentForm?) { let buffer = Buffer() buffer.appendInt32(-1712285883) serializeInt32(msgId, buffer: buffer, boxed: false) @@ -21817,7 +21919,7 @@ public struct Api { }) } - public static func getPaymentReceipt(msgId msgId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.payments.PaymentReceipt?) { + public static func getPaymentReceipt(msgId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.payments.PaymentReceipt?) { let buffer = Buffer() buffer.appendInt32(-1601001088) serializeInt32(msgId, buffer: buffer, boxed: false) @@ -21831,7 +21933,7 @@ public struct Api { }) } - public static func validateRequestedInfo(flags flags: Int32, msgId: Int32, info: Api.PaymentRequestedInfo) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.payments.ValidatedRequestedInfo?) { + public static func validateRequestedInfo(flags: Int32, msgId: Int32, info: Api.PaymentRequestedInfo) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.payments.ValidatedRequestedInfo?) { let buffer = Buffer() buffer.appendInt32(1997180532) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21847,7 +21949,7 @@ public struct Api { }) } - public static func sendPaymentForm(flags flags: Int32, msgId: Int32, requestedInfoId: String?, shippingOptionId: String?, credentials: Api.InputPaymentCredentials) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.payments.PaymentResult?) { + public static func sendPaymentForm(flags: Int32, msgId: Int32, requestedInfoId: String?, shippingOptionId: String?, credentials: Api.InputPaymentCredentials) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.payments.PaymentResult?) { let buffer = Buffer() buffer.appendInt32(730364339) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21879,7 +21981,7 @@ public struct Api { }) } - public static func clearSavedInfo(flags flags: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func clearSavedInfo(flags: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-667062079) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21894,7 +21996,7 @@ public struct Api { } } public struct auth { - public static func checkPhone(phoneNumber phoneNumber: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.CheckedPhone?) { + public static func checkPhone(phoneNumber: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.CheckedPhone?) { let buffer = Buffer() buffer.appendInt32(1877286395) serializeString(phoneNumber, buffer: buffer, boxed: false) @@ -21908,7 +22010,7 @@ public struct Api { }) } - public static func sendCode(flags flags: Int32, phoneNumber: String, currentNumber: Api.Bool?, apiId: Int32, apiHash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.SentCode?) { + public static func sendCode(flags: Int32, phoneNumber: String, currentNumber: Api.Bool?, apiId: Int32, apiHash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.SentCode?) { let buffer = Buffer() buffer.appendInt32(-2035355412) serializeInt32(flags, buffer: buffer, boxed: false) @@ -21926,7 +22028,7 @@ public struct Api { }) } - public static func signUp(phoneNumber phoneNumber: String, phoneCodeHash: String, phoneCode: String, firstName: String, lastName: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { + public static func signUp(phoneNumber: String, phoneCodeHash: String, phoneCode: String, firstName: String, lastName: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { let buffer = Buffer() buffer.appendInt32(453408308) serializeString(phoneNumber, buffer: buffer, boxed: false) @@ -21944,7 +22046,7 @@ public struct Api { }) } - public static func signIn(phoneNumber phoneNumber: String, phoneCodeHash: String, phoneCode: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { + public static func signIn(phoneNumber: String, phoneCodeHash: String, phoneCode: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { let buffer = Buffer() buffer.appendInt32(-1126886015) serializeString(phoneNumber, buffer: buffer, boxed: false) @@ -21988,7 +22090,7 @@ public struct Api { }) } - public static func sendInvites(phoneNumbers phoneNumbers: [String], message: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func sendInvites(phoneNumbers: [String], message: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(1998331287) buffer.appendInt32(481674261) @@ -22007,7 +22109,7 @@ public struct Api { }) } - public static func exportAuthorization(dcId dcId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.ExportedAuthorization?) { + public static func exportAuthorization(dcId: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.ExportedAuthorization?) { let buffer = Buffer() buffer.appendInt32(-440401971) serializeInt32(dcId, buffer: buffer, boxed: false) @@ -22021,7 +22123,7 @@ public struct Api { }) } - public static func importAuthorization(id id: Int32, bytes: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { + public static func importAuthorization(id: Int32, bytes: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { let buffer = Buffer() buffer.appendInt32(-470837741) serializeInt32(id, buffer: buffer, boxed: false) @@ -22036,7 +22138,7 @@ public struct Api { }) } - public static func bindTempAuthKey(permAuthKeyId permAuthKeyId: Int64, nonce: Int64, expiresAt: Int32, encryptedMessage: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func bindTempAuthKey(permAuthKeyId: Int64, nonce: Int64, expiresAt: Int32, encryptedMessage: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-841733627) serializeInt64(permAuthKeyId, buffer: buffer, boxed: false) @@ -22053,7 +22155,7 @@ public struct Api { }) } - public static func importBotAuthorization(flags flags: Int32, apiId: Int32, apiHash: String, botAuthToken: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { + public static func importBotAuthorization(flags: Int32, apiId: Int32, apiHash: String, botAuthToken: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { let buffer = Buffer() buffer.appendInt32(1738800940) serializeInt32(flags, buffer: buffer, boxed: false) @@ -22070,7 +22172,7 @@ public struct Api { }) } - public static func checkPassword(passwordHash passwordHash: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { + public static func checkPassword(passwordHash: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { let buffer = Buffer() buffer.appendInt32(174260510) serializeBytes(passwordHash, buffer: buffer, boxed: false) @@ -22098,7 +22200,7 @@ public struct Api { }) } - public static func recoverPassword(code code: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { + public static func recoverPassword(code: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.Authorization?) { let buffer = Buffer() buffer.appendInt32(1319464594) serializeString(code, buffer: buffer, boxed: false) @@ -22112,7 +22214,7 @@ public struct Api { }) } - public static func resendCode(phoneNumber phoneNumber: String, phoneCodeHash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.SentCode?) { + public static func resendCode(phoneNumber: String, phoneCodeHash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.SentCode?) { let buffer = Buffer() buffer.appendInt32(1056025023) serializeString(phoneNumber, buffer: buffer, boxed: false) @@ -22127,7 +22229,7 @@ public struct Api { }) } - public static func cancelCode(phoneNumber phoneNumber: String, phoneCodeHash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func cancelCode(phoneNumber: String, phoneCodeHash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(520357240) serializeString(phoneNumber, buffer: buffer, boxed: false) @@ -22142,7 +22244,7 @@ public struct Api { }) } - public static func dropTempAuthKeys(exceptAuthKeys exceptAuthKeys: [Int64]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func dropTempAuthKeys(exceptAuthKeys: [Int64]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-1907842680) buffer.appendInt32(481674261) @@ -22161,7 +22263,7 @@ public struct Api { } } public struct bots { - public static func sendCustomRequest(customMethod customMethod: String, params: Api.DataJSON) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.DataJSON?) { + public static func sendCustomRequest(customMethod: String, params: Api.DataJSON) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.DataJSON?) { let buffer = Buffer() buffer.appendInt32(-1440257555) serializeString(customMethod, buffer: buffer, boxed: false) @@ -22176,7 +22278,7 @@ public struct Api { }) } - public static func answerWebhookJSONQuery(queryId queryId: Int64, data: Api.DataJSON) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func answerWebhookJSONQuery(queryId: Int64, data: Api.DataJSON) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-434028723) serializeInt64(queryId, buffer: buffer, boxed: false) @@ -22192,7 +22294,7 @@ public struct Api { } } public struct users { - public static func getUsers(id id: [Api.InputUser]) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.User]?) { + public static func getUsers(id: [Api.InputUser]) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.User]?) { let buffer = Buffer() buffer.appendInt32(227648840) buffer.appendInt32(481674261) @@ -22210,7 +22312,7 @@ public struct Api { }) } - public static func getFullUser(id id: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.UserFull?) { + public static func getFullUser(id: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.UserFull?) { let buffer = Buffer() buffer.appendInt32(-902781519) id.serialize(buffer, true) @@ -22239,7 +22341,7 @@ public struct Api { }) } - public static func getContacts(hash hash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.Contacts?) { + public static func getContacts(hash: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.Contacts?) { let buffer = Buffer() buffer.appendInt32(583445000) serializeString(hash, buffer: buffer, boxed: false) @@ -22253,7 +22355,7 @@ public struct Api { }) } - public static func importContacts(contacts contacts: [Api.InputContact], replace: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.ImportedContacts?) { + public static func importContacts(contacts: [Api.InputContact], replace: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.ImportedContacts?) { let buffer = Buffer() buffer.appendInt32(-634342611) buffer.appendInt32(481674261) @@ -22272,7 +22374,7 @@ public struct Api { }) } - public static func deleteContact(id id: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.Link?) { + public static func deleteContact(id: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.Link?) { let buffer = Buffer() buffer.appendInt32(-1902823612) id.serialize(buffer, true) @@ -22286,7 +22388,7 @@ public struct Api { }) } - public static func deleteContacts(id id: [Api.InputUser]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func deleteContacts(id: [Api.InputUser]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(1504393374) buffer.appendInt32(481674261) @@ -22304,7 +22406,7 @@ public struct Api { }) } - public static func block(id id: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func block(id: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(858475004) id.serialize(buffer, true) @@ -22318,7 +22420,7 @@ public struct Api { }) } - public static func unblock(id id: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func unblock(id: Api.InputUser) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-448724803) id.serialize(buffer, true) @@ -22332,7 +22434,7 @@ public struct Api { }) } - public static func getBlocked(offset offset: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.Blocked?) { + public static func getBlocked(offset: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.Blocked?) { let buffer = Buffer() buffer.appendInt32(-176409329) serializeInt32(offset, buffer: buffer, boxed: false) @@ -22361,7 +22463,7 @@ public struct Api { }) } - public static func importCard(exportCard exportCard: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.User?) { + public static func importCard(exportCard: [Int32]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.User?) { let buffer = Buffer() buffer.appendInt32(1340184318) buffer.appendInt32(481674261) @@ -22379,7 +22481,7 @@ public struct Api { }) } - public static func search(q q: String, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.Found?) { + public static func search(q: String, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.Found?) { let buffer = Buffer() buffer.appendInt32(301470424) serializeString(q, buffer: buffer, boxed: false) @@ -22394,7 +22496,7 @@ public struct Api { }) } - public static func resolveUsername(username username: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.ResolvedPeer?) { + public static func resolveUsername(username: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.ResolvedPeer?) { let buffer = Buffer() buffer.appendInt32(-113456221) serializeString(username, buffer: buffer, boxed: false) @@ -22408,7 +22510,7 @@ public struct Api { }) } - public static func getTopPeers(flags flags: Int32, offset: Int32, limit: Int32, hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.TopPeers?) { + public static func getTopPeers(flags: Int32, offset: Int32, limit: Int32, hash: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.contacts.TopPeers?) { let buffer = Buffer() buffer.appendInt32(-728224331) serializeInt32(flags, buffer: buffer, boxed: false) @@ -22425,7 +22527,7 @@ public struct Api { }) } - public static func resetTopPeerRating(category category: Api.TopPeerCategory, peer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func resetTopPeerRating(category: Api.TopPeerCategory, peer: Api.InputPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(451113900) category.serialize(buffer, true) @@ -22483,7 +22585,7 @@ public struct Api { }) } - public static func saveAppLog(events events: [Api.InputAppEvent]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func saveAppLog(events: [Api.InputAppEvent]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(1862465352) buffer.appendInt32(481674261) @@ -22529,7 +22631,7 @@ public struct Api { }) } - public static func getAppChangelog(prevAppVersion prevAppVersion: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func getAppChangelog(prevAppVersion: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(-1877938321) serializeString(prevAppVersion, buffer: buffer, boxed: false) @@ -22557,7 +22659,7 @@ public struct Api { }) } - public static func setBotUpdatesStatus(pendingUpdatesCount pendingUpdatesCount: Int32, message: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func setBotUpdatesStatus(pendingUpdatesCount: Int32, message: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-333262899) serializeInt32(pendingUpdatesCount, buffer: buffer, boxed: false) @@ -22615,7 +22717,7 @@ public struct Api { }) } - public static func getDifference(flags flags: Int32, pts: Int32, ptsTotalLimit: Int32?, date: Int32, qts: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.updates.Difference?) { + public static func getDifference(flags: Int32, pts: Int32, ptsTotalLimit: Int32?, date: Int32, qts: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.updates.Difference?) { let buffer = Buffer() buffer.appendInt32(630429265) serializeInt32(flags, buffer: buffer, boxed: false) @@ -22633,7 +22735,7 @@ public struct Api { }) } - public static func getChannelDifference(flags flags: Int32, channel: Api.InputChannel, filter: Api.ChannelMessagesFilter, pts: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.updates.ChannelDifference?) { + public static func getChannelDifference(flags: Int32, channel: Api.InputChannel, filter: Api.ChannelMessagesFilter, pts: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.updates.ChannelDifference?) { let buffer = Buffer() buffer.appendInt32(51854712) serializeInt32(flags, buffer: buffer, boxed: false) @@ -22652,7 +22754,7 @@ public struct Api { } } public struct upload { - public static func saveFilePart(fileId fileId: Int64, filePart: Int32, bytes: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func saveFilePart(fileId: Int64, filePart: Int32, bytes: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-1291540959) serializeInt64(fileId, buffer: buffer, boxed: false) @@ -22668,7 +22770,7 @@ public struct Api { }) } - public static func getFile(location location: Api.InputFileLocation, offset: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.upload.File?) { + public static func getFile(location: Api.InputFileLocation, offset: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.upload.File?) { let buffer = Buffer() buffer.appendInt32(-475607115) location.serialize(buffer, true) @@ -22684,7 +22786,7 @@ public struct Api { }) } - public static func saveBigFilePart(fileId fileId: Int64, filePart: Int32, fileTotalParts: Int32, bytes: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func saveBigFilePart(fileId: Int64, filePart: Int32, fileTotalParts: Int32, bytes: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-562337987) serializeInt64(fileId, buffer: buffer, boxed: false) @@ -22701,7 +22803,7 @@ public struct Api { }) } - public static func getWebFile(location location: Api.InputWebFileLocation, offset: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.upload.WebFile?) { + public static func getWebFile(location: Api.InputWebFileLocation, offset: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.upload.WebFile?) { let buffer = Buffer() buffer.appendInt32(619086221) location.serialize(buffer, true) @@ -22717,7 +22819,7 @@ public struct Api { }) } - public static func getCdnFile(fileToken fileToken: Buffer, offset: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.upload.CdnFile?) { + public static func getCdnFile(fileToken: Buffer, offset: Int32, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.upload.CdnFile?) { let buffer = Buffer() buffer.appendInt32(536919235) serializeBytes(fileToken, buffer: buffer, boxed: false) @@ -22733,7 +22835,7 @@ public struct Api { }) } - public static func reuploadCdnFile(fileToken fileToken: Buffer, requestToken: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func reuploadCdnFile(fileToken: Buffer, requestToken: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(779755552) serializeBytes(fileToken, buffer: buffer, boxed: false) @@ -22747,9 +22849,24 @@ public struct Api { return result }) } + + public static func getCdnFileHashes(fileToken: Buffer, offset: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.CdnFileHash]?) { + let buffer = Buffer() + buffer.appendInt32(-149567365) + serializeBytes(fileToken, buffer: buffer, boxed: false) + serializeInt32(offset, buffer: buffer, boxed: false) + return (FunctionDescription({return "(upload.getCdnFileHashes fileToken: \(fileToken), offset: \(offset))"}), buffer, { (buffer: Buffer) -> [Api.CdnFileHash]? in + let reader = BufferReader(buffer) + var result: [Api.CdnFileHash]? + if let _ = reader.readInt32() { + result = Api.parseVector(reader, elementSignature: 0, elementType: Api.CdnFileHash.self) + } + return result + }) + } } public struct account { - public static func registerDevice(tokenType tokenType: Int32, token: String, deviceModel: String, systemVersion: String, appVersion: String, appSandbox: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func registerDevice(tokenType: Int32, token: String, deviceModel: String, systemVersion: String, appVersion: String, appSandbox: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-1568319572) serializeInt32(tokenType, buffer: buffer, boxed: false) @@ -22768,7 +22885,7 @@ public struct Api { }) } - public static func unregisterDevice(tokenType tokenType: Int32, token: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func unregisterDevice(tokenType: Int32, token: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(1707432768) serializeInt32(tokenType, buffer: buffer, boxed: false) @@ -22783,7 +22900,7 @@ public struct Api { }) } - public static func updateNotifySettings(peer peer: Api.InputNotifyPeer, settings: Api.InputPeerNotifySettings) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func updateNotifySettings(peer: Api.InputNotifyPeer, settings: Api.InputPeerNotifySettings) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-2067899501) peer.serialize(buffer, true) @@ -22798,7 +22915,7 @@ public struct Api { }) } - public static func getNotifySettings(peer peer: Api.InputNotifyPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.PeerNotifySettings?) { + public static func getNotifySettings(peer: Api.InputNotifyPeer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.PeerNotifySettings?) { let buffer = Buffer() buffer.appendInt32(313765169) peer.serialize(buffer, true) @@ -22826,7 +22943,7 @@ public struct Api { }) } - public static func updateProfile(flags flags: Int32, firstName: String?, lastName: String?, about: String?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.User?) { + public static func updateProfile(flags: Int32, firstName: String?, lastName: String?, about: String?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.User?) { let buffer = Buffer() buffer.appendInt32(2018596725) serializeInt32(flags, buffer: buffer, boxed: false) @@ -22843,7 +22960,7 @@ public struct Api { }) } - public static func updateStatus(offline offline: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func updateStatus(offline: Api.Bool) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(1713919532) offline.serialize(buffer, true) @@ -22871,7 +22988,7 @@ public struct Api { }) } - public static func reportPeer(peer peer: Api.InputPeer, reason: Api.ReportReason) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func reportPeer(peer: Api.InputPeer, reason: Api.ReportReason) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-1374118561) peer.serialize(buffer, true) @@ -22886,7 +23003,7 @@ public struct Api { }) } - public static func checkUsername(username username: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func checkUsername(username: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(655677548) serializeString(username, buffer: buffer, boxed: false) @@ -22900,7 +23017,7 @@ public struct Api { }) } - public static func updateUsername(username username: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.User?) { + public static func updateUsername(username: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.User?) { let buffer = Buffer() buffer.appendInt32(1040964988) serializeString(username, buffer: buffer, boxed: false) @@ -22914,7 +23031,7 @@ public struct Api { }) } - public static func getPrivacy(key key: Api.InputPrivacyKey) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.account.PrivacyRules?) { + public static func getPrivacy(key: Api.InputPrivacyKey) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.account.PrivacyRules?) { let buffer = Buffer() buffer.appendInt32(-623130288) key.serialize(buffer, true) @@ -22928,7 +23045,7 @@ public struct Api { }) } - public static func setPrivacy(key key: Api.InputPrivacyKey, rules: [Api.InputPrivacyRule]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.account.PrivacyRules?) { + public static func setPrivacy(key: Api.InputPrivacyKey, rules: [Api.InputPrivacyRule]) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.account.PrivacyRules?) { let buffer = Buffer() buffer.appendInt32(-906486552) key.serialize(buffer, true) @@ -22947,7 +23064,7 @@ public struct Api { }) } - public static func deleteAccount(reason reason: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func deleteAccount(reason: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(1099779595) serializeString(reason, buffer: buffer, boxed: false) @@ -22975,7 +23092,7 @@ public struct Api { }) } - public static func setAccountTTL(ttl ttl: Api.AccountDaysTTL) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func setAccountTTL(ttl: Api.AccountDaysTTL) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(608323678) ttl.serialize(buffer, true) @@ -22989,7 +23106,7 @@ public struct Api { }) } - public static func sendChangePhoneCode(flags flags: Int32, phoneNumber: String, currentNumber: Api.Bool?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.SentCode?) { + public static func sendChangePhoneCode(flags: Int32, phoneNumber: String, currentNumber: Api.Bool?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.SentCode?) { let buffer = Buffer() buffer.appendInt32(149257707) serializeInt32(flags, buffer: buffer, boxed: false) @@ -23005,7 +23122,7 @@ public struct Api { }) } - public static func changePhone(phoneNumber phoneNumber: String, phoneCodeHash: String, phoneCode: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.User?) { + public static func changePhone(phoneNumber: String, phoneCodeHash: String, phoneCode: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.User?) { let buffer = Buffer() buffer.appendInt32(1891839707) serializeString(phoneNumber, buffer: buffer, boxed: false) @@ -23021,7 +23138,7 @@ public struct Api { }) } - public static func updateDeviceLocked(period period: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func updateDeviceLocked(period: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(954152242) serializeInt32(period, buffer: buffer, boxed: false) @@ -23049,7 +23166,7 @@ public struct Api { }) } - public static func resetAuthorization(hash hash: Int64) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func resetAuthorization(hash: Int64) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-545786948) serializeInt64(hash, buffer: buffer, boxed: false) @@ -23077,7 +23194,7 @@ public struct Api { }) } - public static func getPasswordSettings(currentPasswordHash currentPasswordHash: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.account.PasswordSettings?) { + public static func getPasswordSettings(currentPasswordHash: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.account.PasswordSettings?) { let buffer = Buffer() buffer.appendInt32(-1131605573) serializeBytes(currentPasswordHash, buffer: buffer, boxed: false) @@ -23091,7 +23208,7 @@ public struct Api { }) } - public static func updatePasswordSettings(currentPasswordHash currentPasswordHash: Buffer, newSettings: Api.account.PasswordInputSettings) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func updatePasswordSettings(currentPasswordHash: Buffer, newSettings: Api.account.PasswordInputSettings) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(-92517498) serializeBytes(currentPasswordHash, buffer: buffer, boxed: false) @@ -23106,7 +23223,7 @@ public struct Api { }) } - public static func sendConfirmPhoneCode(flags flags: Int32, hash: String, currentNumber: Api.Bool?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.SentCode?) { + public static func sendConfirmPhoneCode(flags: Int32, hash: String, currentNumber: Api.Bool?) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.auth.SentCode?) { let buffer = Buffer() buffer.appendInt32(353818557) serializeInt32(flags, buffer: buffer, boxed: false) @@ -23122,7 +23239,7 @@ public struct Api { }) } - public static func confirmPhone(phoneCodeHash phoneCodeHash: String, phoneCode: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func confirmPhone(phoneCodeHash: String, phoneCode: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(1596029123) serializeString(phoneCodeHash, buffer: buffer, boxed: false) @@ -23137,7 +23254,7 @@ public struct Api { }) } - public static func getTmpPassword(passwordHash passwordHash: Buffer, period: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.account.TmpPassword?) { + public static func getTmpPassword(passwordHash: Buffer, period: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.account.TmpPassword?) { let buffer = Buffer() buffer.appendInt32(1250046590) serializeBytes(passwordHash, buffer: buffer, boxed: false) @@ -23153,7 +23270,7 @@ public struct Api { } } public struct langpack { - public static func getLangPack(langCode langCode: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.LangPackDifference?) { + public static func getLangPack(langCode: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.LangPackDifference?) { let buffer = Buffer() buffer.appendInt32(-1699363442) serializeString(langCode, buffer: buffer, boxed: false) @@ -23167,7 +23284,7 @@ public struct Api { }) } - public static func getStrings(langCode langCode: String, keys: [String]) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.LangPackString]?) { + public static func getStrings(langCode: String, keys: [String]) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.LangPackString]?) { let buffer = Buffer() buffer.appendInt32(773776152) serializeString(langCode, buffer: buffer, boxed: false) @@ -23186,7 +23303,7 @@ public struct Api { }) } - public static func getDifference(fromVersion fromVersion: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.LangPackDifference?) { + public static func getDifference(fromVersion: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.LangPackDifference?) { let buffer = Buffer() buffer.appendInt32(187583869) serializeInt32(fromVersion, buffer: buffer, boxed: false) @@ -23215,7 +23332,7 @@ public struct Api { } } public struct photos { - public static func updateProfilePhoto(id id: Api.InputPhoto) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.UserProfilePhoto?) { + public static func updateProfilePhoto(id: Api.InputPhoto) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.UserProfilePhoto?) { let buffer = Buffer() buffer.appendInt32(-256159406) id.serialize(buffer, true) @@ -23229,7 +23346,7 @@ public struct Api { }) } - public static func uploadProfilePhoto(file file: Api.InputFile) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.photos.Photo?) { + public static func uploadProfilePhoto(file: Api.InputFile) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.photos.Photo?) { let buffer = Buffer() buffer.appendInt32(1328726168) file.serialize(buffer, true) @@ -23243,7 +23360,7 @@ public struct Api { }) } - public static func deletePhotos(id id: [Api.InputPhoto]) -> (CustomStringConvertible, Buffer, (Buffer) -> [Int64]?) { + public static func deletePhotos(id: [Api.InputPhoto]) -> (CustomStringConvertible, Buffer, (Buffer) -> [Int64]?) { let buffer = Buffer() buffer.appendInt32(-2016444625) buffer.appendInt32(481674261) @@ -23261,7 +23378,7 @@ public struct Api { }) } - public static func getUserPhotos(userId userId: Api.InputUser, offset: Int32, maxId: Int64, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.photos.Photos?) { + public static func getUserPhotos(userId: Api.InputUser, offset: Int32, maxId: Int64, limit: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.photos.Photos?) { let buffer = Buffer() buffer.appendInt32(-1848823128) userId.serialize(buffer, true) @@ -23293,7 +23410,7 @@ public struct Api { }) } - public static func requestCall(userId userId: Api.InputUser, randomId: Int32, gAHash: Buffer, `protocol`: Api.PhoneCallProtocol) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.phone.PhoneCall?) { + public static func requestCall(userId: Api.InputUser, randomId: Int32, gAHash: Buffer, `protocol`: Api.PhoneCallProtocol) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.phone.PhoneCall?) { let buffer = Buffer() buffer.appendInt32(1536537556) userId.serialize(buffer, true) @@ -23310,7 +23427,7 @@ public struct Api { }) } - public static func acceptCall(peer peer: Api.InputPhoneCall, gB: Buffer, `protocol`: Api.PhoneCallProtocol) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.phone.PhoneCall?) { + public static func acceptCall(peer: Api.InputPhoneCall, gB: Buffer, `protocol`: Api.PhoneCallProtocol) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.phone.PhoneCall?) { let buffer = Buffer() buffer.appendInt32(1003664544) peer.serialize(buffer, true) @@ -23326,7 +23443,7 @@ public struct Api { }) } - public static func confirmCall(peer peer: Api.InputPhoneCall, gA: Buffer, keyFingerprint: Int64, `protocol`: Api.PhoneCallProtocol) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.phone.PhoneCall?) { + public static func confirmCall(peer: Api.InputPhoneCall, gA: Buffer, keyFingerprint: Int64, `protocol`: Api.PhoneCallProtocol) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.phone.PhoneCall?) { let buffer = Buffer() buffer.appendInt32(788404002) peer.serialize(buffer, true) @@ -23343,7 +23460,7 @@ public struct Api { }) } - public static func receivedCall(peer peer: Api.InputPhoneCall) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func receivedCall(peer: Api.InputPhoneCall) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(399855457) peer.serialize(buffer, true) @@ -23357,7 +23474,7 @@ public struct Api { }) } - public static func discardCall(peer peer: Api.InputPhoneCall, duration: Int32, reason: Api.PhoneCallDiscardReason, connectionId: Int64) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func discardCall(peer: Api.InputPhoneCall, duration: Int32, reason: Api.PhoneCallDiscardReason, connectionId: Int64) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(2027164582) peer.serialize(buffer, true) @@ -23374,7 +23491,7 @@ public struct Api { }) } - public static func setCallRating(peer peer: Api.InputPhoneCall, rating: Int32, comment: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { + public static func setCallRating(peer: Api.InputPhoneCall, rating: Int32, comment: String) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Updates?) { let buffer = Buffer() buffer.appendInt32(475228724) peer.serialize(buffer, true) @@ -23390,7 +23507,7 @@ public struct Api { }) } - public static func saveCallDebug(peer peer: Api.InputPhoneCall, debug: Api.DataJSON) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { + public static func saveCallDebug(peer: Api.InputPhoneCall, debug: Api.DataJSON) -> (CustomStringConvertible, Buffer, (Buffer) -> Api.Bool?) { let buffer = Buffer() buffer.appendInt32(662363518) peer.serialize(buffer, true) diff --git a/TelegramCore/ApplyMaxReadIndexInteractively.swift b/TelegramCore/ApplyMaxReadIndexInteractively.swift index d82f2aa07b..c216cba397 100644 --- a/TelegramCore/ApplyMaxReadIndexInteractively.swift +++ b/TelegramCore/ApplyMaxReadIndexInteractively.swift @@ -20,7 +20,7 @@ public func applyMaxReadIndexInteractively(postbox: Postbox, network: Network, i modifier.updateMessage(message.id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } let updatedAttributes = currentMessage.attributes.map({ currentAttribute -> MessageAttribute in if let currentAttribute = currentAttribute as? AutoremoveTimeoutMessageAttribute { @@ -53,7 +53,7 @@ func applyOutgoingReadMaxIndex(modifier: Modifier, index: MessageIndex, beginAt modifier.updateMessage(message.id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } let updatedAttributes = currentMessage.attributes.map({ currentAttribute -> MessageAttribute in if let currentAttribute = currentAttribute as? AutoremoveTimeoutMessageAttribute { diff --git a/TelegramCore/ApplyUpdateMessage.swift b/TelegramCore/ApplyUpdateMessage.swift index 13171c5880..5a421ce4d7 100644 --- a/TelegramCore/ApplyUpdateMessage.swift +++ b/TelegramCore/ApplyUpdateMessage.swift @@ -33,7 +33,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes var updatedTimestamp: Int32? if let apiMessage = apiMessage { switch apiMessage { - case let .message(_, _, _, _, _, _, _, date, _, _, _, _, _, _): + case let .message(_, _, _, _, _, _, _, date, _, _, _, _, _, _, _): updatedTimestamp = date case .messageEmpty: break @@ -68,7 +68,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes attributes = updatedMessage.attributes text = updatedMessage.text } else if case let .updateShortSentMessage(_, _, _, _, _, apiMedia, entities) = result { - let (_, mediaValue) = textAndMediaFromApiMedia(apiMedia, currentMessage.id.peerId) + let (_, mediaValue, _) = textMediaAndExpirationTimerFromApiMedia(apiMedia, currentMessage.id.peerId) if let mediaValue = mediaValue { media = [mediaValue] } else { @@ -85,6 +85,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes } updatedAttributes.append(TextEntitiesMessageAttribute(entities: messageTextEntitiesFromApiEntities(entities))) } + attributes = updatedAttributes text = currentMessage.text } else { @@ -95,7 +96,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } if let fromMedia = currentMessage.media.first, let toMedia = media.first { diff --git a/TelegramCore/AuthorSignatureMessageAttribute.swift b/TelegramCore/AuthorSignatureMessageAttribute.swift new file mode 100644 index 0000000000..81ee82f2a2 --- /dev/null +++ b/TelegramCore/AuthorSignatureMessageAttribute.swift @@ -0,0 +1,24 @@ +import Foundation +#if os(macOS) + import PostboxMac +#else + import Postbox +#endif + +public class AuthorSignatureMessageAttribute: MessageAttribute { + public let signature: String + + public let associatedPeerIds: [PeerId] = [] + + init(signature: String) { + self.signature = signature + } + + required public init(decoder: Decoder) { + self.signature = decoder.decodeStringForKey("s", orElse: "") + } + + public func encode(_ encoder: Encoder) { + encoder.encodeString(self.signature, forKey: "s") + } +} diff --git a/TelegramCore/BotPaymentForm.swift b/TelegramCore/BotPaymentForm.swift index ca8369e272..3a6b696ecf 100644 --- a/TelegramCore/BotPaymentForm.swift +++ b/TelegramCore/BotPaymentForm.swift @@ -119,8 +119,19 @@ public struct BotPaymentRequestedInfo: Equatable { } } -public enum BotPaymentSavedCredentials { +public enum BotPaymentSavedCredentials: Equatable { case card(id: String, title: String) + + public static func ==(lhs: BotPaymentSavedCredentials, rhs: BotPaymentSavedCredentials) -> Bool { + switch lhs { + case let .card(id, title): + if case .card(id, title) = rhs { + return true + } else { + return false + } + } + } } public struct BotPaymentForm { @@ -138,75 +149,101 @@ public enum BotPaymentFormRequestError { case generic } +extension BotPaymentInvoice { + init(apiInvoice: Api.Invoice) { + switch apiInvoice { + case let .invoice(flags, currency, prices): + var fields = BotPaymentInvoiceFields() + if (flags & (1 << 1)) != 0 { + fields.insert(.name) + } + if (flags & (1 << 2)) != 0 { + fields.insert(.phone) + } + if (flags & (1 << 3)) != 0 { + fields.insert(.email) + } + if (flags & (1 << 4)) != 0 { + fields.insert(.shippingAddress) + } + if (flags & (1 << 5)) != 0 { + fields.insert(.flexibleShipping) + } + self.init(isTest: (flags & (1 << 0)) != 0, requestedFields: fields, currency: currency, prices: prices.map { + switch $0 { + case let .labeledPrice(label, amount): + return BotPaymentPrice(label: label, amount: amount) + } + }) + } + } +} + +extension BotPaymentRequestedInfo { + init(apiInfo: Api.PaymentRequestedInfo) { + switch apiInfo { + case let .paymentRequestedInfo(_, name, phone, email, shippingAddress): + var parsedShippingAddress: BotPaymentShippingAddress? + if let shippingAddress = shippingAddress { + switch shippingAddress { + case let .postAddress(streetLine1, streetLine2, city, state, countryIso2, postCode): + parsedShippingAddress = BotPaymentShippingAddress(streetLine1: streetLine1, streetLine2: streetLine2, city: city, state: state, countryIso2: countryIso2, postCode: postCode) + } + } + self.init(name: name, phone: phone, email: email, shippingAddress: parsedShippingAddress) + } + } +} + public func fetchBotPaymentForm(postbox: Postbox, network: Network, messageId: MessageId) -> Signal { return network.request(Api.functions.payments.getPaymentForm(msgId: messageId.id)) |> `catch` { _ -> Signal in return .fail(.generic) } - |> map { result -> BotPaymentForm in - switch result { - case let .paymentForm(flags, _, invoice, providerId, url, nativeProvider, nativeParams, savedInfo, savedCredentials, _): - let parsedInvoice: BotPaymentInvoice - switch invoice { - case let .invoice(flags, currency, prices): - var fields = BotPaymentInvoiceFields() - if (flags & (1 << 1)) != 0 { - fields.insert(.name) - } - if (flags & (1 << 2)) != 0 { - fields.insert(.phone) - } - if (flags & (1 << 3)) != 0 { - fields.insert(.email) - } - if (flags & (1 << 4)) != 0 { - fields.insert(.shippingAddress) - } - if (flags & (1 << 5)) != 0 { - fields.insert(.flexibleShipping) - } - parsedInvoice = BotPaymentInvoice(isTest: (flags & (1 << 0)) != 0, requestedFields: fields, currency: currency, prices: prices.map { - switch $0 { - case let .labeledPrice(label, amount): - return BotPaymentPrice(label: label, amount: amount) - } - }) - } - var parsedNativeProvider: BotPaymentNativeProvider? - if let nativeProvider = nativeProvider, let nativeParams = nativeParams { - switch nativeParams { - case let .dataJSON(data): - parsedNativeProvider = BotPaymentNativeProvider(name: nativeProvider, params: data) + |> mapToSignal { result -> Signal in + return postbox.modify { modifier -> BotPaymentForm in + switch result { + case let .paymentForm(flags, _, invoice, providerId, url, nativeProvider, nativeParams, savedInfo, savedCredentials, apiUsers): + var peers: [Peer] = [] + for user in apiUsers { + let parsed = TelegramUser(user: user) + peers.append(parsed) } - } - var parsedSavedInfo: BotPaymentRequestedInfo? - if let savedInfo = savedInfo { - switch savedInfo { - case let .paymentRequestedInfo(_, name, phone, email, shippingAddress): - var parsedShippingAddress: BotPaymentShippingAddress? - if let shippingAddress = shippingAddress { - switch shippingAddress { - case let .postAddress(streetLine1, streetLine2, city, state, countryIso2, postCode): - parsedShippingAddress = BotPaymentShippingAddress(streetLine1: streetLine1, streetLine2: streetLine2, city: city, state: state, countryIso2: countryIso2, postCode: postCode) - } - } - parsedSavedInfo = BotPaymentRequestedInfo(name: name, phone: phone, email: email, shippingAddress: parsedShippingAddress) + updatePeers(modifier: modifier, peers: peers, update: { _, updated in + return updated + }) + + let parsedInvoice = BotPaymentInvoice(apiInvoice: invoice) + var parsedNativeProvider: BotPaymentNativeProvider? + if let nativeProvider = nativeProvider, let nativeParams = nativeParams { + switch nativeParams { + case let .dataJSON(data): + parsedNativeProvider = BotPaymentNativeProvider(name: nativeProvider, params: data) + } } - } - var parsedSavedCredentials: BotPaymentSavedCredentials? - if let savedCredentials = savedCredentials { - switch savedCredentials { - case let .paymentSavedCredentialsCard(id, title): - parsedSavedCredentials = .card(id: id, title: title) + let parsedSavedInfo = savedInfo.flatMap(BotPaymentRequestedInfo.init) + var parsedSavedCredentials: BotPaymentSavedCredentials? + if let savedCredentials = savedCredentials { + switch savedCredentials { + case let .paymentSavedCredentialsCard(id, title): + parsedSavedCredentials = .card(id: id, title: title) + } } - } - return BotPaymentForm(canSaveCredentials: (flags & (1 << 2)) != 0, passwordMissing: (flags & (1 << 3)) != 0, invoice: parsedInvoice, providerId: providerId, url: url, nativeProvider: parsedNativeProvider, savedInfo: parsedSavedInfo, savedCredentials: parsedSavedCredentials) - } + return BotPaymentForm(canSaveCredentials: (flags & (1 << 2)) != 0, passwordMissing: (flags & (1 << 3)) != 0, invoice: parsedInvoice, providerId: providerId, url: url, nativeProvider: parsedNativeProvider, savedInfo: parsedSavedInfo, savedCredentials: parsedSavedCredentials) + } + } |> mapError { _ -> BotPaymentFormRequestError in return .generic } } } public enum ValidateBotPaymentFormError { case generic + case shippingNotAvailable + case addressStateInvalid + case addressPostcodeInvalid + case addressCityInvalid + case nameInvalid + case emailInvalid + case phoneInvalid } public struct BotPaymentShippingOption { @@ -220,6 +257,20 @@ public struct BotPaymentValidatedFormInfo { public let shippingOptions: [BotPaymentShippingOption]? } +extension BotPaymentShippingOption { + init(apiOption: Api.ShippingOption) { + switch apiOption { + case let .shippingOption(id, title, prices): + self.init(id: id, title: title, prices: prices.map { + switch $0 { + case let .labeledPrice(label, amount): + return BotPaymentPrice(label: label, amount: amount) + } + }) + } + } +} + public func validateBotPaymentForm(network: Network, saveInfo: Bool, messageId: MessageId, formInfo: BotPaymentRequestedInfo) -> Signal { var flags: Int32 = 0 if saveInfo { @@ -242,23 +293,29 @@ public func validateBotPaymentForm(network: Network, saveInfo: Bool, messageId: } return network.request(Api.functions.payments.validateRequestedInfo(flags: flags, msgId: messageId.id, info: .paymentRequestedInfo(flags: infoFlags, name: formInfo.name, phone: formInfo.phone, email: formInfo.email, shippingAddress: apiShippingAddress))) |> mapError { error -> ValidateBotPaymentFormError in - return .generic + if error.errorDescription == "SHIPPING_NOT_AVAILABLE" { + return .shippingNotAvailable + } else if error.errorDescription == "ADDRESS_STATE_INVALID" { + return .addressStateInvalid + } else if error.errorDescription == "ADDRESS_POSTCODE_INVALID" { + return .addressPostcodeInvalid + } else if error.errorDescription == "ADDRESS_CITY_INVALID" { + return .addressCityInvalid + } else if error.errorDescription == "REQ_INFO_NAME_INVALID" { + return .nameInvalid + } else if error.errorDescription == "REQ_INFO_EMAIL_INVALID" { + return .emailInvalid + } else if error.errorDescription == "REQ_INFO_PHONE_INVALID" { + return .phoneInvalid + } else { + return .generic + } } |> map { result -> BotPaymentValidatedFormInfo in switch result { case let .validatedRequestedInfo(_, id, shippingOptions): return BotPaymentValidatedFormInfo(id: id, shippingOptions: shippingOptions.flatMap { - return $0.map { - switch $0 { - case let .shippingOption(id, title, prices): - return BotPaymentShippingOption(id: id, title: title, prices: prices.map { - switch $0 { - case let .labeledPrice(label, amount): - return BotPaymentPrice(label: label, amount: amount) - } - }) - } - } + return $0.map(BotPaymentShippingOption.init) }) } } @@ -271,6 +328,9 @@ public enum BotPaymentCredentials { public enum SendBotPaymentFormError { case generic + case precheckoutFailed + case paymentFailed + case alreadyPaid } public enum SendBotPaymentResult { @@ -307,7 +367,35 @@ public func sendBotPaymentForm(account: Account, messageId: MessageId, validated return .externalVerificationRequired(url: url) } } - |> `catch` { _ -> Signal in + |> `catch` { error -> Signal in + if error.errorDescription == "BOT_PRECHECKOUT_FAILED" { + return .fail(.precheckoutFailed) + } else if error.errorDescription == "PAYMENT_FAILED" { + return .fail(.paymentFailed) + } else if error.errorDescription == "INVOICE_ALREADY_PAID" { + return .fail(.alreadyPaid) + } return .fail(.generic) } } + +public struct BotPaymentReceipt { + public let invoice: BotPaymentInvoice + public let info: BotPaymentRequestedInfo? + public let shippingOption: BotPaymentShippingOption? + public let credentialsTitle: String +} + +public func requestBotPaymentReceipt(network: Network, messageId: MessageId) -> Signal { + return network.request(Api.functions.payments.getPaymentReceipt(msgId: messageId.id)) + |> retryRequest + |> map { result -> BotPaymentReceipt in + switch result { + case let .paymentReceipt(_, _, _, invoice, _, info, shipping, _, _, credentialsTitle, _): + let parsedInvoice = BotPaymentInvoice(apiInvoice: invoice) + let parsedInfo = info.flatMap(BotPaymentRequestedInfo.init) + let shippingOption = shipping.flatMap(BotPaymentShippingOption.init) + return BotPaymentReceipt(invoice: parsedInvoice, info: parsedInfo, shippingOption: shippingOption, credentialsTitle: credentialsTitle) + } + } +} diff --git a/TelegramCore/CallSessionManager.swift b/TelegramCore/CallSessionManager.swift index 9739bd6b91..eaa48510f3 100644 --- a/TelegramCore/CallSessionManager.swift +++ b/TelegramCore/CallSessionManager.swift @@ -326,6 +326,13 @@ private final class CallSessionManagerContext { } } + func dropAll() { + let contexts = self.contexts + for (internalId, context) in contexts { + self.drop(internalId: internalId, reason: .hangUp) + } + } + func accept(internalId: CallSessionInternalId) { if let context = self.contexts[internalId] { switch context.state { @@ -615,6 +622,12 @@ public final class CallSessionManager { } } + func dropAll() { + self.withContext { context in + context.dropAll() + } + } + public func accept(internalId: CallSessionInternalId) { self.withContext { context in context.accept(internalId: internalId) diff --git a/TelegramCore/CloudFileMediaResource.swift b/TelegramCore/CloudFileMediaResource.swift index 309b06f2f6..61fd10fef3 100644 --- a/TelegramCore/CloudFileMediaResource.swift +++ b/TelegramCore/CloudFileMediaResource.swift @@ -6,7 +6,6 @@ import Foundation #endif protocol TelegramCloudMediaResource: TelegramMediaResource { - var apiInputLocation: Api.InputFileLocation { get } } diff --git a/TelegramCore/ContactManagement.swift b/TelegramCore/ContactManagement.swift index 53dabbe6ab..fda49bad19 100644 --- a/TelegramCore/ContactManagement.swift +++ b/TelegramCore/ContactManagement.swift @@ -103,7 +103,7 @@ public func addContactPeerInteractively(account: Account, peerId: PeerId) -> Sig return account.postbox.modify { modifier -> Void in if let result = result { switch result { - case let .importedContacts(_, _, users): + case let .importedContacts(_, _, _, users): if let first = users.first { let user = TelegramUser(user: first) updatePeers(modifier: modifier, peers: [user], update: { _, updated in diff --git a/TelegramCore/Download.swift b/TelegramCore/Download.swift index 7895587fa8..0e31c7291c 100644 --- a/TelegramCore/Download.swift +++ b/TelegramCore/Download.swift @@ -24,16 +24,19 @@ private func roundUp(_ value: Int, to multiple: Int) -> Int { class Download: NSObject, MTRequestMessageServiceDelegate { let datacenterId: Int + let isCdn: Bool let context: MTContext let mtProto: MTProto let requestService: MTRequestMessageService - init(datacenterId: Int, context: MTContext, masterDatacenterId: Int, usageInfo: MTNetworkUsageCalculationInfo?) { + init(datacenterId: Int, isCdn: Bool, context: MTContext, masterDatacenterId: Int, usageInfo: MTNetworkUsageCalculationInfo?) { self.datacenterId = datacenterId + self.isCdn = isCdn self.context = context self.mtProto = MTProto(context: self.context, datacenterId: datacenterId, usageCalculationInfo: usageInfo) - if datacenterId != masterDatacenterId { + self.mtProto.cdn = isCdn + if !isCdn && datacenterId != masterDatacenterId { self.mtProto.authTokenMasterDatacenterId = masterDatacenterId self.mtProto.requiredAuthToken = Int(datacenterId) as NSNumber } @@ -93,7 +96,6 @@ class Download: NSObject, MTRequestMessageServiceDelegate { } |> retryRequest } - func webFilePart(location: Api.InputWebFileLocation, offset: Int, length: Int) -> Signal { return Signal { subscriber in let request = MTRequest() @@ -119,11 +121,9 @@ class Download: NSObject, MTRequestMessageServiceDelegate { subscriber.putError(error) } else { if let result = (boxedResponse as! BoxedMessage).body as? Api.upload.WebFile { - //upload.webFile#21e753bc size:int mime_type:string file_type:storage.FileType mtime:int bytes:bytes = upload.WebFile; - switch result { - case .webFile(_, _, _, _, let bytes): - subscriber.putNext(bytes.makeData()) + case .webFile(_, _, _, _, let bytes): + subscriber.putNext(bytes.makeData()) } subscriber.putCompletion() } @@ -140,7 +140,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate { return ActionDisposable { self.requestService.removeRequest(byInternalId: internalId) } - } |> retryRequest + } |> retryRequest } func part(location: Api.InputFileLocation, offset: Int, length: Int) -> Signal { @@ -171,7 +171,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate { switch result { case let .file(_, _, bytes): subscriber.putNext(bytes.makeData()) - case let .fileCdnRedirect(dcId, fileToken, encryptionKey, encryptionIv): + case .fileCdnRedirect: break } subscriber.putCompletion() @@ -224,8 +224,8 @@ class Download: NSObject, MTRequestMessageServiceDelegate { requestService.add(request) - return ActionDisposable { - self.requestService.removeRequest(byInternalId: internalId) + return ActionDisposable { [weak requestService] in + requestService?.removeRequest(byInternalId: internalId) } } } diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index 7fb6b595e6..776e4f2788 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -233,7 +233,7 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa attributes.append(contentsOf: filterMessageAttributesForForwardedMessage(sourceMessage.attributes)) let forwardInfo: StoreMessageForwardInfo? if let sourceForwardInfo = sourceMessage.forwardInfo { - forwardInfo = StoreMessageForwardInfo(authorId: sourceForwardInfo.author.id, sourceId: sourceForwardInfo.source?.id, sourceMessageId: sourceForwardInfo.sourceMessageId, date: sourceForwardInfo.date) + forwardInfo = StoreMessageForwardInfo(authorId: sourceForwardInfo.author.id, sourceId: sourceForwardInfo.source?.id, sourceMessageId: sourceForwardInfo.sourceMessageId, date: sourceForwardInfo.date, authorSignature: sourceForwardInfo.authorSignature) } else { if sourceMessage.id.peerId != account.peerId { var sourceId:PeerId? = nil @@ -242,7 +242,7 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa sourceId = peer.id sourceMessageId = sourceMessage.id } - forwardInfo = StoreMessageForwardInfo(authorId: author.id, sourceId: sourceId, sourceMessageId: sourceMessageId, date: sourceMessage.timestamp) + forwardInfo = StoreMessageForwardInfo(authorId: author.id, sourceId: sourceId, sourceMessageId: sourceMessageId, date: sourceMessage.timestamp, authorSignature: nil) } else { forwardInfo = nil } diff --git a/TelegramCore/HistoryViewChannelStateValidation.swift b/TelegramCore/HistoryViewChannelStateValidation.swift index 4b38d66aef..9e9664541f 100644 --- a/TelegramCore/HistoryViewChannelStateValidation.swift +++ b/TelegramCore/HistoryViewChannelStateValidation.swift @@ -170,7 +170,7 @@ private func validateBatch(postbox: Postbox, network: Network, messageIds: [Mess } } if let (minId, maxId) = currentRange { - ranges.append(Api.MessageRange.messageRange(minId: minId - 1, maxId: maxId + 1)) + ranges.append(Api.MessageRange.messageRange(minId: minId, maxId: maxId)) } return network.request(Api.functions.updates.getChannelDifference(flags: 0, channel: inputChannel, filter: .channelMessagesFilter(flags: 1 << 1, ranges: ranges), pts: minValidatedPts ?? 1, limit: 100)) |> `catch` { _ -> Signal in @@ -263,7 +263,7 @@ private func validateBatch(postbox: Postbox, network: Network, messageIds: [Mess modifier.updateMessage(messageId, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } var attributes = currentMessage.attributes for j in 0 ..< attributes.count { diff --git a/TelegramCore/ImportContact.swift b/TelegramCore/ImportContact.swift index 77ae965e6f..7032238e0f 100644 --- a/TelegramCore/ImportContact.swift +++ b/TelegramCore/ImportContact.swift @@ -19,7 +19,7 @@ public func importContact(account:Account, firstName:String, lastName:String, ph return account.postbox.modify { modifier -> PeerId? in if let result = result { switch result { - case let .importedContacts(_, _, users): + case let .importedContacts(_, _, _, users): if let first = users.first { let user = TelegramUser(user: first) let peerId = user.id diff --git a/TelegramCore/ManagedAutoremoveMessageOperations.swift b/TelegramCore/ManagedAutoremoveMessageOperations.swift index c9119ce574..bcfd00c01f 100644 --- a/TelegramCore/ManagedAutoremoveMessageOperations.swift +++ b/TelegramCore/ManagedAutoremoveMessageOperations.swift @@ -64,7 +64,27 @@ func managedAutoremoveMessageOperations(postbox: Postbox) -> Signal.complete() |> delay(max(0.0, Double(entry.timestamp) - timestamp), queue: Queue.concurrentDefaultQueue()) |> then(postbox.modify { modifier -> Void in - modifier.deleteMessages([entry.messageId]) + if let message = modifier.getMessage(entry.messageId) { + if message.id.namespace == Namespaces.Peer.SecretChat { + modifier.deleteMessages([entry.messageId]) + } else { + modifier.updateMessage(message.id, update: { currentMessage in + var storeForwardInfo: StoreMessageForwardInfo? + if let forwardInfo = currentMessage.forwardInfo { + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) + } + var updatedMedia = currentMessage.media + for i in 0 ..< updatedMedia.count { + if let _ = updatedMedia[i] as? TelegramMediaImage { + updatedMedia[i] = TelegramMediaExpiredContent(data: .image) + } else if let _ = updatedMedia[i] as? TelegramMediaFile { + updatedMedia[i] = TelegramMediaExpiredContent(data: .file) + } + } + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: updatedMedia)) + }) + } + } modifier.removeTimestampBasedMessageAttribute(tag: 0, messageId: entry.messageId) }) disposable.set(signal.start()) diff --git a/TelegramCore/ManagedDeviceContacts.swift b/TelegramCore/ManagedDeviceContacts.swift index e2136f1945..fb5715816a 100644 --- a/TelegramCore/ManagedDeviceContacts.swift +++ b/TelegramCore/ManagedDeviceContacts.swift @@ -240,7 +240,7 @@ private func applyAddedOrUpdatedContacts(network: Network, contacts: [ManagedDev } |> mapToSignal { result -> Signal<([Peer], [PeerId: PeerPresence], [ValueBoxKey: ManagedDeviceContactEntryContents]), ManagedDeviceContactsError> in switch result { - case let .importedContacts(imported, retryContacts, users): + case let .importedContacts(imported, _, retryContacts, users): var peers: [Peer] = [] var peerPresences: [PeerId: PeerPresence] = [:] var importedContents: [ValueBoxKey: ManagedDeviceContactEntryContents] = [:] diff --git a/TelegramCore/ManagedSecretChatOutgoingOperations.swift b/TelegramCore/ManagedSecretChatOutgoingOperations.swift index e0b5ce1bb8..22b7f4ccfe 100644 --- a/TelegramCore/ManagedSecretChatOutgoingOperations.swift +++ b/TelegramCore/ManagedSecretChatOutgoingOperations.swift @@ -716,7 +716,7 @@ private func sendMessage(postbox: Postbox, network: Network, messageId: MessageI } var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) @@ -762,7 +762,7 @@ private func sendServiceActionMessage(postbox: Postbox, network: Network, peerId } var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) diff --git a/TelegramCore/MarkMessageContentAsConsumedInteractively.swift b/TelegramCore/MarkMessageContentAsConsumedInteractively.swift index aeb1f98408..fbeff257bc 100644 --- a/TelegramCore/MarkMessageContentAsConsumedInteractively.swift +++ b/TelegramCore/MarkMessageContentAsConsumedInteractively.swift @@ -25,16 +25,16 @@ public func markMessageContentAsConsumedInteractively(postbox: Postbox, messageI } } - if messageId.peerId.namespace == Namespaces.Peer.SecretChat { - let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) - for i in 0 ..< updatedAttributes.count { - if let attribute = updatedAttributes[i] as? AutoremoveTimeoutMessageAttribute { - if (attribute.countdownBeginTime == nil || attribute.countdownBeginTime == 0) && message.containsSecretMedia { - updatedAttributes[i] = AutoremoveTimeoutMessageAttribute(timeout: attribute.timeout, countdownBeginTime: timestamp) - updateMessage = true - - modifier.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + attribute.timeout, messageId: messageId) - + let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) + for i in 0 ..< updatedAttributes.count { + if let attribute = updatedAttributes[i] as? AutoremoveTimeoutMessageAttribute { + if (attribute.countdownBeginTime == nil || attribute.countdownBeginTime == 0) && message.containsSecretMedia { + updatedAttributes[i] = AutoremoveTimeoutMessageAttribute(timeout: attribute.timeout, countdownBeginTime: timestamp) + updateMessage = true + + modifier.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + attribute.timeout, messageId: messageId) + + if messageId.peerId.namespace == Namespaces.Peer.SecretChat { var layer: SecretChatLayer? let state = modifier.getPeerChatState(message.id.peerId) as? SecretChatState if let state = state { @@ -55,8 +55,8 @@ public func markMessageContentAsConsumedInteractively(postbox: Postbox, messageI } } } - break } + break } } @@ -64,7 +64,7 @@ public func markMessageContentAsConsumedInteractively(postbox: Postbox, messageI modifier.updateMessage(message.id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags,forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) }) @@ -77,6 +77,7 @@ func markMessageContentAsConsumedRemotely(modifier: Modifier, messageId: Message if let message = modifier.getMessage(messageId) { var updateMessage = false var updatedAttributes = message.attributes + var updatedMedia = message.media for i in 0 ..< updatedAttributes.count { if let attribute = updatedAttributes[i] as? ConsumableContentMessageAttribute { @@ -88,17 +89,26 @@ func markMessageContentAsConsumedRemotely(modifier: Modifier, messageId: Message } } - if messageId.peerId.namespace == Namespaces.Peer.SecretChat { - let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) - for i in 0 ..< updatedAttributes.count { - if let attribute = updatedAttributes[i] as? AutoremoveTimeoutMessageAttribute { - if (attribute.countdownBeginTime == nil || attribute.countdownBeginTime == 0) && message.containsSecretMedia { - updatedAttributes[i] = AutoremoveTimeoutMessageAttribute(timeout: attribute.timeout, countdownBeginTime: timestamp) - updateMessage = true + let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) + for i in 0 ..< updatedAttributes.count { + if let attribute = updatedAttributes[i] as? AutoremoveTimeoutMessageAttribute { + if (attribute.countdownBeginTime == nil || attribute.countdownBeginTime == 0) && message.containsSecretMedia { + updatedAttributes[i] = AutoremoveTimeoutMessageAttribute(timeout: attribute.timeout, countdownBeginTime: timestamp) + updateMessage = true + + if message.id.peerId.namespace == Namespaces.Peer.SecretChat { modifier.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + attribute.timeout, messageId: messageId) + } else { + for i in 0 ..< updatedMedia.count { + if let _ = updatedMedia[i] as? TelegramMediaImage { + updatedMedia[i] = TelegramMediaExpiredContent(data: .image) + } else if let _ = updatedMedia[i] as? TelegramMediaFile { + updatedMedia[i] = TelegramMediaExpiredContent(data: .file) + } + } } - break } + break } } @@ -106,9 +116,9 @@ func markMessageContentAsConsumedRemotely(modifier: Modifier, messageId: Message modifier.updateMessage(message.id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } - return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) + return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: updatedMedia)) }) } } diff --git a/TelegramCore/MonotonicTime.h b/TelegramCore/MonotonicTime.h new file mode 100644 index 0000000000..a6fff4b31b --- /dev/null +++ b/TelegramCore/MonotonicTime.h @@ -0,0 +1,4 @@ +#import + +int64_t MonotonicGetBootTimestamp(); +int64_t MonotonicGetUptime(); diff --git a/TelegramCore/MonotonicTime.m b/TelegramCore/MonotonicTime.m new file mode 100644 index 0000000000..0bdac21a5a --- /dev/null +++ b/TelegramCore/MonotonicTime.m @@ -0,0 +1,29 @@ +#import "MonotonicTime.h" + +#include + +int64_t MonotonicGetBootTimestamp() { + struct timeval boottime; + int mib[2] = {CTL_KERN, KERN_BOOTTIME}; + size_t size = sizeof(boottime); + int rc = sysctl(mib, 2, &boottime, &size, NULL, 0); + if (rc != 0) { + return 0; + } + return boottime.tv_sec * 1000000 + boottime.tv_usec; +} + +int64_t MonotonicGetUptime() { + int64_t before_now; + int64_t after_now; + struct timeval now; + + after_now = MonotonicGetBootTimestamp(); + do { + before_now = after_now; + gettimeofday(&now, NULL); + after_now = MonotonicGetBootTimestamp(); + } while (after_now != before_now); + + return now.tv_sec * 1000000 + now.tv_usec - before_now; +} diff --git a/TelegramCore/MonotonicTime.swift b/TelegramCore/MonotonicTime.swift new file mode 100644 index 0000000000..c2aefc6d6e --- /dev/null +++ b/TelegramCore/MonotonicTime.swift @@ -0,0 +1,13 @@ +import Foundation + +import TelegramCorePrivateModule + +public struct MonotonicTime { + public func getBootTimestamp() -> Int64 { + return MonotonicGetBootTimestamp() + } + + public func getUptime() -> Int64 { + return MonotonicGetUptime() + } +} diff --git a/TelegramCore/MultipartFetch.swift b/TelegramCore/MultipartFetch.swift index 048b483ff9..73ef557ddd 100644 --- a/TelegramCore/MultipartFetch.swift +++ b/TelegramCore/MultipartFetch.swift @@ -43,10 +43,10 @@ private final class MultipartDownloadState { MTAesDecryptBytesInplaceAndModifyIv(bytes, decryptedData.count, self.aesKey, iv) } } - if currentSize + decryptedData.count > self.decryptedSize! { - decryptedData.count = self.decryptedSize! - currentSize + if self.currentSize + Int32(decryptedData.count) > self.decryptedSize! { + decryptedData.count = Int(self.decryptedSize! - self.currentSize) } - currentSize += decryptedData.count + self.currentSize += Int32(decryptedData.count) return decryptedData } else { return data @@ -54,6 +54,234 @@ private final class MultipartDownloadState { } } +private enum MultipartFetchDownloadError { + case generic + case switchToCdn(id: Int32, token: Data, key: Data, iv: Data, partHashes: [Int32: Data]) + case reuploadToCdn(masterDatacenterId: Int32, token: Data) + case hashesMissing +} + +private enum MultipartFetchMasterLocation { + case generic(Int32, Api.InputFileLocation) + case web(Int32, Api.InputWebFileLocation) + + var datacenterId: Int32 { + switch self { + case let .generic(id, _): + return id + case let .web(id, _): + return id + } + } +} + +private final class DownloadWrapper { + private let id: Int32 + private let cdn: Bool + private let take: (Int32, Bool) -> Signal + private let value = Atomic?>(value: nil) + + init(id: Int32, cdn: Bool, take: @escaping (Int32, Bool) -> Signal) { + self.id = id + self.cdn = cdn + self.take = take + } + + func get() -> Signal { + return Signal { subscriber in + var initialize = false + let result = self.value.modify { current in + if let current = current { + return current + } else { + let value = Promise() + initialize = true + return value + } + } + if let result = result { + if initialize { + result.set(self.take(self.id, self.cdn)) + } + return result.get().start(next: { next in + subscriber.putNext(next) + subscriber.putCompletion() + }) + } else { + return EmptyDisposable + } + } + } +} + +private func roundUp(_ value: Int, to multiple: Int) -> Int { + if multiple == 0 { + return value + } + + let remainder = value % multiple + if remainder == 0 { + return value + } + + return value + multiple - remainder +} + +private final class MultipartCdnHashSourceState { + private var hashes: [Int32: Data] + private var requestOffsetAndDisposable: (Int32, Disposable)? + private var requestedOffsets = Set() + + init(hashes: [Int32: Data]) { + self.hashes = hashes + } + + func dispose() -> Disposable? { + let disposable = self.requestOffsetAndDisposable?.1 + self.requestOffsetAndDisposable = nil + return disposable + } + + func get(offset: Int32) -> (Data?, MetaDisposable?) { + if let data = self.hashes[offset] { + return (data, nil) + } else { + requestedOffsets.insert(offset) + if self.requestOffsetAndDisposable == nil { + let disposable = MetaDisposable() + self.requestOffsetAndDisposable = (offset, disposable) + return (nil, disposable) + } else { + return (nil, nil) + } + } + } + + func add(requestedOffset: Int32, addedHashes: [Int32: Data]) -> (Int32, MetaDisposable)? { + + return nil + } +} + +private final class MultipartCdnHashSource { + private let state: Atomic + private let masterDownload: DownloadWrapper + + init(hashes: [Int32: Data], masterDownload: DownloadWrapper) { + self.state = Atomic(value: MultipartCdnHashSourceState(hashes: hashes)) + self.masterDownload = masterDownload + } + + deinit { + let disposable = self.state.with { + return $0.dispose() + } + disposable?.dispose() + } + + func get(offset: Int32) -> Signal { + return .never() + } +} + +private enum MultipartFetchSource { + case none + case master(location: MultipartFetchMasterLocation, download: DownloadWrapper) + case cdn(masterDatacenterId: Int32, fileToken: Data, key: Data, iv: Data, download: DownloadWrapper, masterDownload: DownloadWrapper, hashSource: MultipartCdnHashSource) + + func request(offset: Int32, limit: Int32) -> Signal { + switch self { + case .none: + return .never() + case let .master(location, download): + return download.get() + |> mapToSignalPromotingError { download -> Signal in + var updatedLength = roundUp(Int(limit), to: 4096) + while updatedLength % 4096 != 0 || 1048576 % updatedLength != 0 { + updatedLength += 1 + } + + switch location { + case let .generic(_, location): + return download.request(Api.functions.upload.getFile(location: location, offset: offset, limit: Int32(updatedLength))) + |> mapError { _ -> MultipartFetchDownloadError in + return .generic + } + |> mapToSignal { result -> Signal in + switch result { + case let .file(_, _, bytes): + var resultData = bytes.makeData() + if resultData.count > Int(limit) { + resultData.count = Int(limit) + } + return .single(resultData) + case let .fileCdnRedirect(dcId, fileToken, encryptionKey, encryptionIv, partHashes): + var parsedPartHashes: [Int32: Data] = [:] + for part in partHashes { + switch part { + case let .cdnFileHash(offset, limit, bytes): + assert(limit == 128 * 1024) + parsedPartHashes[offset] = bytes.makeData() + } + } + return .fail(.switchToCdn(id: dcId, token: fileToken.makeData(), key: encryptionKey.makeData(), iv: encryptionIv.makeData(), partHashes: parsedPartHashes)) + } + } + case let .web(_, location): + return download.request(Api.functions.upload.getWebFile(location: location, offset: offset, limit: Int32(updatedLength))) + |> mapError { _ -> MultipartFetchDownloadError in + return .generic + } + |> mapToSignal { result -> Signal in + switch result { + case let .webFile(_, _, _, _, bytes): + var resultData = bytes.makeData() + if resultData.count > Int(limit) { + resultData.count = Int(limit) + } + return .single(resultData) + } + } + } + } + case let .cdn(masterDatacenterId, fileToken, key, iv, download, _, hashSource): + let part = download.get() + |> mapToSignalPromotingError { download -> Signal in + var updatedLength = roundUp(Int(limit), to: 4096) + while updatedLength % 4096 != 0 || 1048576 % updatedLength != 0 { + updatedLength += 1 + } + + return download.request(Api.functions.upload.getCdnFile(fileToken: Buffer(data: fileToken), offset: offset, limit: Int32(updatedLength))) + |> mapError { _ -> MultipartFetchDownloadError in + return .generic + } + |> mapToSignal { result -> Signal in + switch result { + case let .cdnFileReuploadNeeded(token): + return .fail(.reuploadToCdn(masterDatacenterId: masterDatacenterId, token: token.makeData())) + case let .cdnFile(bytes): + if bytes.size == 0 { + return .single(bytes.makeData()) + } else { + var partIv = iv + partIv.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer) -> Void in + var ivOffset: Int32 = (offset / 16).bigEndian + memcpy(bytes.advanced(by: partIv.count - 4), &ivOffset, 4) + } + return .single(MTAesCtrDecrypt(bytes.makeData(), key, partIv)) + } + } + } + } + return combineLatest(part, hashSource.get(offset: offset)) + |> mapToSignal { partData, hashData -> Signal in + return .single(partData) + } + } + } +} + private final class MultipartFetchManager { let parallelParts: Int let defaultPartSize = 128 * 1024 @@ -63,20 +291,26 @@ private final class MultipartFetchManager { var committedOffset: Int let range: Range var completeSize: Int? - let fetchPart: (Int, Int) -> Signal + let takeDownloader: (Int32, Bool) -> Signal let partReady: (Data) -> Void let completed: () -> Void + private var source: MultipartFetchSource + var fetchingParts: [Int: (Int, Disposable)] = [:] var fetchedParts: [Int: Data] = [:] + var cachedPartHashes: [Int: Data] = [:] var statsTimer: SignalKitTimer? var receivedSize = 0 var lastStatReport: (timestamp: Double, receivedSize: Int)? + var reuploadingToCdn = false + let reuploadToCdnDisposable = MetaDisposable() + var state: MultipartDownloadState - init(size: Int?, range: Range, encryptionKey: SecretFileEncryptionKey?, decryptedSize: Int32?, fetchPart: @escaping (Int, Int) -> Signal, partReady: @escaping (Data) -> Void, completed: @escaping () -> Void) { + init(size: Int?, range: Range, encryptionKey: SecretFileEncryptionKey?, decryptedSize: Int32?, location: MultipartFetchMasterLocation, takeDownloader: @escaping (Int32, Bool) -> Signal, partReady: @escaping (Data) -> Void, completed: @escaping () -> Void) { self.completeSize = size if let size = size { if size <= range.lowerBound { @@ -91,9 +325,11 @@ private final class MultipartFetchManager { self.range = range self.parallelParts = 1 } + self.state = MultipartDownloadState(encryptionKey: encryptionKey, decryptedSize: decryptedSize) self.committedOffset = range.lowerBound - self.fetchPart = fetchPart + self.takeDownloader = takeDownloader + self.source = .master(location: location, download: DownloadWrapper(id: location.datacenterId, cdn: false, take: takeDownloader)) self.partReady = partReady self.completed = completed @@ -120,10 +356,12 @@ private final class MultipartFetchManager { func cancel() { self.queue.async { + self.source = .none for (_, (_, disposable)) in self.fetchingParts { disposable.dispose() } self.statsTimer?.invalidate() + self.reuploadToCdnDisposable.dispose() } } @@ -142,18 +380,29 @@ private final class MultipartFetchManager { } else if self.committedOffset >= self.range.upperBound { self.completed() } else { - while fetchingParts.count < self.parallelParts { - var nextOffset = self.committedOffset + while fetchingParts.count < self.parallelParts && !self.reuploadingToCdn { + var processedParts: [(Int, Int)] = [] for (offset, (size, _)) in self.fetchingParts { - nextOffset = max(nextOffset, offset + size) + processedParts.append((offset, size)) } for (offset, data) in self.fetchedParts { - nextOffset = max(nextOffset, offset + data.count) + processedParts.append((offset, data.count)) + } + processedParts.sort(by: { $0.0 < $1.0 }) + var nextOffset = self.committedOffset + for (offset, size) in processedParts { + if offset >= self.committedOffset { + if offset == nextOffset { + nextOffset = offset + size + } else { + break + } + } } if nextOffset < self.range.upperBound { let partSize = min(self.range.upperBound - nextOffset, self.defaultPartSize) - let part = self.fetchPart(nextOffset, partSize) + let part = self.source.request(offset: Int32(nextOffset), limit: Int32(partSize)) |> deliverOn(self.queue) let partOffset = nextOffset self.fetchingParts[nextOffset] = (partSize, part.start(next: { [weak self] data in @@ -175,6 +424,45 @@ private final class MultipartFetchManager { strongSelf.fetchedParts[partOffset] = data strongSelf.checkState() } + }, error: { [weak self] error in + if let strongSelf = self { + let _ = strongSelf.fetchingParts.removeValue(forKey: partOffset) + switch error { + case .generic: + break + case let .switchToCdn(id, token, key, iv, partHashes): + switch strongSelf.source { + case let .master(location, download): + strongSelf.source = .cdn(masterDatacenterId: location.datacenterId, fileToken: token, key: key, iv: iv, download: DownloadWrapper(id: id, cdn: true, take: strongSelf.takeDownloader), masterDownload: download, hashSource: MultipartCdnHashSource(hashes: partHashes, masterDownload: download)) + strongSelf.checkState() + case .cdn, .none: + break + } + case let .reuploadToCdn(_, token): + switch strongSelf.source { + case .master, .none: + break + case let .cdn(_, fileToken, _, _, _, masterDownload, _): + if !strongSelf.reuploadingToCdn { + strongSelf.reuploadingToCdn = true + let reupload: Signal = masterDownload.get() |> mapToSignal { download -> Signal in + return download.request(Api.functions.upload.reuploadCdnFile(fileToken: Buffer(data: fileToken), requestToken: Buffer(data: token))) + |> `catch` { _ -> Signal in + return .single(.boolFalse) + } + } + strongSelf.reuploadToCdnDisposable.set((reupload |> deliverOn(strongSelf.queue)).start(next: { result in + if let strongSelf = self { + strongSelf.reuploadingToCdn = false + strongSelf.checkState() + } + })) + } + } + case .hashesMissing: + break + } + } })) } else { break @@ -184,39 +472,43 @@ private final class MultipartFetchManager { } func reportStats() { - if let lastStatReport = self.lastStatReport { + /*if let lastStatReport = self.lastStatReport { let downloadSpeed = Double(self.receivedSize - lastStatReport.receivedSize) / (CACurrentMediaTime() - lastStatReport.timestamp) print("MultipartFetch speed \(downloadSpeed / 1024) KB/s") } - self.lastStatReport = (CACurrentMediaTime(), self.receivedSize) + self.lastStatReport = (CACurrentMediaTime(), self.receivedSize)*/ } } func multipartFetch(account: Account, resource: TelegramMultipartFetchableResource, size: Int?, range: Range, tag: MediaResourceFetchTag?, encryptionKey: SecretFileEncryptionKey? = nil, decryptedSize: Int32? = nil) -> Signal { - return account.network.download(datacenterId: resource.datacenterId, tag: tag) - |> mapToSignal { download -> Signal in - return Signal { subscriber in - - let manager = MultipartFetchManager(size: size, range: range, encryptionKey: encryptionKey, decryptedSize: decryptedSize, fetchPart: { offset, size in - if let resource = resource as? TelegramCloudMediaResource { - return download.part(location: resource.apiInputLocation, offset: offset, length: size) - } else if let resource = resource as? WebFileReferenceMediaResource { - return download.webFilePart(location: resource.apiInputLocation, offset: offset, length: size) - } else { - fatalError("multipart fetch allos only TelegramCloudMediaResource and WebFileReferenceMediaResource") - } - }, partReady: { data in - subscriber.putNext(.dataPart(data: data, range: 0 ..< data.count, complete: false)) - }, completed: { - subscriber.putNext(.dataPart(data: Data(), range: 0 ..< 0, complete: true)) - subscriber.putCompletion() - }) - - manager.start() - - return ActionDisposable { - manager.cancel() - } - } + return Signal { subscriber in + let datacenterId = resource.datacenterId + let location: MultipartFetchMasterLocation + if let resource = resource as? TelegramCloudMediaResource { + location = .generic(Int32(datacenterId), resource.apiInputLocation) + } else if let resource = resource as? WebFileReferenceMediaResource { + location = .web(Int32(datacenterId), resource.apiInputLocation) + } else { + assertionFailure("multipartFetch: unsupported resource type \(resource)") + return EmptyDisposable } + + let manager = MultipartFetchManager(size: size, range: range, encryptionKey: encryptionKey, decryptedSize: decryptedSize, location: location, takeDownloader: { id, cdn in + return account.network.download(datacenterId: Int(id), isCdn: cdn, tag: tag) + }, partReady: { data in + subscriber.putNext(.dataPart(data: data, range: 0 ..< data.count, complete: false)) + }, completed: { + subscriber.putNext(.dataPart(data: Data(), range: 0 ..< 0, complete: true)) + subscriber.putCompletion() + }) + + manager.start() + + var managerRef: MultipartFetchManager? = manager + + return ActionDisposable { + managerRef?.cancel() + managerRef = nil + } + } } diff --git a/TelegramCore/MultipartUpload.swift b/TelegramCore/MultipartUpload.swift index 709983039a..a86dee1f18 100644 --- a/TelegramCore/MultipartUpload.swift +++ b/TelegramCore/MultipartUpload.swift @@ -147,7 +147,7 @@ private final class MultipartUploadManager { var committedOffset: Int let uploadPart: (UploadPart) -> Signal let progress: (Float) -> Void - let completed: (MultipartIntermediateResult) -> Void + let completed: (MultipartIntermediateResult?) -> Void var uploadingParts: [Int: (Int, Disposable)] = [:] var uploadedParts: [Int: Int] = [:] @@ -159,7 +159,7 @@ private final class MultipartUploadManager { let state: MultipartUploadState - init(headerSize: Int32, data: Signal, encryptionKey: SecretFileEncryptionKey?, hintFileSize: Int?, uploadPart: @escaping (UploadPart) -> Signal, progress: @escaping (Float) -> Void, completed: @escaping (MultipartIntermediateResult) -> Void) { + init(headerSize: Int32, data: Signal, encryptionKey: SecretFileEncryptionKey?, hintFileSize: Int?, uploadPart: @escaping (UploadPart) -> Signal, progress: @escaping (Float) -> Void, completed: @escaping (MultipartIntermediateResult?) -> Void) { self.dataSignal = data var fileId: Int64 = 0 @@ -287,20 +287,24 @@ private final class MultipartUploadManager { case let .data(data): fileData = data } - let partData = self.state.transform(data: fileData!.subdata(in: partOffset ..< (partOffset + partSize))) - var currentBigTotalParts = self.bigTotalParts - if let _ = self.bigTotalParts, resourceData.complete && partOffset + partSize == resourceData.size { - currentBigTotalParts = (resourceData.size / self.defaultPartSize) + (resourceData.size % self.defaultPartSize == 0 ? 0 : 1) - } - let part = self.uploadPart(UploadPart(fileId: self.fileId, index: partIndex, data: partData, bigTotalParts: currentBigTotalParts)) - |> deliverOn(self.queue) - self.uploadingParts[nextOffset] = (partSize, part.start(completed: { [weak self] in - if let strongSelf = self { - let _ = strongSelf.uploadingParts.removeValue(forKey: nextOffset) - strongSelf.uploadedParts[partOffset] = partSize - strongSelf.checkState() + if let fileData = fileData { + let partData = self.state.transform(data: fileData.subdata(in: partOffset ..< (partOffset + partSize))) + var currentBigTotalParts = self.bigTotalParts + if let _ = self.bigTotalParts, resourceData.complete && partOffset + partSize == resourceData.size { + currentBigTotalParts = (resourceData.size / self.defaultPartSize) + (resourceData.size % self.defaultPartSize == 0 ? 0 : 1) } - })) + let part = self.uploadPart(UploadPart(fileId: self.fileId, index: partIndex, data: partData, bigTotalParts: currentBigTotalParts)) + |> deliverOn(self.queue) + self.uploadingParts[nextOffset] = (partSize, part.start(completed: { [weak self] in + if let strongSelf = self { + let _ = strongSelf.uploadingParts.removeValue(forKey: nextOffset) + strongSelf.uploadedParts[partOffset] = partSize + strongSelf.checkState() + } + })) + } else { + self.completed(nil) + } } else { break } @@ -323,9 +327,13 @@ enum MultipartUploadSource { case data(Data) } -func multipartUpload(network: Network, postbox: Postbox, source: MultipartUploadSource, encrypt: Bool, tag: MediaResourceFetchTag?, hintFileSize: Int? = nil) -> Signal { +enum MultipartUploadError { + case generic +} + +func multipartUpload(network: Network, postbox: Postbox, source: MultipartUploadSource, encrypt: Bool, tag: MediaResourceFetchTag?, hintFileSize: Int? = nil) -> Signal { return network.download(datacenterId: network.datacenterId, tag: tag) - |> mapToSignal { download -> Signal in + |> mapToSignalPromotingError { download -> Signal in return Signal { subscriber in var encryptionKey: SecretFileEncryptionKey? if encrypt { @@ -361,35 +369,39 @@ func multipartUpload(network: Network, postbox: Postbox, source: MultipartUpload }, progress: { progress in subscriber.putNext(.progress(progress)) }, completed: { result in - if let encryptionKey = encryptionKey { - let keyDigest = md5(encryptionKey.aesKey + encryptionKey.aesIv) - var fingerprint: Int32 = 0 - keyDigest.withUnsafeBytes { (bytes: UnsafePointer) -> Void in - withUnsafeMutableBytes(of: &fingerprint, { ptr -> Void in - let uintPtr = ptr.baseAddress!.assumingMemoryBound(to: UInt8.self) - uintPtr[0] = bytes[0] ^ bytes[4] - uintPtr[1] = bytes[1] ^ bytes[5] - uintPtr[2] = bytes[2] ^ bytes[6] - uintPtr[3] = bytes[3] ^ bytes[7] - }) - } - if let _ = result.bigTotalParts { - let inputFile = Api.InputEncryptedFile.inputEncryptedFileBigUploaded(id: result.id, parts: result.partCount, keyFingerprint: fingerprint) - subscriber.putNext(.inputSecretFile(inputFile, result.size, encryptionKey)) + if let result = result { + if let encryptionKey = encryptionKey { + let keyDigest = md5(encryptionKey.aesKey + encryptionKey.aesIv) + var fingerprint: Int32 = 0 + keyDigest.withUnsafeBytes { (bytes: UnsafePointer) -> Void in + withUnsafeMutableBytes(of: &fingerprint, { ptr -> Void in + let uintPtr = ptr.baseAddress!.assumingMemoryBound(to: UInt8.self) + uintPtr[0] = bytes[0] ^ bytes[4] + uintPtr[1] = bytes[1] ^ bytes[5] + uintPtr[2] = bytes[2] ^ bytes[6] + uintPtr[3] = bytes[3] ^ bytes[7] + }) + } + if let _ = result.bigTotalParts { + let inputFile = Api.InputEncryptedFile.inputEncryptedFileBigUploaded(id: result.id, parts: result.partCount, keyFingerprint: fingerprint) + subscriber.putNext(.inputSecretFile(inputFile, result.size, encryptionKey)) + } else { + let inputFile = Api.InputEncryptedFile.inputEncryptedFileUploaded(id: result.id, parts: result.partCount, md5Checksum: result.md5Digest, keyFingerprint: fingerprint) + subscriber.putNext(.inputSecretFile(inputFile, result.size, encryptionKey)) + } } else { - let inputFile = Api.InputEncryptedFile.inputEncryptedFileUploaded(id: result.id, parts: result.partCount, md5Checksum: result.md5Digest, keyFingerprint: fingerprint) - subscriber.putNext(.inputSecretFile(inputFile, result.size, encryptionKey)) + if let _ = result.bigTotalParts { + let inputFile = Api.InputFile.inputFileBig(id: result.id, parts: result.partCount, name: "file.jpg") + subscriber.putNext(.inputFile(inputFile)) + } else { + let inputFile = Api.InputFile.inputFile(id: result.id, parts: result.partCount, name: "file.jpg", md5Checksum: result.md5Digest) + subscriber.putNext(.inputFile(inputFile)) + } } + subscriber.putCompletion() } else { - if let _ = result.bigTotalParts { - let inputFile = Api.InputFile.inputFileBig(id: result.id, parts: result.partCount, name: "file.jpg") - subscriber.putNext(.inputFile(inputFile)) - } else { - let inputFile = Api.InputFile.inputFile(id: result.id, parts: result.partCount, name: "file.jpg", md5Checksum: result.md5Digest) - subscriber.putNext(.inputFile(inputFile)) - } + subscriber.putError(.generic) } - subscriber.putCompletion() }) manager.start() diff --git a/TelegramCore/Namespaces.swift b/TelegramCore/Namespaces.swift index 2dafe1e1d0..ebca673959 100644 --- a/TelegramCore/Namespaces.swift +++ b/TelegramCore/Namespaces.swift @@ -53,6 +53,7 @@ public struct Namespaces { struct CachedItemCollection { public static let resolvedByNamePeers: Int8 = 0 + public static let cachedTwoStepToken: Int8 = 1 } struct UnorderedItemList { diff --git a/TelegramCore/Network.swift b/TelegramCore/Network.swift index ff8130df66..0c476bfca9 100644 --- a/TelegramCore/Network.swift +++ b/TelegramCore/Network.swift @@ -433,7 +433,28 @@ func initializedNetwork(arguments: NetworkInitializationArguments, supplementary } } -public class Network: NSObject, MTRequestMessageServiceDelegate { +private final class NetworkHelper: NSObject, MTContextChangeListener { + private let requestPublicKeys: (Int) -> Signal + + init(requestPublicKeys: @escaping (Int) -> Signal) { + self.requestPublicKeys = requestPublicKeys + } + + func fetchContextDatacenterPublicKeys(_ context: MTContext!, datacenterId: Int) -> MTSignal! { + return MTSignal { subscriber in + let disposable = self.requestPublicKeys(datacenterId).start(next: { next in + subscriber?.putNext(next) + subscriber?.putCompletion() + }) + + return MTBlockDisposable(block: { + disposable.dispose() + }) + } + } +} + +public final class Network: NSObject, MTRequestMessageServiceDelegate { let datacenterId: Int let context: MTContext let mtProto: MTProto @@ -462,6 +483,37 @@ public class Network: NSObject, MTRequestMessageServiceDelegate { super.init() + context.add(NetworkHelper(requestPublicKeys: { [weak self] id in + if let strongSelf = self { + return strongSelf.request(Api.functions.help.getCdnConfig()) + |> map { Optional($0) } + |> `catch` { _ -> Signal in + return .single(nil) + } + |> map { result -> NSArray in + let array = NSMutableArray() + if let result = result { + switch result { + case let .cdnConfig(publicKeys): + for key in publicKeys { + switch key { + case let .cdnPublicKey(dcId, publicKey): + if id == Int(dcId) { + let dict = NSMutableDictionary() + dict["key"] = publicKey + dict["fingerprint"] = MTRsaFingerprint(publicKey) + array.add(dict) + } + } + } + } + } + return array + } + } else { + return .never() + } + })) requestService.delegate = self let shouldKeepConnectionSignal = self.shouldKeepConnection.get() @@ -487,10 +539,10 @@ public class Network: NSObject, MTRequestMessageServiceDelegate { self.loggedOut?() } - func download(datacenterId: Int, tag: MediaResourceFetchTag?) -> Signal { + func download(datacenterId: Int, isCdn: Bool = false, tag: MediaResourceFetchTag?) -> Signal { return Signal { [weak self] subscriber in if let strongSelf = self { - subscriber.putNext(Download(datacenterId: datacenterId, context: strongSelf.context, masterDatacenterId: strongSelf.datacenterId, usageInfo: usageCalculationInfo(basePath: strongSelf.basePath, category: (tag as? TelegramMediaResourceFetchTag)?.statsCategory))) + subscriber.putNext(Download(datacenterId: datacenterId, isCdn: isCdn, context: strongSelf.context, masterDatacenterId: strongSelf.datacenterId, usageInfo: usageCalculationInfo(basePath: strongSelf.basePath, category: (tag as? TelegramMediaResourceFetchTag)?.statsCategory))) } subscriber.putCompletion() @@ -500,6 +552,10 @@ public class Network: NSObject, MTRequestMessageServiceDelegate { } } + public func getApproximateRemoteTimestamp() -> Int32 { + return Int32(self.context.globalTime()) + } + public func request(_ data: (CustomStringConvertible, Buffer, (Buffer) -> T?), tag: NetworkRequestDependencyTag? = nil, automaticFloodWait: Bool = true) -> Signal { let requestService = self.requestService return Signal { subscriber in @@ -551,8 +607,8 @@ public class Network: NSObject, MTRequestMessageServiceDelegate { requestService.add(request) - return ActionDisposable { - self.requestService.removeRequest(byInternalId: internalId) + return ActionDisposable { [weak requestService] in + requestService?.removeRequest(byInternalId: internalId) } } } diff --git a/TelegramCore/PendingMessageManager.swift b/TelegramCore/PendingMessageManager.swift index bbcd2f3183..e68cc09156 100644 --- a/TelegramCore/PendingMessageManager.swift +++ b/TelegramCore/PendingMessageManager.swift @@ -17,7 +17,7 @@ public struct PendingMessageStatus: Equatable { private enum PendingMessageState { case none - case waitingForUploadToStart(Signal) + case waitingForUploadToStart(Signal) case uploading case sending } @@ -258,7 +258,7 @@ public final class PendingMessageManager { })) } - private func beginUploadingMessage(messageContext: PendingMessageContext, id: MessageId, uploadSignal: Signal) { + private func beginUploadingMessage(messageContext: PendingMessageContext, id: MessageId, uploadSignal: Signal) { messageContext.state = .uploading messageContext.disposable.set((uploadSignal |> deliverOn(self.queue)).start(next: { [weak self] next in @@ -386,7 +386,7 @@ public final class PendingMessageManager { } var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) @@ -407,7 +407,7 @@ public final class PendingMessageManager { } var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) @@ -416,7 +416,7 @@ public final class PendingMessageManager { modifier.updateMessage(messageId, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) @@ -501,7 +501,7 @@ public final class PendingMessageManager { modifier.updateMessage(message.id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) @@ -514,7 +514,7 @@ public final class PendingMessageManager { modifier.updateMessage(message.id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature) } return .update(StoreMessage(id: message.id, globallyUniqueId: currentMessage.globallyUniqueId, timestamp: currentMessage.timestamp, flags: [.Failed], tags: currentMessage.tags, globalTags: currentMessage.globalTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media)) }) diff --git a/TelegramCore/PendingMessageUploadedContent.swift b/TelegramCore/PendingMessageUploadedContent.swift index 0bc733ba9c..9c38872445 100644 --- a/TelegramCore/PendingMessageUploadedContent.swift +++ b/TelegramCore/PendingMessageUploadedContent.swift @@ -20,9 +20,13 @@ enum PendingMessageUploadedContentResult { case content(PendingMessageUploadedContent) } +enum PendingMessageUploadError { + case generic +} + enum PendingMessageUploadContent { case ready(PendingMessageUploadedContent) - case upload(Signal) + case upload(Signal) } func messageContentToUpload(network: Network, postbox: Postbox, transformOutgoingMessageMedia: TransformOutgoingMessageMedia?, message: Message) -> PendingMessageUploadContent { @@ -80,15 +84,16 @@ func messageContentToUpload(network: Network, postbox: Postbox, transformOutgoin } } -private func uploadedMediaImageContent(network: Network, postbox: Postbox, peerId: PeerId, image: TelegramMediaImage, text: String) -> Signal { +private func uploadedMediaImageContent(network: Network, postbox: Postbox, peerId: PeerId, image: TelegramMediaImage, text: String) -> Signal { if let largestRepresentation = largestImageRepresentation(image.representations) { return multipartUpload(network: network, postbox: postbox, source: .resource(largestRepresentation.resource), encrypt: peerId.namespace == Namespaces.Peer.SecretChat, tag: TelegramMediaResourceFetchTag(statsCategory: .image)) + |> mapError { _ -> PendingMessageUploadError in return .generic } |> map { next -> PendingMessageUploadedContentResult in switch next { case let .progress(progress): return .progress(progress) case let .inputFile(file): - return .content(.media(Api.InputMedia.inputMediaUploadedPhoto(flags: 0, file: file, caption: text, stickers: nil))) + return .content(.media(Api.InputMedia.inputMediaUploadedPhoto(flags: 0, file: file, caption: text, stickers: nil, ttlSeconds: nil))) case let .inputSecretFile(file, size, key): return .content(.secretMedia(file, size, key)) } @@ -160,9 +165,10 @@ private enum UploadedMediaThumbnail { case done(Api.InputFile?) } -private func uploadedThumbnail(network: Network, postbox: Postbox, image: TelegramMediaImageRepresentation) -> Signal { +private func uploadedThumbnail(network: Network, postbox: Postbox, image: TelegramMediaImageRepresentation) -> Signal { return multipartUpload(network: network, postbox: postbox, source: .resource(image.resource), encrypt: false, tag: TelegramMediaResourceFetchTag(statsCategory: .image)) - |> mapToSignal { result -> Signal in + |> mapError { _ -> PendingMessageUploadError in return .generic } + |> mapToSignal { result -> Signal in switch result { case .progress: return .complete() @@ -188,7 +194,7 @@ public func statsCategoryForFileWithAttributes(_ attributes: [TelegramMediaFileA return .file } -private func uploadedMediaFileContent(network: Network, postbox: Postbox, transformOutgoingMessageMedia: TransformOutgoingMessageMedia?, peerId: PeerId, messageId: MessageId?, text: String, attributes: [MessageAttribute], file: TelegramMediaFile) -> Signal { +private func uploadedMediaFileContent(network: Network, postbox: Postbox, transformOutgoingMessageMedia: TransformOutgoingMessageMedia?, peerId: PeerId, messageId: MessageId?, text: String, attributes: [MessageAttribute], file: TelegramMediaFile) -> Signal { var hintSize: Int? if let size = file.size { hintSize = size @@ -196,16 +202,7 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, transf hintSize = Int(size) } let upload = multipartUpload(network: network, postbox: postbox, source: .resource(file.resource), encrypt: peerId.namespace == Namespaces.Peer.SecretChat, tag: TelegramMediaResourceFetchTag(statsCategory: statsCategoryForFileWithAttributes(file.attributes)), hintFileSize: hintSize) - /*|> map { next -> UploadedMediaFileContent in - switch next { - case let .progress(progress): - return .progress(progress) - case let .inputFile(inputFile): - return .content(message, .media(Api.InputMedia.inputMediaUploadedDocument(flags: 0, file: inputFile, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFile(file), caption: message.text, stickers: nil))) - case let .inputSecretFile(file, size, key): - return .content(message, .secretMedia(file, size, key)) - } - }*/ + |> mapError { _ -> PendingMessageUploadError in return .generic } var alreadyTransformed = false for attribute in attributes { if let attribute = attribute as? OutgoingMessageInfoAttribute { @@ -227,7 +224,7 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, transf modifier.updateMessage(messageId, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? if let forwardInfo = currentMessage.forwardInfo { - storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date) + storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: nil) } var updatedAttributes = currentMessage.attributes if let index = updatedAttributes.index(where: { $0 is OutgoingMessageInfoAttribute }){ @@ -249,14 +246,15 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, transf transform = .single(.done(file)) } - let thumbnail: Signal = .single(.pending) |> then(transform - |> mapToSignal { media -> Signal in + let thumbnail: Signal = .single(.pending) |> then(transform + |> mapToSignalPromotingError { media -> Signal in switch media { case .pending: return .single(.pending) case let .done(media): if let media = media as? TelegramMediaFile, let smallestThumbnail = smallestImageRepresentation(media.previewRepresentations) { return uploadedThumbnail(network: network, postbox: postbox, image: smallestThumbnail) + |> mapError { _ -> PendingMessageUploadError in return .generic } |> map { result in return .done(result) } @@ -267,7 +265,7 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, transf }) return combineLatest(upload, thumbnail) - |> mapToSignal { content, media -> Signal in + |> mapToSignal { content, media -> Signal in switch content { case let .progress(progress): return .single(.progress(progress)) @@ -275,9 +273,9 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, transf if case let .done(thumbnail) = media { let inputMedia: Api.InputMedia if let thumbnail = thumbnail { - inputMedia = Api.InputMedia.inputMediaUploadedThumbDocument(flags: 0, file: inputFile, thumb: thumbnail, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), caption: text, stickers: nil) + inputMedia = Api.InputMedia.inputMediaUploadedDocument(flags: (1 << 2), file: inputFile, thumb: thumbnail, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), caption: text, stickers: nil, ttlSeconds: nil) } else { - inputMedia = Api.InputMedia.inputMediaUploadedDocument(flags: 0, file: inputFile, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), caption: text, stickers: nil) + inputMedia = Api.InputMedia.inputMediaUploadedDocument(flags: 0, file: inputFile, thumb: nil, mimeType: file.mimeType, attributes: inputDocumentAttributesFromFileAttributes(file.attributes), caption: text, stickers: nil, ttlSeconds: nil) } return .single(.content(.media(inputMedia))) } else { diff --git a/TelegramCore/RecentPeerItem.swift b/TelegramCore/RecentPeerItem.swift index 50a3cfc602..e7c0e88274 100644 --- a/TelegramCore/RecentPeerItem.swift +++ b/TelegramCore/RecentPeerItem.swift @@ -26,12 +26,17 @@ public struct RecentPeerItemId { } public final class RecentPeerItem: OrderedItemListEntryContents { - init() { + public let rating: Double + + init(rating: Double) { + self.rating = rating } public init(decoder: Decoder) { + self.rating = decoder.decodeDoubleForKey("r", orElse: 0.0) } public func encode(_ encoder: Encoder) { + encoder.encodeDouble(self.rating, forKey: "r") } } diff --git a/TelegramCore/RecentPeers.swift b/TelegramCore/RecentPeers.swift index b690f293e7..0cbaafebb0 100644 --- a/TelegramCore/RecentPeers.swift +++ b/TelegramCore/RecentPeers.swift @@ -51,9 +51,9 @@ public func recentPeers(account: Account) -> Signal<[Peer], NoError> { public func managedRecentlyUsedInlineBots(postbox: Postbox, network: Network) -> Signal { let remotePeers = network.request(Api.functions.contacts.getTopPeers(flags: 1 << 2, offset: 0, limit: 16, hash: 0)) |> retryRequest - |> map { result -> ([Peer], [PeerId: PeerPresence])? in + |> map { result -> ([Peer], [PeerId: PeerPresence], [(PeerId, Double)])? in switch result { - case let .topPeers(_, _, users): + case let .topPeers(categories, _, users): var peers: [Peer] = [] var peerPresences: [PeerId: PeerPresence] = [:] for user in users { @@ -63,21 +63,36 @@ public func managedRecentlyUsedInlineBots(postbox: Postbox, network: Network) -> peerPresences[telegramUser.id] = presence } } - return (peers, peerPresences) + var peersWithRating: [(PeerId, Double)] = [] + for category in categories { + switch category { + case let .topPeerCategoryPeers(_, _, topPeers): + for topPeer in topPeers { + switch topPeer { + case let .topPeer(apiPeer, rating): + peersWithRating.append((apiPeer.peerId, rating)) + } + } + } + } + return (peers, peerPresences, peersWithRating) case .topPeersNotModified: break } - return ([], [:]) + return ([], [:], []) } let updatedRemotePeers = remotePeers |> mapToSignal { peersAndPresences -> Signal in - if let (peers, peerPresences) = peersAndPresences { + if let (peers, peerPresences, peersWithRating) = peersAndPresences { return postbox.modify { modifier -> Void in updatePeers(modifier: modifier, peers: peers, update: { return $1 }) modifier.updatePeerPresences(peerPresences) - modifier.replaceOrderedItemListItems(collectionId: Namespaces.OrderedItemList.CloudRecentInlineBots, items: peers.map { peer in - return OrderedItemListEntry(id: RecentPeerItemId(peer.id).rawValue, contents: RecentPeerItem()) + + let sortedPeersWithRating = peersWithRating.sorted(by: { $0.1 > $1.1 }) + + modifier.replaceOrderedItemListItems(collectionId: Namespaces.OrderedItemList.CloudRecentInlineBots, items: sortedPeersWithRating.map { (peerId, rating) in + return OrderedItemListEntry(id: RecentPeerItemId(peerId).rawValue, contents: RecentPeerItem(rating: rating)) }) } } else { @@ -90,21 +105,27 @@ public func managedRecentlyUsedInlineBots(postbox: Postbox, network: Network) -> public func addRecentlyUsedInlineBot(postbox: Postbox, peerId: PeerId) -> Signal { return postbox.modify { modifier -> Void in - modifier.addOrMoveToFirstPositionOrderedItemListItem(collectionId: Namespaces.OrderedItemList.CloudRecentInlineBots, item: OrderedItemListEntry(id: RecentPeerItemId(peerId).rawValue, contents: RecentPeerItem()), removeTailIfCountExceeds: 20) + var maxRating = 1.0 + for entry in modifier.getOrderedListItems(collectionId: Namespaces.OrderedItemList.CloudRecentInlineBots) { + if let contents = entry.contents as? RecentPeerItem { + maxRating = max(maxRating, contents.rating) + } + } + modifier.addOrMoveToFirstPositionOrderedItemListItem(collectionId: Namespaces.OrderedItemList.CloudRecentInlineBots, item: OrderedItemListEntry(id: RecentPeerItemId(peerId).rawValue, contents: RecentPeerItem(rating: maxRating)), removeTailIfCountExceeds: 20) } } -public func recentlyUsedInlineBots(postbox: Postbox) -> Signal<[Peer], NoError> { +public func recentlyUsedInlineBots(postbox: Postbox) -> Signal<[(Peer, Double)], NoError> { return postbox.combinedView(keys: [.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentInlineBots)]) |> take(1) - |> mapToSignal { view -> Signal<[Peer], NoError> in - return postbox.modify { modifier -> [Peer] in - var peers: [Peer] = [] + |> mapToSignal { view -> Signal<[(Peer, Double)], NoError> in + return postbox.modify { modifier -> [(Peer, Double)] in + var peers: [(Peer, Double)] = [] if let view = view.views[.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentInlineBots)] as? OrderedItemListView { for item in view.items { let peerId = RecentPeerItemId(item.id).peerId - if let peer = modifier.getPeer(peerId) { - peers.append(peer) + if let peer = modifier.getPeer(peerId), let contents = item.contents as? RecentPeerItem { + peers.append((peer, contents.rating)) } } } diff --git a/TelegramCore/RecentlySearchedPeerIds.swift b/TelegramCore/RecentlySearchedPeerIds.swift index 12408b0150..2f7f507d30 100644 --- a/TelegramCore/RecentlySearchedPeerIds.swift +++ b/TelegramCore/RecentlySearchedPeerIds.swift @@ -9,7 +9,7 @@ import Foundation public func addRecentlySearchedPeer(postbox: Postbox, peerId: PeerId) -> Signal { return postbox.modify { modifier -> Void in - modifier.addOrMoveToFirstPositionOrderedItemListItem(collectionId: Namespaces.OrderedItemList.RecentlySearchedPeerIds, item: OrderedItemListEntry(id: RecentPeerItemId(peerId).rawValue, contents: RecentPeerItem()), removeTailIfCountExceeds: 20) + modifier.addOrMoveToFirstPositionOrderedItemListItem(collectionId: Namespaces.OrderedItemList.RecentlySearchedPeerIds, item: OrderedItemListEntry(id: RecentPeerItemId(peerId).rawValue, contents: RecentPeerItem(rating: 0.0)), removeTailIfCountExceeds: 20) } } diff --git a/TelegramCore/Serialization.swift b/TelegramCore/Serialization.swift index 4b3f1f4307..35eb340ec5 100644 --- a/TelegramCore/Serialization.swift +++ b/TelegramCore/Serialization.swift @@ -20,7 +20,7 @@ public class BoxedMessage: NSObject { public class Serialization: NSObject, MTSerialization { public func currentLayer() -> UInt { - return 68 + return 70 } public func parseMessage(_ data: Data!) -> Any! { diff --git a/TelegramCore/StandaloneSendMessage.swift b/TelegramCore/StandaloneSendMessage.swift index ce575a9d04..c5dbe01b6b 100644 --- a/TelegramCore/StandaloneSendMessage.swift +++ b/TelegramCore/StandaloneSendMessage.swift @@ -24,12 +24,17 @@ private enum StandaloneSendMessageEvent { case progress(Float) } -public func standaloneSendMessage(account: Account, peerId: PeerId, text: String, attributes: [MessageAttribute], media: StandaloneMedia?, replyToMessageId: MessageId?) -> Signal { - let content: Signal +public enum StandaloneSendMessageError { + case generic +} + +public func standaloneSendMessage(account: Account, peerId: PeerId, text: String, attributes: [MessageAttribute], media: StandaloneMedia?, replyToMessageId: MessageId?) -> Signal { + let content: Signal if let media = media { switch media { case let .image(data): content = uploadedImage(account: account, text: text, data: data) + |> mapError { _ -> StandaloneSendMessageError in return .generic } |> map { next -> StandaloneSendMessageEvent in switch next { case let .progress(progress): @@ -40,6 +45,7 @@ public func standaloneSendMessage(account: Account, peerId: PeerId, text: String } case let .file(data, mimeType, attributes): content = uploadedFile(account: account, text: text, data: data, mimeType: mimeType, attributes: attributes) + |> mapError { _ -> StandaloneSendMessageError in return .generic } |> map { next -> StandaloneSendMessageEvent in switch next { case let .progress(progress): @@ -54,12 +60,13 @@ public func standaloneSendMessage(account: Account, peerId: PeerId, text: String } return content - |> mapToSignal { event -> Signal in + |> mapToSignal { event -> Signal in switch event { case let .progress(progress): return .single(progress) case let .result(result): - return .single(1.0) |> then(sendMessageContent(account: account, peerId: peerId, attributes: attributes, content: result) |> map({ _ -> Float in return 1.0 })) + let sendContent = sendMessageContent(account: account, peerId: peerId, attributes: attributes, content: result) |> map({ _ -> Float in return 1.0 }) + return .single(1.0) |> then(sendContent |> mapError { _ -> StandaloneSendMessageError in return .generic }) } } @@ -119,11 +126,6 @@ private func sendMessageContent(account: Account, peerId: PeerId, attributes: [M return sendMessageRequest |> mapToSignal { result -> Signal in return .complete() - /*if let strongSelf = self { - return strongSelf.applySentMessage(postbox: postbox, stateManager: stateManager, message: message, result: result) - } else { - return .never() - }*/ } |> `catch` { _ -> Signal in return .complete() @@ -139,12 +141,13 @@ private enum UploadMediaEvent { case result(Api.InputMedia) } -private func uploadedImage(account: Account, text: String, data: Data) -> Signal { +private func uploadedImage(account: Account, text: String, data: Data) -> Signal { return multipartUpload(network: account.network, postbox: account.postbox, source: .data(data), encrypt: false, tag: TelegramMediaResourceFetchTag(statsCategory: .image)) + |> mapError { _ -> StandaloneSendMessageError in return .generic } |> map { next -> UploadMediaEvent in switch next { case let .inputFile(inputFile): - return .result(Api.InputMedia.inputMediaUploadedPhoto(flags: 0, file: inputFile, caption: text, stickers: nil)) + return .result(Api.InputMedia.inputMediaUploadedPhoto(flags: 0, file: inputFile, caption: text, stickers: nil, ttlSeconds: nil)) case .inputSecretFile: preconditionFailure() case let .progress(progress): @@ -153,16 +156,17 @@ private func uploadedImage(account: Account, text: String, data: Data) -> Signal } } -private func uploadedFile(account: Account, text: String, data: Data, mimeType: String, attributes: [TelegramMediaFileAttribute]) -> Signal { +private func uploadedFile(account: Account, text: String, data: Data, mimeType: String, attributes: [TelegramMediaFileAttribute]) -> Signal { return multipartUpload(network: account.network, postbox: account.postbox, source: .data(data), encrypt: false, tag: TelegramMediaResourceFetchTag(statsCategory: statsCategoryForFileWithAttributes(attributes))) + |> mapError { _ -> PendingMessageUploadError in return .generic } |> map { next -> UploadMediaEvent in switch next { case let .inputFile(inputFile): - return .result(Api.InputMedia.inputMediaUploadedDocument(flags: 0, file: inputFile, mimeType: mimeType, attributes: inputDocumentAttributesFromFileAttributes(attributes), caption: text, stickers: nil)) + return .result(Api.InputMedia.inputMediaUploadedDocument(flags: 0, file: inputFile, thumb: nil, mimeType: mimeType, attributes: inputDocumentAttributesFromFileAttributes(attributes), caption: text, stickers: nil, ttlSeconds: nil)) case .inputSecretFile: preconditionFailure() case let .progress(progress): return .progress(progress) } - } + } } diff --git a/TelegramCore/StoreMessage_Telegram.swift b/TelegramCore/StoreMessage_Telegram.swift index 8e65cad8e6..48049b2453 100644 --- a/TelegramCore/StoreMessage_Telegram.swift +++ b/TelegramCore/StoreMessage_Telegram.swift @@ -69,7 +69,7 @@ public func tagsForStoreMessage(incoming: Bool, media: [Media], textEntities: [M extension Api.Message { var peerId: PeerId? { switch self { - case let .message(flags, _, fromId, toId, _, _, _, _, _, _, _, _, _, _): + case let .message(flags, _, fromId, toId, _, _, _, _, _, _, _, _, _, _, _): switch toId { case let .peerUser(userId): return PeerId(namespace: Namespaces.Peer.CloudUser, id: (flags & Int32(2)) != 0 ? userId : (fromId ?? userId)) @@ -94,7 +94,7 @@ extension Api.Message { var peerIds: [PeerId] { switch self { - case let .message(flags, _, fromId, toId, fwdFrom, viaBotId, _, _, _, media, _, entities, _, _): + case let .message(flags, _, fromId, toId, fwdFrom, viaBotId, _, _, _, media, _, entities, _, _, _): let peerId: PeerId switch toId { case let .peerUser(userId): @@ -113,7 +113,7 @@ extension Api.Message { if let fwdFrom = fwdFrom { switch fwdFrom { - case let .messageFwdHeader(_, fromId, _, channelId, _): + case let .messageFwdHeader(_, fromId, _, channelId, _, _): if let channelId = channelId { result.append(PeerId(namespace: Namespaces.Peer.CloudChannel, id: channelId)) } @@ -201,7 +201,7 @@ extension Api.Message { var associatedMessageIds: [MessageId]? { switch self { - case let .message(flags, _, fromId, toId, _, _, replyToMsgId, _, _, _, _, _, _, _): + case let .message(flags, _, fromId, toId, _, _, replyToMsgId, _, _, _, _, _, _, _, _): if let replyToMsgId = replyToMsgId { let peerId: PeerId switch toId { @@ -236,38 +236,45 @@ extension Api.Message { } } -func textAndMediaFromApiMedia(_ media: Api.MessageMedia?, _ peerId:PeerId) -> (String?, Media?) { +func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerId:PeerId) -> (String?, Media?, Int32?) { if let media = media { switch media { - case let .messageMediaPhoto(photo, caption): - if let mediaImage = telegramMediaImageFromApiPhoto(photo) { - return (caption, mediaImage) + case let .messageMediaPhoto(_, photo, caption, ttlSeconds): + if let photo = photo { + if let mediaImage = telegramMediaImageFromApiPhoto(photo) { + return (caption, mediaImage, ttlSeconds) + } + } else { + return (nil, TelegramMediaExpiredContent(data: .image), nil) } - break case let .messageMediaContact(phoneNumber, firstName, lastName, userId): let contactPeerId: PeerId? = userId == 0 ? nil : PeerId(namespace: Namespaces.Peer.CloudUser, id: userId) let mediaContact = TelegramMediaContact(firstName: firstName, lastName: lastName, phoneNumber: phoneNumber, peerId: contactPeerId) - return (nil, mediaContact) + return (nil, mediaContact, nil) case let .messageMediaGeo(geo): let mediaMap = telegramMediaMapFromApiGeoPoint(geo, title: nil, address: nil, provider: nil, venueId: nil) - return (nil, mediaMap) + return (nil, mediaMap, nil) case let .messageMediaVenue(geo, title, address, provider, venueId): let mediaMap = telegramMediaMapFromApiGeoPoint(geo, title: title, address: address, provider: provider, venueId: venueId) - return (nil, mediaMap) - case let .messageMediaDocument(document, caption): - if let mediaFile = telegramMediaFileFromApiDocument(document) { - return (caption, mediaFile) + return (nil, mediaMap, nil) + case let .messageMediaDocument(_, document, caption, ttlSeconds): + if let document = document { + if let mediaFile = telegramMediaFileFromApiDocument(document) { + return (caption, mediaFile, ttlSeconds) + } + } else { + return (nil, TelegramMediaExpiredContent(data: .file), nil) } case let .messageMediaWebPage(webpage): if let mediaWebpage = telegramMediaWebpageFromApiWebpage(webpage) { - return (nil, mediaWebpage) + return (nil, mediaWebpage, nil) } case .messageMediaUnsupported: - return (nil, TelegramMediaUnsupported()) + return (nil, TelegramMediaUnsupported(), nil) case .messageMediaEmpty: break case let .messageMediaGame(game): - return (nil, TelegramMediaGame(apiGame: game)) + return (nil, TelegramMediaGame(apiGame: game), nil) case let .messageMediaInvoice(flags, title, description, photo, receiptMsgId, currency, totalAmount, startParam): var parsedFlags = TelegramMediaInvoiceFlags() if (flags & (1 << 3)) != 0 { @@ -276,11 +283,11 @@ func textAndMediaFromApiMedia(_ media: Api.MessageMedia?, _ peerId:PeerId) -> (S if (flags & (1 << 1)) != 0 { parsedFlags.insert(.shippingAddressRequested) } - return (nil, TelegramMediaInvoice(title: title, description: description, photo: photo.flatMap(TelegramMediaWebFile.init), receiptMessageId: receiptMsgId.flatMap { MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) }, currency: currency, totalAmount: totalAmount, startParam: startParam, flags: parsedFlags)) + return (nil, TelegramMediaInvoice(title: title, description: description, photo: photo.flatMap(TelegramMediaWebFile.init), receiptMessageId: receiptMsgId.flatMap { MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) }, currency: currency, totalAmount: totalAmount, startParam: startParam, flags: parsedFlags), nil) } } - return (nil, nil) + return (nil, nil, nil) } func messageTextEntitiesFromApiEntities(_ entities: [Api.MessageEntity]) -> [MessageTextEntity] { @@ -319,7 +326,7 @@ func messageTextEntitiesFromApiEntities(_ entities: [Api.MessageEntity]) -> [Mes extension StoreMessage { convenience init?(apiMessage: Api.Message) { switch apiMessage { - case let .message(flags, id, fromId, toId, fwdFrom, viaBotId, replyToMsgId, date, message, media, replyMarkup, entities, views, editDate): + case let .message(flags, id, fromId, toId, fwdFrom, viaBotId, replyToMsgId, date, message, media, replyMarkup, entities, views, editDate, postAuthor): let peerId: PeerId var authorId: PeerId? switch toId { @@ -349,7 +356,7 @@ extension StoreMessage { var forwardInfo: StoreMessageForwardInfo? if let fwdFrom = fwdFrom { switch fwdFrom { - case let .messageFwdHeader(_, fromId, date, channelId, channelPost): + case let .messageFwdHeader(_, fromId, date, channelId, channelPost, postAuthor): var authorId: PeerId? var sourceId: PeerId? var sourceMessageId: MessageId? @@ -367,9 +374,9 @@ extension StoreMessage { } if let authorId = authorId { - forwardInfo = StoreMessageForwardInfo(authorId: authorId, sourceId: sourceId, sourceMessageId: sourceMessageId, date: date) + forwardInfo = StoreMessageForwardInfo(authorId: authorId, sourceId: sourceId, sourceMessageId: sourceMessageId, date: date, authorSignature: postAuthor) } else if let sourceId = sourceId { - forwardInfo = StoreMessageForwardInfo(authorId: sourceId, sourceId: nil, sourceMessageId: sourceMessageId, date: date) + forwardInfo = StoreMessageForwardInfo(authorId: sourceId, sourceId: nil, sourceMessageId: sourceMessageId, date: date, authorSignature: postAuthor) } } } @@ -378,28 +385,44 @@ extension StoreMessage { var medias: [Media] = [] var attributes: [MessageAttribute] = [] + var consumableContent: (Bool, Bool)? = nil + if let media = media { - let (mediaText, mediaValue) = textAndMediaFromApiMedia(media, peerId) + let (mediaText, mediaValue, expirationTimer) = textMediaAndExpirationTimerFromApiMedia(media, peerId) if let mediaText = mediaText { messageText = mediaText } if let mediaValue = mediaValue { medias.append(mediaValue) + + if let expirationTimer = expirationTimer, expirationTimer > 0 { + attributes.append(AutoremoveTimeoutMessageAttribute(timeout: expirationTimer, countdownBeginTime: nil)) + + consumableContent = (true, false) + } } } + if let postAuthor = postAuthor { + attributes.append(AuthorSignatureMessageAttribute(signature: postAuthor)) + } + 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)) + consumableContent = (true, (flags & (1 << 5)) == 0) break } else if file.isInstantVideo { - attributes.append(ConsumableContentMessageAttribute(consumed: (flags & (1 << 5)) == 0)) + consumableContent = (true, (flags & (1 << 5)) == 0) break } } } + if let (value, consumed) = consumableContent, value { + attributes.append(ConsumableContentMessageAttribute(consumed: consumed)) + } + if let viaBotId = viaBotId { attributes.append(InlineBotMessageAttribute(peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: viaBotId))) } diff --git a/TelegramCore/TelegramCorePrivate/module.modulemap b/TelegramCore/TelegramCorePrivate/module.modulemap index 35c9e539a8..043192a38f 100644 --- a/TelegramCore/TelegramCorePrivate/module.modulemap +++ b/TelegramCore/TelegramCorePrivate/module.modulemap @@ -3,5 +3,6 @@ module TelegramCorePrivateModule { header "../../third-party/libphonenumber-iOS/NBPhoneNumberUtil.h" header "../../third-party/libphonenumber-iOS/NBAsYouTypeFormatter.h" header "../NetworkLogging.h" + header "../MonotonicTime.h" header "../TelegramCoreIncludes.h" } diff --git a/TelegramCore/TelegramMediaExpiredContent.swift b/TelegramCore/TelegramMediaExpiredContent.swift new file mode 100644 index 0000000000..0854dad348 --- /dev/null +++ b/TelegramCore/TelegramMediaExpiredContent.swift @@ -0,0 +1,38 @@ +import Foundation +#if os(macOS) + import PostboxMac +#else + import Postbox +#endif + +public enum TelegramMediaExpiredContentData: Int32 { + case image + case file +} + +public final class TelegramMediaExpiredContent: Media { + public let data: TelegramMediaExpiredContentData + + public let id: MediaId? = nil + public let peerIds: [PeerId] = [] + + public init(data: TelegramMediaExpiredContentData) { + self.data = data + } + + public init(decoder: Decoder) { + self.data = TelegramMediaExpiredContentData(rawValue: decoder.decodeInt32ForKey("d", orElse: 0))! + } + + public func encode(_ encoder: Encoder) { + encoder.encodeInt32(self.data.rawValue, forKey: "d") + } + + public func isEqual(_ other: Media) -> Bool { + if let other = other as? TelegramMediaExpiredContent { + return self.data == other.data + } else { + return false + } + } +} diff --git a/TelegramCore/TelegramMediaImage.swift b/TelegramCore/TelegramMediaImage.swift index 3c210824f2..b90572e281 100644 --- a/TelegramCore/TelegramMediaImage.swift +++ b/TelegramCore/TelegramMediaImage.swift @@ -136,7 +136,7 @@ public func telegramMediaImageRepresentationsFromApiSizes(_ sizes: [Api.PhotoSiz public func telegramMediaImageFromApiPhoto(_ photo: Api.Photo) -> TelegramMediaImage? { switch photo { - case let .photo(flags, id, accessHash, date, sizes): + case let .photo(_, id, accessHash, _, sizes): return TelegramMediaImage(imageId: MediaId(namespace: Namespaces.Media.CloudImage, id: id), representations: telegramMediaImageRepresentationsFromApiSizes(sizes)) case .photoEmpty: return nil diff --git a/TelegramCore/TogglePeerChatPinned.swift b/TelegramCore/TogglePeerChatPinned.swift index 2936ad6e67..1b5e314943 100644 --- a/TelegramCore/TogglePeerChatPinned.swift +++ b/TelegramCore/TogglePeerChatPinned.swift @@ -7,15 +7,26 @@ import Foundation import SwiftSignalKit #endif -public func togglePeerChatPinned(postbox: Postbox, peerId: PeerId) -> Signal { - return postbox.modify { modifier -> Void in +public enum TogglePeerChatPinnedResult { + case done + case limitExceeded +} + +public func togglePeerChatPinned(postbox: Postbox, peerId: PeerId) -> Signal { + return postbox.modify { modifier -> TogglePeerChatPinnedResult in var peerIds = modifier.getPinnedPeerIds() - if let index = peerIds.index(of: peerId) { - peerIds.remove(at: index) + let sameKind = peerIds.filter { ($0.namespace == Namespaces.Peer.SecretChat) == (peerId.namespace == Namespaces.Peer.SecretChat) } + if sameKind.count + 1 > 5 { + return .limitExceeded } else { - peerIds.insert(peerId, at: 0) + if let index = peerIds.index(of: peerId) { + peerIds.remove(at: index) + } else { + peerIds.insert(peerId, at: 0) + } + modifier.setPinnedPeerIds(peerIds) + addSynchronizePinnedChatsOperation(modifier: modifier) + return .done } - modifier.setPinnedPeerIds(peerIds) - addSynchronizePinnedChatsOperation(modifier: modifier) } } diff --git a/TelegramCore/TwoStepVerification.swift b/TelegramCore/TwoStepVerification.swift index 1afb79650a..d9f7c7c1a9 100644 --- a/TelegramCore/TwoStepVerification.swift +++ b/TelegramCore/TwoStepVerification.swift @@ -235,3 +235,79 @@ public func recoverTwoStepVerificationPassword(account: Account, code: String) - return .complete() } } + +public struct TemporaryTwoStepPasswordToken: Coding, Equatable { + public let token: Data + public let validUntilDate: Int32 + public let requiresBiometrics: Bool + + public init(token: Data, validUntilDate: Int32, requiresBiometrics: Bool) { + self.token = token + self.validUntilDate = validUntilDate + self.requiresBiometrics = requiresBiometrics + } + + public init(decoder: Decoder) { + self.token = decoder.decodeBytesForKey("t")!.makeData() + self.validUntilDate = decoder.decodeInt32ForKey("d", orElse: 0) + self.requiresBiometrics = decoder.decodeInt32ForKey("b", orElse: 0) != 0 + } + + public func encode(_ encoder: Encoder) { + encoder.encodeBytes(MemoryBuffer(data: self.token), forKey: "t") + encoder.encodeInt32(self.validUntilDate, forKey: "d") + encoder.encodeInt32(self.requiresBiometrics ? 1 : 0, forKey: "b") + } + + public static func ==(lhs: TemporaryTwoStepPasswordToken, rhs: TemporaryTwoStepPasswordToken) -> Bool { + return lhs.token == rhs.token && lhs.validUntilDate == rhs.validUntilDate && lhs.requiresBiometrics == rhs.requiresBiometrics + } +} + +public func cachedTwoStepPasswordToken(postbox: Postbox) -> Signal { + return postbox.modify { modifier -> TemporaryTwoStepPasswordToken? in + let key = ValueBoxKey(length: 1) + key.setUInt8(0, value: 0) + return modifier.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedTwoStepToken, key: key)) as? TemporaryTwoStepPasswordToken + } +} + +public func cacheTwoStepPasswordToken(postbox: Postbox, token: TemporaryTwoStepPasswordToken?) -> Signal { + return postbox.modify { modifier -> Void in + let key = ValueBoxKey(length: 1) + key.setUInt8(0, value: 0) + if let token = token { + modifier.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedTwoStepToken, key: key), entry: token, collectionSpec: ItemCacheCollectionSpec(lowWaterItemCount: 1, highWaterItemCount: 1)) + } else { + modifier.removeItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedTwoStepToken, key: key)) + } + } +} + +public func requestTemporaryTwoStepPasswordToken(account: Account, password: String, period: Int32, requiresBiometrics: Bool) -> Signal { + return twoStepAuthData(account.network) + |> mapToSignal { authData -> Signal in + var data = Data() + data.append(authData.currentSalt!) + data.append(password.data(using: .utf8, allowLossyConversion: true)!) + data.append(authData.currentSalt!) + let currentPasswordHash = sha256Digest(data) + + return account.network.request(Api.functions.account.getTmpPassword(passwordHash: Buffer(data: currentPasswordHash), period: period), automaticFloodWait: false) + |> map { result -> TemporaryTwoStepPasswordToken in + switch result { + case let .tmpPassword(tmpPassword, validUntil): + return TemporaryTwoStepPasswordToken(token: tmpPassword.makeData(), validUntilDate: validUntil, requiresBiometrics: requiresBiometrics) + } + } + } + |> `catch` { error -> Signal in + if error.errorDescription.hasPrefix("FLOOD_WAIT") { + return .fail(.limitExceeded) + } else if error.errorDescription == "PASSWORD_HASH_INVALID" { + return .fail(.invalidPassword) + } else { + return .fail(.generic) + } + } +} diff --git a/TelegramCore/Unixtime.swift b/TelegramCore/Unixtime.swift index c507b4cf2a..090a84723b 100644 --- a/TelegramCore/Unixtime.swift +++ b/TelegramCore/Unixtime.swift @@ -124,5 +124,3 @@ public func secondsSinceEpochToDateTime(_ secondsSinceEpoch: Int64) -> DateTime return DateTime(seconds: Int32(sec), minutes: Int32(min), hours: Int32(hour), dayOfMonth: Int32(mday), month: Int32(month - 1), year: Int32(year - 1900), dayOfWeek: Int32(wday), dayOfYear: Int32(yday)) } - - diff --git a/TelegramCore/UpdateContactName.swift b/TelegramCore/UpdateContactName.swift index be728ed8db..ec1b0aa210 100644 --- a/TelegramCore/UpdateContactName.swift +++ b/TelegramCore/UpdateContactName.swift @@ -23,7 +23,7 @@ public func updateContactName(account: Account, peerId: PeerId, firstName: Strin |> mapToSignal { result -> Signal in return account.postbox.modify { modifier -> Void in switch result { - case let .importedContacts(_, _, users): + case let .importedContacts(_, _, _, users): if let first = users.first { let user = TelegramUser(user: first) updatePeers(modifier: modifier, peers: [user], update: { _, updated in diff --git a/TelegramCore/UpdateMessageService.swift b/TelegramCore/UpdateMessageService.swift index 26bea42afe..8d75f7397e 100644 --- a/TelegramCore/UpdateMessageService.swift +++ b/TelegramCore/UpdateMessageService.swift @@ -63,7 +63,7 @@ class UpdateMessageService: NSObject, MTMessageService { self.putNext(groups) } case let .updateShortChatMessage(flags, id, fromId, chatId, message, pts, ptsCount, date, fwdFrom, viaBotId, replyToMsgId, entities): - let generatedMessage = Api.Message.message(flags: flags, id: id, fromId: fromId, toId: Api.Peer.peerChat(chatId: chatId), fwdFrom: fwdFrom, viaBotId: viaBotId, replyToMsgId: replyToMsgId, date: date, message: message, media: Api.MessageMedia.messageMediaEmpty, replyMarkup: nil, entities: entities, views: nil, editDate: nil) + let generatedMessage = Api.Message.message(flags: flags, id: id, fromId: fromId, toId: Api.Peer.peerChat(chatId: chatId), fwdFrom: fwdFrom, viaBotId: viaBotId, replyToMsgId: replyToMsgId, date: date, message: message, media: Api.MessageMedia.messageMediaEmpty, replyMarkup: nil, entities: entities, views: nil, editDate: nil, postAuthor: nil) let update = Api.Update.updateNewMessage(message: generatedMessage, pts: pts, ptsCount: ptsCount) let groups = groupUpdates([update], users: [], chats: [], date: date, seqRange: nil) if groups.count != 0 { @@ -80,7 +80,7 @@ class UpdateMessageService: NSObject, MTMessageService { generatedToId = Api.Peer.peerUser(userId: self.peerId.id) } - let generatedMessage = Api.Message.message(flags: flags, id: id, fromId: generatedFromId, toId: generatedToId, fwdFrom: fwdFrom, viaBotId: viaBotId, replyToMsgId: replyToMsgId, date: date, message: message, media: Api.MessageMedia.messageMediaEmpty, replyMarkup: nil, entities: entities, views: nil, editDate: nil) + let generatedMessage = Api.Message.message(flags: flags, id: id, fromId: generatedFromId, toId: generatedToId, fwdFrom: fwdFrom, viaBotId: viaBotId, replyToMsgId: replyToMsgId, date: date, message: message, media: Api.MessageMedia.messageMediaEmpty, replyMarkup: nil, entities: entities, views: nil, editDate: nil, postAuthor: nil) let update = Api.Update.updateNewMessage(message: generatedMessage, pts: pts, ptsCount: ptsCount) let groups = groupUpdates([update], users: [], chats: [], date: date, seqRange: nil) if groups.count != 0 { diff --git a/TelegramCore/UpdatesApiUtils.swift b/TelegramCore/UpdatesApiUtils.swift index c6b52294cd..6b626b6a5f 100644 --- a/TelegramCore/UpdatesApiUtils.swift +++ b/TelegramCore/UpdatesApiUtils.swift @@ -8,34 +8,40 @@ import Foundation extension Api.MessageMedia { var preCachedResources: [(MediaResource, Data)]? { switch self { - case let .messageMediaPhoto(photo, _): - switch photo { - case let .photo(_, _, _, _, sizes): - for size in sizes { - switch size { - case let .photoCachedSize(_, location, _, _, bytes): - switch location { - case let .fileLocation(dcId, volumeId, localId, secret): - let data = bytes.makeData() - let resource = CloudFileMediaResource(datacenterId: Int(dcId), volumeId: volumeId, localId: localId, secret: secret, size: data.count) - return [(resource, data)] - default: - break - } - default: - break + case let .messageMediaPhoto(_, photo, _, _): + if let photo = photo { + switch photo { + case let .photo(_, _, _, _, sizes): + for size in sizes { + switch size { + case let .photoCachedSize(_, location, _, _, bytes): + switch location { + case let .fileLocation(dcId, volumeId, localId, secret): + let data = bytes.makeData() + let resource = CloudFileMediaResource(datacenterId: Int(dcId), volumeId: volumeId, localId: localId, secret: secret, size: data.count) + return [(resource, data)] + default: + break + } + default: + break + } } - } - return nil - default: - return nil + return nil + default: + return nil + } + } else { + return nil } - case let .messageMediaDocument(document, _): - switch document { - case .document: - break - default: - break + case let .messageMediaDocument(_, document, _, _): + if let document = document { + switch document { + case .document: + break + default: + break + } } return nil default: @@ -47,7 +53,7 @@ extension Api.MessageMedia { extension Api.Message { var rawId: Int32 { switch self { - case let .message(_, id, _, _, _, _, _, _, _, _, _, _, _, _): + case let .message(_, id, _, _, _, _, _, _, _, _, _, _, _, _, _): return id case let .messageEmpty(id): return id @@ -58,7 +64,7 @@ extension Api.Message { var id: MessageId? { switch self { - case let .message(flags, id, fromId, toId, _, _, _, _, _, _, _, _, _, _): + case let .message(flags, id, fromId, toId, _, _, _, _, _, _, _, _, _, _, _): let peerId: PeerId switch toId { case let .peerUser(userId): @@ -88,7 +94,7 @@ extension Api.Message { var timestamp: Int32? { switch self { - case let .message(_, _, _, _, _, _, _, date, _, _, _, _, _, _): + case let .message(_, _, _, _, _, _, _, date, _, _, _, _, _, _, _): return date case let .messageService(_, _, _, _, _, date, _): return date @@ -99,7 +105,7 @@ extension Api.Message { var preCachedResources: [(MediaResource, Data)]? { switch self { - case let .message(_, _, _, _, _, _, _, _, _, media, _, _, _, _): + case let .message(_, _, _, _, _, _, _, _, _, media, _, _, _, _, _): return media?.preCachedResources default: return nil