diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index d58bad3917..e11594b422 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -244,7 +244,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController private var powerSavingMonitoringDisposable: Disposable? - public private(set) var storyListContext: StoryListContext? private var storySubscriptions: EngineStorySubscriptions? private var storySubscriptionsDisposable: Disposable? @@ -2543,204 +2542,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController ) self.push(storyContainerScreen) }) - - /*let storyFocusContext = self.context.engine.messages.peerStoryFocusContext(id: peer.id, focusItemId: nil) - - let _ = (storyFocusContext.state - |> filter { state -> Bool in - if state.isLoading { - return false - } else { - return true - } - } - |> take(1) - |> deliverOnMainQueue).start(next: { [weak self] state in - guard let self else { - return - } - let _ = storyFocusContext - let _ = self - - if let item = state.item { - let _ = item - - let _ = (StoryChatContent.subscriptionsStories( - context: self.context, - peerId: peer.id - ) - |> take(1) - |> deliverOnMainQueue).start(next: { [weak self] initialContent in - guard let self else { - return - } - - var transitionIn: StoryContainerScreen.TransitionIn? - if let componentView = self.headerContentView.view as? ChatListHeaderComponent.View { - if let transitionView = componentView.storyPeerListView()?.transitionViewForItem(peerId: peer.id) { - transitionIn = StoryContainerScreen.TransitionIn( - sourceView: transitionView, - sourceRect: transitionView.bounds, - sourceCornerRadius: transitionView.bounds.height * 0.5 - ) - } - } - - var cameraTransitionIn: StoryCameraTransitionIn? - if let componentView = self.headerContentView.view as? ChatListHeaderComponent.View { - if let transitionView = componentView.storyPeerListView()?.transitionViewForItem(peerId: self.context.account.peerId) { - cameraTransitionIn = StoryCameraTransitionIn( - sourceView: transitionView, - sourceRect: transitionView.bounds, - sourceCornerRadius: transitionView.bounds.height * 0.5 - ) - } - } - - var initialFocusedId: AnyHashable? - //if let peer { - initialFocusedId = AnyHashable(peer.id) - //} - - if initialFocusedId == AnyHashable(self.context.account.peerId), let firstItem = initialContent.first, firstItem.id == initialFocusedId && firstItem.items.isEmpty { - if let rootController = self.context.sharedContext.mainWindow?.viewController as? TelegramRootControllerInterface { - rootController.openStoryCamera(transitionIn: cameraTransitionIn, transitionOut: { [weak self] _ in - guard let self else { - return nil - } - if let componentView = self.headerContentView.view as? ChatListHeaderComponent.View { - if let transitionView = componentView.storyPeerListView()?.transitionViewForItem(peerId: self.context.account.peerId) { - return StoryCameraTransitionOut( - destinationView: transitionView, - destinationRect: transitionView.bounds, - destinationCornerRadius: transitionView.bounds.height * 0.5 - ) - } - } - return nil - }) - } - - return - } - - let storyContainerScreen = StoryContainerScreen( - context: self.context, - initialFocusedId: initialFocusedId, - initialContent: initialContent, - transitionIn: transitionIn, - transitionOut: { [weak self] peerId, _ in - guard let self else { - return nil - } - - if let componentView = self.headerContentView.view as? ChatListHeaderComponent.View { - if let transitionView = componentView.storyPeerListView()?.transitionViewForItem(peerId: peerId) { - return StoryContainerScreen.TransitionOut( - destinationView: transitionView, - destinationRect: transitionView.bounds, - destinationCornerRadius: transitionView.bounds.height * 0.5, - destinationIsAvatar: true, - completed: {} - ) - } - } - - return nil - } - ) - self.push(storyContainerScreen) - }) - } - })*/ - - /*let _ = (StoryChatContent.stories( - context: self.context, - storyList: storyListContext, - focusItem: nil - ) - |> take(1) - |> deliverOnMainQueue).start(next: { [weak self] initialContent in - guard let self else { - return - } - - var transitionIn: StoryContainerScreen.TransitionIn? - if let peer, let componentView = self.headerContentView.view as? ChatListHeaderComponent.View { - if let transitionView = componentView.storyPeerListView()?.transitionViewForItem(peerId: peer.id) { - transitionIn = StoryContainerScreen.TransitionIn( - sourceView: transitionView, - sourceRect: transitionView.bounds, - sourceCornerRadius: transitionView.bounds.height * 0.5 - ) - } - } - - var cameraTransitionIn: StoryCameraTransitionIn? - if let componentView = self.headerContentView.view as? ChatListHeaderComponent.View { - if let transitionView = componentView.storyPeerListView()?.transitionViewForItem(peerId: self.context.account.peerId) { - cameraTransitionIn = StoryCameraTransitionIn( - sourceView: transitionView, - sourceRect: transitionView.bounds, - sourceCornerRadius: transitionView.bounds.height * 0.5 - ) - } - } - - var initialFocusedId: AnyHashable? - if let peer { - initialFocusedId = AnyHashable(peer.id) - } - - if initialFocusedId == AnyHashable(self.context.account.peerId), let firstItem = initialContent.first, firstItem.id == initialFocusedId && firstItem.items.isEmpty { - if let rootController = self.context.sharedContext.mainWindow?.viewController as? TelegramRootControllerInterface { - rootController.openStoryCamera(transitionIn: cameraTransitionIn, transitionOut: { [weak self] _ in - guard let self else { - return nil - } - if let componentView = self.headerContentView.view as? ChatListHeaderComponent.View { - if let transitionView = componentView.storyPeerListView()?.transitionViewForItem(peerId: self.context.account.peerId) { - return StoryCameraTransitionOut( - destinationView: transitionView, - destinationRect: transitionView.bounds, - destinationCornerRadius: transitionView.bounds.height * 0.5 - ) - } - } - return nil - }) - } - - return - } - - let storyContainerScreen = StoryContainerScreen( - context: self.context, - initialFocusedId: initialFocusedId, - initialContent: initialContent, - transitionIn: transitionIn, - transitionOut: { [weak self] peerId, _ in - guard let self else { - return nil - } - - if let componentView = self.headerContentView.view as? ChatListHeaderComponent.View { - if let transitionView = componentView.storyPeerListView()?.transitionViewForItem(peerId: peerId) { - return StoryContainerScreen.TransitionOut( - destinationView: transitionView, - destinationRect: transitionView.bounds, - destinationCornerRadius: transitionView.bounds.height * 0.5, - destinationIsAvatar: true, - completed: {} - ) - } - } - - return nil - } - ) - self.push(storyContainerScreen) - })*/ } let fraction = 94.0 / (navigationBarSearchContentHeight + 94.0) diff --git a/submodules/DirectMediaImageCache/Sources/DirectMediaImageCache.swift b/submodules/DirectMediaImageCache/Sources/DirectMediaImageCache.swift index 9483811d6a..00fc79847d 100644 --- a/submodules/DirectMediaImageCache/Sources/DirectMediaImageCache.swift +++ b/submodules/DirectMediaImageCache/Sources/DirectMediaImageCache.swift @@ -351,11 +351,11 @@ public final class DirectMediaImageCache { return self.getProgressiveSize(mediaReference: MediaReference.message(message: MessageReference(message), media: file).abstract, width: width, representations: file.previewRepresentations) } - private func getResource(peer: PeerReference, story: StoryListContext.Item, image: TelegramMediaImage, width: Int) -> (resource: MediaResourceReference, size: Int64)? { + private func getResource(peer: PeerReference, story: EngineStoryItem, image: TelegramMediaImage, width: Int) -> (resource: MediaResourceReference, size: Int64)? { return self.getProgressiveSize(mediaReference: MediaReference.story(peer: peer, id: story.id, media: image).abstract, width: width, representations: image.representations) } - private func getResource(peer: PeerReference, story: StoryListContext.Item, file: TelegramMediaFile, width: Int) -> (resource: MediaResourceReference, size: Int64)? { + private func getResource(peer: PeerReference, story: EngineStoryItem, file: TelegramMediaFile, width: Int) -> (resource: MediaResourceReference, size: Int64)? { return self.getProgressiveSize(mediaReference: MediaReference.story(peer: peer, id: story.id, media: file).abstract, width: width, representations: file.previewRepresentations) } @@ -445,7 +445,7 @@ public final class DirectMediaImageCache { } } - private func getImageSynchronous(peer: PeerReference, story: StoryListContext.Item, userLocation: MediaResourceUserLocation, media: Media, width: Int, aspectRatio: CGFloat, possibleWidths: [Int], includeBlurred: Bool) -> GetMediaResult? { + private func getImageSynchronous(peer: PeerReference, story: EngineStoryItem, userLocation: MediaResourceUserLocation, media: Media, width: Int, aspectRatio: CGFloat, possibleWidths: [Int], includeBlurred: Bool) -> GetMediaResult? { var immediateThumbnailData: Data? var resource: (resource: MediaResourceReference, size: Int64)? if let image = media as? TelegramMediaImage { @@ -492,7 +492,7 @@ public final class DirectMediaImageCache { return GetMediaResult(image: resultImage, blurredImage: blurredImage, loadSignal: self.getLoadSignal(width: width, aspectRatio: aspectRatio, userLocation: userLocation, userContentType: .image, resource: resource.resource, resourceSizeLimit: resource.size)) } - public func getImage(peer: PeerReference, story: StoryListContext.Item, media: Media, width: Int, aspectRatio: CGFloat, possibleWidths: [Int], includeBlurred: Bool = false, synchronous: Bool) -> GetMediaResult? { + public func getImage(peer: PeerReference, story: EngineStoryItem, media: Media, width: Int, aspectRatio: CGFloat, possibleWidths: [Int], includeBlurred: Bool = false, synchronous: Bool) -> GetMediaResult? { if synchronous { return self.getImageSynchronous(peer: peer, story: story, userLocation: .peer(peer.id), media: media, width: width, aspectRatio: aspectRatio, possibleWidths: possibleWidths, includeBlurred: includeBlurred) } else { diff --git a/submodules/FFMpegBinding/Sources/FFMpegAVIOContext.m b/submodules/FFMpegBinding/Sources/FFMpegAVIOContext.m index 8f76b54667..6a0cc03e29 100644 --- a/submodules/FFMpegBinding/Sources/FFMpegAVIOContext.m +++ b/submodules/FFMpegBinding/Sources/FFMpegAVIOContext.m @@ -15,11 +15,12 @@ if (self != nil) { void *avIoBuffer = av_malloc(bufferSize); _impl = avio_alloc_context(avIoBuffer, bufferSize, 0, opaqueContext, readPacket, writePacket, seek); - _impl->direct = 1; if (_impl == nil) { av_free(avIoBuffer); return nil; } + _impl->direct = 1; + _impl->seekable = 0; } return self; } diff --git a/submodules/MediaPlayer/Sources/FFMpegMediaFrameSourceContext.swift b/submodules/MediaPlayer/Sources/FFMpegMediaFrameSourceContext.swift index 21edfd4cec..a4e303532e 100644 --- a/submodules/MediaPlayer/Sources/FFMpegMediaFrameSourceContext.swift +++ b/submodules/MediaPlayer/Sources/FFMpegMediaFrameSourceContext.swift @@ -95,6 +95,9 @@ private func readPacketCallback(userData: UnsafeMutableRawPointer?, buffer: Unsa if readCount == 0 { fetchedData = Data() } else { + #if DEBUG + print("requestRange: \(requestRange)") + #endif if let tempFilePath = context.tempFilePath, let fileData = (try? Data(contentsOf: URL(fileURLWithPath: tempFilePath), options: .mappedRead))?.subdata(in: Int(requestRange.lowerBound) ..< Int(requestRange.upperBound)) { fetchedData = fileData } else { diff --git a/submodules/MediaPlayer/Sources/MediaPlayer.swift b/submodules/MediaPlayer/Sources/MediaPlayer.swift index 289c4fd83a..aeebddf5a7 100644 --- a/submodules/MediaPlayer/Sources/MediaPlayer.swift +++ b/submodules/MediaPlayer/Sources/MediaPlayer.swift @@ -85,7 +85,7 @@ public enum MediaPlayerStreaming { case .earlierStart: return (1.0, 1.0, 2.0) case .story: - return (0.25, 0.5, 2.0) + return (0.25, 0.5, 0.5) } } } diff --git a/submodules/MediaPlayer/Sources/MediaTrackFrameBuffer.swift b/submodules/MediaPlayer/Sources/MediaTrackFrameBuffer.swift index 49b3764921..f9fbca1118 100644 --- a/submodules/MediaPlayer/Sources/MediaTrackFrameBuffer.swift +++ b/submodules/MediaPlayer/Sources/MediaTrackFrameBuffer.swift @@ -16,7 +16,13 @@ public enum MediaTrackFrameResult { case finished } -private let traceEvents = false +private let traceEvents: Bool = { + #if DEBUG + return true + #else + return false + #endif +}() public final class MediaTrackFrameBuffer { private let stallDuration: Double @@ -89,7 +95,7 @@ public final class MediaTrackFrameBuffer { if let maxUntilTime = maxUntilTime { if traceEvents { - print("added \(frames.count) frames until \(CMTimeGetSeconds(maxUntilTime)), \(self.frames.count) total") + print("\(self.type) added \(frames.count) frames until \(CMTimeGetSeconds(maxUntilTime)), \(self.frames.count) total") } } @@ -123,7 +129,7 @@ public final class MediaTrackFrameBuffer { if bufferedDuration < self.lowWaterDuration { if traceEvents { - print("buffered duration: \(bufferedDuration), requesting until \(timestamp) + \(self.highWaterDuration - bufferedDuration)") + print("\(self.type) buffered duration: \(bufferedDuration), requesting until \(timestamp) + \(self.highWaterDuration - bufferedDuration)") } let delayIncrement = 0.3 var generateUntil = timestamp + delayIncrement @@ -134,7 +140,7 @@ public final class MediaTrackFrameBuffer { if bufferedDuration > self.stallDuration && !self.isWaitingForLowWaterDuration { if traceEvents { - print("buffered1 duration: \(bufferedDuration), wait until \(timestamp) + \(self.highWaterDuration - bufferedDuration)") + print("\(self.type) buffered1 duration: \(bufferedDuration), wait until \(timestamp) + \(self.highWaterDuration - bufferedDuration)") } return .full(until: timestamp + self.highWaterDuration) } else { @@ -144,7 +150,7 @@ public final class MediaTrackFrameBuffer { } else { self.isWaitingForLowWaterDuration = false if traceEvents { - print("buffered2 duration: \(bufferedDuration), wait until \(timestamp) + \(bufferedDuration - self.lowWaterDuration)") + print("\(self.type) buffered2 duration: \(bufferedDuration), wait until \(timestamp) + \(bufferedDuration - self.lowWaterDuration)") } return .full(until: timestamp + max(0.0, bufferedDuration - self.lowWaterDuration)) } diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index 877bf9e25e..a7eed89b13 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -382,6 +382,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-380694650] = { return Api.InputPrivacyRule.parse_inputPrivacyValueDisallowChatParticipants($0) } dict[195371015] = { return Api.InputPrivacyRule.parse_inputPrivacyValueDisallowContacts($0) } dict[-1877932953] = { return Api.InputPrivacyRule.parse_inputPrivacyValueDisallowUsers($0) } + dict[-1672247580] = { return Api.InputReplyTo.parse_inputReplyToMessage($0) } + dict[-1139169566] = { return Api.InputReplyTo.parse_inputReplyToStory($0) } dict[1399317950] = { return Api.InputSecureFile.parse_inputSecureFile($0) } dict[859091184] = { return Api.InputSecureFile.parse_inputSecureFileUploaded($0) } dict[-618540889] = { return Api.InputSecureValue.parse_inputSecureValue($0) } @@ -535,6 +537,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1328256121] = { return Api.MessageReactions.parse_messageReactions($0) } dict[-2083123262] = { return Api.MessageReplies.parse_messageReplies($0) } dict[-1495959709] = { return Api.MessageReplyHeader.parse_messageReplyHeader($0) } + dict[-1667711039] = { return Api.MessageReplyHeader.parse_messageReplyStoryHeader($0) } dict[1163625789] = { return Api.MessageViews.parse_messageViews($0) } dict[975236280] = { return Api.MessagesFilter.parse_inputMessagesFilterChatPhotos($0) } dict[-530392189] = { return Api.MessagesFilter.parse_inputMessagesFilterContacts($0) } @@ -790,7 +793,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1374088783] = { return Api.StoryItem.parse_storyItemDeleted($0) } dict[-1579626609] = { return Api.StoryItem.parse_storyItemSkipped($0) } dict[-1491424062] = { return Api.StoryView.parse_storyView($0) } - dict[1368082392] = { return Api.StoryViews.parse_storyViews($0) } + dict[-748199729] = { return Api.StoryViews.parse_storyViews($0) } dict[1964978502] = { return Api.TextWithEntities.parse_textWithEntities($0) } dict[-1609668650] = { return Api.Theme.parse_theme($0) } dict[-94849324] = { return Api.ThemeSettings.parse_themeSettings($0) } @@ -1155,7 +1158,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[172975040] = { return Api.storage.FileType.parse_filePng($0) } dict[-1432995067] = { return Api.storage.FileType.parse_fileUnknown($0) } dict[276907596] = { return Api.storage.FileType.parse_fileWebp($0) } - dict[1528473228] = { return Api.stories.AllStories.parse_allStories($0) } + dict[-2086796248] = { return Api.stories.AllStories.parse_allStories($0) } dict[1205903486] = { return Api.stories.AllStories.parse_allStoriesNotModified($0) } dict[1340440049] = { return Api.stories.Stories.parse_stories($0) } dict[-560009955] = { return Api.stories.StoryViews.parse_storyViews($0) } @@ -1479,6 +1482,8 @@ public extension Api { _1.serialize(buffer, boxed) case let _1 as Api.InputPrivacyRule: _1.serialize(buffer, boxed) + case let _1 as Api.InputReplyTo: + _1.serialize(buffer, boxed) case let _1 as Api.InputSecureFile: _1.serialize(buffer, boxed) case let _1 as Api.InputSecureValue: diff --git a/submodules/TelegramApi/Sources/Api10.swift b/submodules/TelegramApi/Sources/Api10.swift index 22bf87c5cb..a82c2e4600 100644 --- a/submodules/TelegramApi/Sources/Api10.swift +++ b/submodules/TelegramApi/Sources/Api10.swift @@ -1,3 +1,77 @@ +public extension Api { + indirect enum InputReplyTo: TypeConstructorDescription { + case inputReplyToMessage(flags: Int32, replyToMsgId: Int32, topMsgId: Int32?) + case inputReplyToStory(flags: Int32, userId: Api.InputUser, storyId: Int32) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .inputReplyToMessage(let flags, let replyToMsgId, let topMsgId): + if boxed { + buffer.appendInt32(-1672247580) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(replyToMsgId, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {serializeInt32(topMsgId!, buffer: buffer, boxed: false)} + break + case .inputReplyToStory(let flags, let userId, let storyId): + if boxed { + buffer.appendInt32(-1139169566) + } + serializeInt32(flags, buffer: buffer, boxed: false) + userId.serialize(buffer, true) + serializeInt32(storyId, buffer: buffer, boxed: false) + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .inputReplyToMessage(let flags, let replyToMsgId, let topMsgId): + return ("inputReplyToMessage", [("flags", flags as Any), ("replyToMsgId", replyToMsgId as Any), ("topMsgId", topMsgId as Any)]) + case .inputReplyToStory(let flags, let userId, let storyId): + return ("inputReplyToStory", [("flags", flags as Any), ("userId", userId as Any), ("storyId", storyId as Any)]) + } + } + + public static func parse_inputReplyToMessage(_ reader: BufferReader) -> InputReplyTo? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: Int32? + if Int(_1!) & Int(1 << 0) != 0 {_3 = reader.readInt32() } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil + if _c1 && _c2 && _c3 { + return Api.InputReplyTo.inputReplyToMessage(flags: _1!, replyToMsgId: _2!, topMsgId: _3) + } + else { + return nil + } + } + public static func parse_inputReplyToStory(_ reader: BufferReader) -> InputReplyTo? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.InputUser? + if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.InputUser + } + var _3: Int32? + _3 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + if _c1 && _c2 && _c3 { + return Api.InputReplyTo.inputReplyToStory(flags: _1!, userId: _2!, storyId: _3!) + } + else { + return nil + } + } + + } +} public extension Api { enum InputSecureFile: TypeConstructorDescription { case inputSecureFile(id: Int64, accessHash: Int64) @@ -932,119 +1006,3 @@ public extension Api { } } -public extension Api { - enum InputWebFileLocation: TypeConstructorDescription { - case inputWebFileAudioAlbumThumbLocation(flags: Int32, document: Api.InputDocument?, title: String?, performer: String?) - case inputWebFileGeoPointLocation(geoPoint: Api.InputGeoPoint, accessHash: Int64, w: Int32, h: Int32, zoom: Int32, scale: Int32) - case inputWebFileLocation(url: String, accessHash: Int64) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .inputWebFileAudioAlbumThumbLocation(let flags, let document, let title, let performer): - if boxed { - buffer.appendInt32(-193992412) - } - 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(title!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 1) != 0 {serializeString(performer!, buffer: buffer, boxed: false)} - break - case .inputWebFileGeoPointLocation(let geoPoint, let accessHash, let w, let h, let zoom, let scale): - if boxed { - buffer.appendInt32(-1625153079) - } - geoPoint.serialize(buffer, true) - serializeInt64(accessHash, buffer: buffer, boxed: false) - serializeInt32(w, buffer: buffer, boxed: false) - serializeInt32(h, buffer: buffer, boxed: false) - serializeInt32(zoom, buffer: buffer, boxed: false) - serializeInt32(scale, buffer: buffer, boxed: false) - break - case .inputWebFileLocation(let url, let accessHash): - if boxed { - buffer.appendInt32(-1036396922) - } - serializeString(url, buffer: buffer, boxed: false) - serializeInt64(accessHash, buffer: buffer, boxed: false) - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .inputWebFileAudioAlbumThumbLocation(let flags, let document, let title, let performer): - return ("inputWebFileAudioAlbumThumbLocation", [("flags", flags as Any), ("document", document as Any), ("title", title as Any), ("performer", performer as Any)]) - case .inputWebFileGeoPointLocation(let geoPoint, let accessHash, let w, let h, let zoom, let scale): - return ("inputWebFileGeoPointLocation", [("geoPoint", geoPoint as Any), ("accessHash", accessHash as Any), ("w", w as Any), ("h", h as Any), ("zoom", zoom as Any), ("scale", scale as Any)]) - case .inputWebFileLocation(let url, let accessHash): - return ("inputWebFileLocation", [("url", url as Any), ("accessHash", accessHash as Any)]) - } - } - - public static func parse_inputWebFileAudioAlbumThumbLocation(_ reader: BufferReader) -> InputWebFileLocation? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Api.InputDocument? - if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { - _2 = Api.parse(reader, signature: signature) as? Api.InputDocument - } } - var _3: String? - if Int(_1!) & Int(1 << 1) != 0 {_3 = parseString(reader) } - var _4: String? - if Int(_1!) & Int(1 << 1) != 0 {_4 = parseString(reader) } - 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 << 1) == 0) || _4 != nil - if _c1 && _c2 && _c3 && _c4 { - return Api.InputWebFileLocation.inputWebFileAudioAlbumThumbLocation(flags: _1!, document: _2, title: _3, performer: _4) - } - else { - return nil - } - } - public static func parse_inputWebFileGeoPointLocation(_ reader: BufferReader) -> InputWebFileLocation? { - var _1: Api.InputGeoPoint? - if let signature = reader.readInt32() { - _1 = Api.parse(reader, signature: signature) as? Api.InputGeoPoint - } - var _2: Int64? - _2 = reader.readInt64() - var _3: Int32? - _3 = reader.readInt32() - var _4: Int32? - _4 = reader.readInt32() - var _5: Int32? - _5 = reader.readInt32() - var _6: Int32? - _6 = reader.readInt32() - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = _3 != nil - let _c4 = _4 != nil - let _c5 = _5 != nil - let _c6 = _6 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 { - return Api.InputWebFileLocation.inputWebFileGeoPointLocation(geoPoint: _1!, accessHash: _2!, w: _3!, h: _4!, zoom: _5!, scale: _6!) - } - else { - return nil - } - } - public static func parse_inputWebFileLocation(_ reader: BufferReader) -> InputWebFileLocation? { - var _1: String? - _1 = parseString(reader) - var _2: Int64? - _2 = reader.readInt64() - let _c1 = _1 != nil - let _c2 = _2 != nil - if _c1 && _c2 { - return Api.InputWebFileLocation.inputWebFileLocation(url: _1!, accessHash: _2!) - } - else { - return nil - } - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api11.swift b/submodules/TelegramApi/Sources/Api11.swift index 83048a991e..3448343725 100644 --- a/submodules/TelegramApi/Sources/Api11.swift +++ b/submodules/TelegramApi/Sources/Api11.swift @@ -1,3 +1,119 @@ +public extension Api { + enum InputWebFileLocation: TypeConstructorDescription { + case inputWebFileAudioAlbumThumbLocation(flags: Int32, document: Api.InputDocument?, title: String?, performer: String?) + case inputWebFileGeoPointLocation(geoPoint: Api.InputGeoPoint, accessHash: Int64, w: Int32, h: Int32, zoom: Int32, scale: Int32) + case inputWebFileLocation(url: String, accessHash: Int64) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .inputWebFileAudioAlbumThumbLocation(let flags, let document, let title, let performer): + if boxed { + buffer.appendInt32(-193992412) + } + 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(title!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 1) != 0 {serializeString(performer!, buffer: buffer, boxed: false)} + break + case .inputWebFileGeoPointLocation(let geoPoint, let accessHash, let w, let h, let zoom, let scale): + if boxed { + buffer.appendInt32(-1625153079) + } + geoPoint.serialize(buffer, true) + serializeInt64(accessHash, buffer: buffer, boxed: false) + serializeInt32(w, buffer: buffer, boxed: false) + serializeInt32(h, buffer: buffer, boxed: false) + serializeInt32(zoom, buffer: buffer, boxed: false) + serializeInt32(scale, buffer: buffer, boxed: false) + break + case .inputWebFileLocation(let url, let accessHash): + if boxed { + buffer.appendInt32(-1036396922) + } + serializeString(url, buffer: buffer, boxed: false) + serializeInt64(accessHash, buffer: buffer, boxed: false) + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .inputWebFileAudioAlbumThumbLocation(let flags, let document, let title, let performer): + return ("inputWebFileAudioAlbumThumbLocation", [("flags", flags as Any), ("document", document as Any), ("title", title as Any), ("performer", performer as Any)]) + case .inputWebFileGeoPointLocation(let geoPoint, let accessHash, let w, let h, let zoom, let scale): + return ("inputWebFileGeoPointLocation", [("geoPoint", geoPoint as Any), ("accessHash", accessHash as Any), ("w", w as Any), ("h", h as Any), ("zoom", zoom as Any), ("scale", scale as Any)]) + case .inputWebFileLocation(let url, let accessHash): + return ("inputWebFileLocation", [("url", url as Any), ("accessHash", accessHash as Any)]) + } + } + + public static func parse_inputWebFileAudioAlbumThumbLocation(_ reader: BufferReader) -> InputWebFileLocation? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Api.InputDocument? + if Int(_1!) & Int(1 << 0) != 0 {if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.InputDocument + } } + var _3: String? + if Int(_1!) & Int(1 << 1) != 0 {_3 = parseString(reader) } + var _4: String? + if Int(_1!) & Int(1 << 1) != 0 {_4 = parseString(reader) } + 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 << 1) == 0) || _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.InputWebFileLocation.inputWebFileAudioAlbumThumbLocation(flags: _1!, document: _2, title: _3, performer: _4) + } + else { + return nil + } + } + public static func parse_inputWebFileGeoPointLocation(_ reader: BufferReader) -> InputWebFileLocation? { + var _1: Api.InputGeoPoint? + if let signature = reader.readInt32() { + _1 = Api.parse(reader, signature: signature) as? Api.InputGeoPoint + } + var _2: Int64? + _2 = reader.readInt64() + var _3: Int32? + _3 = reader.readInt32() + var _4: Int32? + _4 = reader.readInt32() + var _5: Int32? + _5 = reader.readInt32() + var _6: Int32? + _6 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + let _c6 = _6 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 { + return Api.InputWebFileLocation.inputWebFileGeoPointLocation(geoPoint: _1!, accessHash: _2!, w: _3!, h: _4!, zoom: _5!, scale: _6!) + } + else { + return nil + } + } + public static func parse_inputWebFileLocation(_ reader: BufferReader) -> InputWebFileLocation? { + var _1: String? + _1 = parseString(reader) + var _2: Int64? + _2 = reader.readInt64() + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.InputWebFileLocation.inputWebFileLocation(url: _1!, accessHash: _2!) + } + else { + return nil + } + } + + } +} public extension Api { enum Invoice: TypeConstructorDescription { case invoice(flags: Int32, currency: String, prices: [Api.LabeledPrice], maxTipAmount: Int64?, suggestedTipAmounts: [Int64]?, recurringTermsUrl: String?) @@ -1000,51 +1116,3 @@ public extension Api { } } -public extension Api { - enum MaskCoords: TypeConstructorDescription { - case maskCoords(n: Int32, x: Double, y: Double, zoom: Double) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .maskCoords(let n, let x, let y, let zoom): - if boxed { - buffer.appendInt32(-1361650766) - } - serializeInt32(n, buffer: buffer, boxed: false) - serializeDouble(x, buffer: buffer, boxed: false) - serializeDouble(y, buffer: buffer, boxed: false) - serializeDouble(zoom, buffer: buffer, boxed: false) - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .maskCoords(let n, let x, let y, let zoom): - return ("maskCoords", [("n", n as Any), ("x", x as Any), ("y", y as Any), ("zoom", zoom as Any)]) - } - } - - public static func parse_maskCoords(_ reader: BufferReader) -> MaskCoords? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Double? - _2 = reader.readDouble() - var _3: Double? - _3 = reader.readDouble() - var _4: Double? - _4 = reader.readDouble() - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = _3 != nil - let _c4 = _4 != nil - if _c1 && _c2 && _c3 && _c4 { - return Api.MaskCoords.maskCoords(n: _1!, x: _2!, y: _3!, zoom: _4!) - } - else { - return nil - } - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api12.swift b/submodules/TelegramApi/Sources/Api12.swift index 55ad86a29f..2aa6b0b28f 100644 --- a/submodules/TelegramApi/Sources/Api12.swift +++ b/submodules/TelegramApi/Sources/Api12.swift @@ -1,3 +1,51 @@ +public extension Api { + enum MaskCoords: TypeConstructorDescription { + case maskCoords(n: Int32, x: Double, y: Double, zoom: Double) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .maskCoords(let n, let x, let y, let zoom): + if boxed { + buffer.appendInt32(-1361650766) + } + serializeInt32(n, buffer: buffer, boxed: false) + serializeDouble(x, buffer: buffer, boxed: false) + serializeDouble(y, buffer: buffer, boxed: false) + serializeDouble(zoom, buffer: buffer, boxed: false) + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .maskCoords(let n, let x, let y, let zoom): + return ("maskCoords", [("n", n as Any), ("x", x as Any), ("y", y as Any), ("zoom", zoom as Any)]) + } + } + + public static func parse_maskCoords(_ reader: BufferReader) -> MaskCoords? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Double? + _2 = reader.readDouble() + var _3: Double? + _3 = reader.readDouble() + var _4: Double? + _4 = reader.readDouble() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.MaskCoords.maskCoords(n: _1!, x: _2!, y: _3!, zoom: _4!) + } + else { + return nil + } + } + + } +} public extension Api { indirect enum Message: TypeConstructorDescription { case message(flags: Int32, id: Int32, fromId: Api.Peer?, peerId: Api.Peer, fwdFrom: Api.MessageFwdHeader?, viaBotId: Int64?, replyTo: Api.MessageReplyHeader?, date: Int32, message: String, media: Api.MessageMedia?, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?, views: Int32?, forwards: Int32?, replies: Api.MessageReplies?, editDate: Int32?, postAuthor: String?, groupedId: Int64?, reactions: Api.MessageReactions?, restrictionReason: [Api.RestrictionReason]?, ttlPeriod: Int32?) diff --git a/submodules/TelegramApi/Sources/Api14.swift b/submodules/TelegramApi/Sources/Api14.swift index 7b2668a632..f1ea5107f5 100644 --- a/submodules/TelegramApi/Sources/Api14.swift +++ b/submodules/TelegramApi/Sources/Api14.swift @@ -323,6 +323,7 @@ public extension Api { public extension Api { enum MessageReplyHeader: TypeConstructorDescription { case messageReplyHeader(flags: Int32, replyToMsgId: Int32, replyToPeerId: Api.Peer?, replyToTopId: Int32?) + case messageReplyStoryHeader(userId: Int64, storyId: Int32) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -335,6 +336,13 @@ public extension Api { if Int(flags) & Int(1 << 0) != 0 {replyToPeerId!.serialize(buffer, true)} if Int(flags) & Int(1 << 1) != 0 {serializeInt32(replyToTopId!, buffer: buffer, boxed: false)} break + case .messageReplyStoryHeader(let userId, let storyId): + if boxed { + buffer.appendInt32(-1667711039) + } + serializeInt64(userId, buffer: buffer, boxed: false) + serializeInt32(storyId, buffer: buffer, boxed: false) + break } } @@ -342,6 +350,8 @@ public extension Api { switch self { case .messageReplyHeader(let flags, let replyToMsgId, let replyToPeerId, let replyToTopId): return ("messageReplyHeader", [("flags", flags as Any), ("replyToMsgId", replyToMsgId as Any), ("replyToPeerId", replyToPeerId as Any), ("replyToTopId", replyToTopId as Any)]) + case .messageReplyStoryHeader(let userId, let storyId): + return ("messageReplyStoryHeader", [("userId", userId as Any), ("storyId", storyId as Any)]) } } @@ -367,6 +377,20 @@ public extension Api { return nil } } + public static func parse_messageReplyStoryHeader(_ reader: BufferReader) -> MessageReplyHeader? { + 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.MessageReplyHeader.messageReplyStoryHeader(userId: _1!, storyId: _2!) + } + else { + return nil + } + } } } @@ -776,103 +800,3 @@ public extension Api { } } -public extension Api { - enum NotifyPeer: TypeConstructorDescription { - case notifyBroadcasts - case notifyChats - case notifyForumTopic(peer: Api.Peer, topMsgId: Int32) - case notifyPeer(peer: Api.Peer) - case notifyUsers - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .notifyBroadcasts: - if boxed { - buffer.appendInt32(-703403793) - } - - break - case .notifyChats: - if boxed { - buffer.appendInt32(-1073230141) - } - - break - case .notifyForumTopic(let peer, let topMsgId): - if boxed { - buffer.appendInt32(577659656) - } - peer.serialize(buffer, true) - serializeInt32(topMsgId, buffer: buffer, boxed: false) - break - case .notifyPeer(let peer): - if boxed { - buffer.appendInt32(-1613493288) - } - peer.serialize(buffer, true) - break - case .notifyUsers: - if boxed { - buffer.appendInt32(-1261946036) - } - - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .notifyBroadcasts: - return ("notifyBroadcasts", []) - case .notifyChats: - return ("notifyChats", []) - case .notifyForumTopic(let peer, let topMsgId): - return ("notifyForumTopic", [("peer", peer as Any), ("topMsgId", topMsgId as Any)]) - case .notifyPeer(let peer): - return ("notifyPeer", [("peer", peer as Any)]) - case .notifyUsers: - return ("notifyUsers", []) - } - } - - public static func parse_notifyBroadcasts(_ reader: BufferReader) -> NotifyPeer? { - return Api.NotifyPeer.notifyBroadcasts - } - public static func parse_notifyChats(_ reader: BufferReader) -> NotifyPeer? { - return Api.NotifyPeer.notifyChats - } - public static func parse_notifyForumTopic(_ reader: BufferReader) -> NotifyPeer? { - var _1: Api.Peer? - if let signature = reader.readInt32() { - _1 = Api.parse(reader, signature: signature) as? Api.Peer - } - var _2: Int32? - _2 = reader.readInt32() - let _c1 = _1 != nil - let _c2 = _2 != nil - if _c1 && _c2 { - return Api.NotifyPeer.notifyForumTopic(peer: _1!, topMsgId: _2!) - } - else { - return nil - } - } - public static func parse_notifyPeer(_ reader: BufferReader) -> NotifyPeer? { - var _1: Api.Peer? - if let signature = reader.readInt32() { - _1 = Api.parse(reader, signature: signature) as? Api.Peer - } - let _c1 = _1 != nil - if _c1 { - return Api.NotifyPeer.notifyPeer(peer: _1!) - } - else { - return nil - } - } - public static func parse_notifyUsers(_ reader: BufferReader) -> NotifyPeer? { - return Api.NotifyPeer.notifyUsers - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api15.swift b/submodules/TelegramApi/Sources/Api15.swift index c62dd8720f..d71cc7f9fe 100644 --- a/submodules/TelegramApi/Sources/Api15.swift +++ b/submodules/TelegramApi/Sources/Api15.swift @@ -1,3 +1,103 @@ +public extension Api { + enum NotifyPeer: TypeConstructorDescription { + case notifyBroadcasts + case notifyChats + case notifyForumTopic(peer: Api.Peer, topMsgId: Int32) + case notifyPeer(peer: Api.Peer) + case notifyUsers + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .notifyBroadcasts: + if boxed { + buffer.appendInt32(-703403793) + } + + break + case .notifyChats: + if boxed { + buffer.appendInt32(-1073230141) + } + + break + case .notifyForumTopic(let peer, let topMsgId): + if boxed { + buffer.appendInt32(577659656) + } + peer.serialize(buffer, true) + serializeInt32(topMsgId, buffer: buffer, boxed: false) + break + case .notifyPeer(let peer): + if boxed { + buffer.appendInt32(-1613493288) + } + peer.serialize(buffer, true) + break + case .notifyUsers: + if boxed { + buffer.appendInt32(-1261946036) + } + + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .notifyBroadcasts: + return ("notifyBroadcasts", []) + case .notifyChats: + return ("notifyChats", []) + case .notifyForumTopic(let peer, let topMsgId): + return ("notifyForumTopic", [("peer", peer as Any), ("topMsgId", topMsgId as Any)]) + case .notifyPeer(let peer): + return ("notifyPeer", [("peer", peer as Any)]) + case .notifyUsers: + return ("notifyUsers", []) + } + } + + public static func parse_notifyBroadcasts(_ reader: BufferReader) -> NotifyPeer? { + return Api.NotifyPeer.notifyBroadcasts + } + public static func parse_notifyChats(_ reader: BufferReader) -> NotifyPeer? { + return Api.NotifyPeer.notifyChats + } + public static func parse_notifyForumTopic(_ reader: BufferReader) -> NotifyPeer? { + var _1: Api.Peer? + if let signature = reader.readInt32() { + _1 = Api.parse(reader, signature: signature) as? Api.Peer + } + var _2: Int32? + _2 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.NotifyPeer.notifyForumTopic(peer: _1!, topMsgId: _2!) + } + else { + return nil + } + } + public static func parse_notifyPeer(_ reader: BufferReader) -> NotifyPeer? { + var _1: Api.Peer? + if let signature = reader.readInt32() { + _1 = Api.parse(reader, signature: signature) as? Api.Peer + } + let _c1 = _1 != nil + if _c1 { + return Api.NotifyPeer.notifyPeer(peer: _1!) + } + else { + return nil + } + } + public static func parse_notifyUsers(_ reader: BufferReader) -> NotifyPeer? { + return Api.NotifyPeer.notifyUsers + } + + } +} public extension Api { enum Page: TypeConstructorDescription { case page(flags: Int32, url: String, blocks: [Api.PageBlock], photos: [Api.Photo], documents: [Api.Document], views: Int32?) @@ -890,111 +990,3 @@ public extension Api { } } -public extension Api { - indirect enum PageCaption: TypeConstructorDescription { - case pageCaption(text: Api.RichText, credit: Api.RichText) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .pageCaption(let text, let credit): - if boxed { - buffer.appendInt32(1869903447) - } - text.serialize(buffer, true) - credit.serialize(buffer, true) - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .pageCaption(let text, let credit): - return ("pageCaption", [("text", text as Any), ("credit", credit as Any)]) - } - } - - public static func parse_pageCaption(_ reader: BufferReader) -> PageCaption? { - var _1: Api.RichText? - if let signature = reader.readInt32() { - _1 = Api.parse(reader, signature: signature) as? Api.RichText - } - var _2: Api.RichText? - if let signature = reader.readInt32() { - _2 = Api.parse(reader, signature: signature) as? Api.RichText - } - let _c1 = _1 != nil - let _c2 = _2 != nil - if _c1 && _c2 { - return Api.PageCaption.pageCaption(text: _1!, credit: _2!) - } - else { - return nil - } - } - - } -} -public extension Api { - indirect enum PageListItem: TypeConstructorDescription { - case pageListItemBlocks(blocks: [Api.PageBlock]) - case pageListItemText(text: Api.RichText) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .pageListItemBlocks(let blocks): - if boxed { - buffer.appendInt32(635466748) - } - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(blocks.count)) - for item in blocks { - item.serialize(buffer, true) - } - break - case .pageListItemText(let text): - if boxed { - buffer.appendInt32(-1188055347) - } - text.serialize(buffer, true) - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .pageListItemBlocks(let blocks): - return ("pageListItemBlocks", [("blocks", blocks as Any)]) - case .pageListItemText(let text): - return ("pageListItemText", [("text", text as Any)]) - } - } - - public static func parse_pageListItemBlocks(_ reader: BufferReader) -> PageListItem? { - var _1: [Api.PageBlock]? - if let _ = reader.readInt32() { - _1 = Api.parseVector(reader, elementSignature: 0, elementType: Api.PageBlock.self) - } - let _c1 = _1 != nil - if _c1 { - return Api.PageListItem.pageListItemBlocks(blocks: _1!) - } - else { - return nil - } - } - public static func parse_pageListItemText(_ reader: BufferReader) -> PageListItem? { - var _1: Api.RichText? - if let signature = reader.readInt32() { - _1 = Api.parse(reader, signature: signature) as? Api.RichText - } - let _c1 = _1 != nil - if _c1 { - return Api.PageListItem.pageListItemText(text: _1!) - } - else { - return nil - } - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api16.swift b/submodules/TelegramApi/Sources/Api16.swift index 1ad7545048..8981915c7f 100644 --- a/submodules/TelegramApi/Sources/Api16.swift +++ b/submodules/TelegramApi/Sources/Api16.swift @@ -1,3 +1,111 @@ +public extension Api { + indirect enum PageCaption: TypeConstructorDescription { + case pageCaption(text: Api.RichText, credit: Api.RichText) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .pageCaption(let text, let credit): + if boxed { + buffer.appendInt32(1869903447) + } + text.serialize(buffer, true) + credit.serialize(buffer, true) + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .pageCaption(let text, let credit): + return ("pageCaption", [("text", text as Any), ("credit", credit as Any)]) + } + } + + public static func parse_pageCaption(_ reader: BufferReader) -> PageCaption? { + var _1: Api.RichText? + if let signature = reader.readInt32() { + _1 = Api.parse(reader, signature: signature) as? Api.RichText + } + var _2: Api.RichText? + if let signature = reader.readInt32() { + _2 = Api.parse(reader, signature: signature) as? Api.RichText + } + let _c1 = _1 != nil + let _c2 = _2 != nil + if _c1 && _c2 { + return Api.PageCaption.pageCaption(text: _1!, credit: _2!) + } + else { + return nil + } + } + + } +} +public extension Api { + indirect enum PageListItem: TypeConstructorDescription { + case pageListItemBlocks(blocks: [Api.PageBlock]) + case pageListItemText(text: Api.RichText) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .pageListItemBlocks(let blocks): + if boxed { + buffer.appendInt32(635466748) + } + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(blocks.count)) + for item in blocks { + item.serialize(buffer, true) + } + break + case .pageListItemText(let text): + if boxed { + buffer.appendInt32(-1188055347) + } + text.serialize(buffer, true) + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .pageListItemBlocks(let blocks): + return ("pageListItemBlocks", [("blocks", blocks as Any)]) + case .pageListItemText(let text): + return ("pageListItemText", [("text", text as Any)]) + } + } + + public static func parse_pageListItemBlocks(_ reader: BufferReader) -> PageListItem? { + var _1: [Api.PageBlock]? + if let _ = reader.readInt32() { + _1 = Api.parseVector(reader, elementSignature: 0, elementType: Api.PageBlock.self) + } + let _c1 = _1 != nil + if _c1 { + return Api.PageListItem.pageListItemBlocks(blocks: _1!) + } + else { + return nil + } + } + public static func parse_pageListItemText(_ reader: BufferReader) -> PageListItem? { + var _1: Api.RichText? + if let signature = reader.readInt32() { + _1 = Api.parse(reader, signature: signature) as? Api.RichText + } + let _c1 = _1 != nil + if _c1 { + return Api.PageListItem.pageListItemText(text: _1!) + } + else { + return nil + } + } + + } +} public extension Api { indirect enum PageListOrderedItem: TypeConstructorDescription { case pageListOrderedItemBlocks(num: String, blocks: [Api.PageBlock]) @@ -1114,157 +1222,3 @@ public extension Api { } } -public extension Api { - enum PhoneCallProtocol: TypeConstructorDescription { - case phoneCallProtocol(flags: Int32, minLayer: Int32, maxLayer: Int32, libraryVersions: [String]) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .phoneCallProtocol(let flags, let minLayer, let maxLayer, let libraryVersions): - if boxed { - buffer.appendInt32(-58224696) - } - serializeInt32(flags, buffer: buffer, boxed: false) - serializeInt32(minLayer, buffer: buffer, boxed: false) - serializeInt32(maxLayer, buffer: buffer, boxed: false) - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(libraryVersions.count)) - for item in libraryVersions { - serializeString(item, buffer: buffer, boxed: false) - } - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .phoneCallProtocol(let flags, let minLayer, let maxLayer, let libraryVersions): - return ("phoneCallProtocol", [("flags", flags as Any), ("minLayer", minLayer as Any), ("maxLayer", maxLayer as Any), ("libraryVersions", libraryVersions as Any)]) - } - } - - public static func parse_phoneCallProtocol(_ reader: BufferReader) -> PhoneCallProtocol? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Int32? - _2 = reader.readInt32() - var _3: Int32? - _3 = reader.readInt32() - var _4: [String]? - if let _ = reader.readInt32() { - _4 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self) - } - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = _3 != nil - let _c4 = _4 != nil - if _c1 && _c2 && _c3 && _c4 { - return Api.PhoneCallProtocol.phoneCallProtocol(flags: _1!, minLayer: _2!, maxLayer: _3!, libraryVersions: _4!) - } - else { - return nil - } - } - - } -} -public extension Api { - enum PhoneConnection: TypeConstructorDescription { - case phoneConnection(flags: Int32, id: Int64, ip: String, ipv6: String, port: Int32, peerTag: Buffer) - case phoneConnectionWebrtc(flags: Int32, id: Int64, ip: String, ipv6: String, port: Int32, username: String, password: String) - - public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { - switch self { - case .phoneConnection(let flags, let id, let ip, let ipv6, let port, let peerTag): - if boxed { - buffer.appendInt32(-1665063993) - } - serializeInt32(flags, buffer: buffer, boxed: false) - serializeInt64(id, buffer: buffer, boxed: false) - serializeString(ip, buffer: buffer, boxed: false) - serializeString(ipv6, buffer: buffer, boxed: false) - serializeInt32(port, buffer: buffer, boxed: false) - serializeBytes(peerTag, buffer: buffer, boxed: false) - break - case .phoneConnectionWebrtc(let flags, let id, let ip, let ipv6, let port, let username, let password): - if boxed { - buffer.appendInt32(1667228533) - } - serializeInt32(flags, buffer: buffer, boxed: false) - serializeInt64(id, buffer: buffer, boxed: false) - serializeString(ip, buffer: buffer, boxed: false) - serializeString(ipv6, buffer: buffer, boxed: false) - serializeInt32(port, buffer: buffer, boxed: false) - serializeString(username, buffer: buffer, boxed: false) - serializeString(password, buffer: buffer, boxed: false) - break - } - } - - public func descriptionFields() -> (String, [(String, Any)]) { - switch self { - case .phoneConnection(let flags, let id, let ip, let ipv6, let port, let peerTag): - return ("phoneConnection", [("flags", flags as Any), ("id", id as Any), ("ip", ip as Any), ("ipv6", ipv6 as Any), ("port", port as Any), ("peerTag", peerTag as Any)]) - case .phoneConnectionWebrtc(let flags, let id, let ip, let ipv6, let port, let username, let password): - return ("phoneConnectionWebrtc", [("flags", flags as Any), ("id", id as Any), ("ip", ip as Any), ("ipv6", ipv6 as Any), ("port", port as Any), ("username", username as Any), ("password", password as Any)]) - } - } - - public static func parse_phoneConnection(_ reader: BufferReader) -> PhoneConnection? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Int64? - _2 = reader.readInt64() - var _3: String? - _3 = parseString(reader) - var _4: String? - _4 = parseString(reader) - var _5: Int32? - _5 = reader.readInt32() - var _6: Buffer? - _6 = parseBytes(reader) - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = _3 != nil - let _c4 = _4 != nil - let _c5 = _5 != nil - let _c6 = _6 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 { - return Api.PhoneConnection.phoneConnection(flags: _1!, id: _2!, ip: _3!, ipv6: _4!, port: _5!, peerTag: _6!) - } - else { - return nil - } - } - public static func parse_phoneConnectionWebrtc(_ reader: BufferReader) -> PhoneConnection? { - var _1: Int32? - _1 = reader.readInt32() - var _2: Int64? - _2 = reader.readInt64() - var _3: String? - _3 = parseString(reader) - var _4: String? - _4 = parseString(reader) - var _5: Int32? - _5 = reader.readInt32() - var _6: String? - _6 = parseString(reader) - var _7: String? - _7 = parseString(reader) - let _c1 = _1 != nil - let _c2 = _2 != nil - let _c3 = _3 != nil - let _c4 = _4 != nil - let _c5 = _5 != nil - let _c6 = _6 != nil - let _c7 = _7 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 { - return Api.PhoneConnection.phoneConnectionWebrtc(flags: _1!, id: _2!, ip: _3!, ipv6: _4!, port: _5!, username: _6!, password: _7!) - } - else { - return nil - } - } - - } -} diff --git a/submodules/TelegramApi/Sources/Api17.swift b/submodules/TelegramApi/Sources/Api17.swift index 41f414105a..c50124ce4c 100644 --- a/submodules/TelegramApi/Sources/Api17.swift +++ b/submodules/TelegramApi/Sources/Api17.swift @@ -1,3 +1,157 @@ +public extension Api { + enum PhoneCallProtocol: TypeConstructorDescription { + case phoneCallProtocol(flags: Int32, minLayer: Int32, maxLayer: Int32, libraryVersions: [String]) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .phoneCallProtocol(let flags, let minLayer, let maxLayer, let libraryVersions): + if boxed { + buffer.appendInt32(-58224696) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(minLayer, buffer: buffer, boxed: false) + serializeInt32(maxLayer, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(libraryVersions.count)) + for item in libraryVersions { + serializeString(item, buffer: buffer, boxed: false) + } + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .phoneCallProtocol(let flags, let minLayer, let maxLayer, let libraryVersions): + return ("phoneCallProtocol", [("flags", flags as Any), ("minLayer", minLayer as Any), ("maxLayer", maxLayer as Any), ("libraryVersions", libraryVersions as Any)]) + } + } + + public static func parse_phoneCallProtocol(_ reader: BufferReader) -> PhoneCallProtocol? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: Int32? + _3 = reader.readInt32() + var _4: [String]? + if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self) + } + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.PhoneCallProtocol.phoneCallProtocol(flags: _1!, minLayer: _2!, maxLayer: _3!, libraryVersions: _4!) + } + else { + return nil + } + } + + } +} +public extension Api { + enum PhoneConnection: TypeConstructorDescription { + case phoneConnection(flags: Int32, id: Int64, ip: String, ipv6: String, port: Int32, peerTag: Buffer) + case phoneConnectionWebrtc(flags: Int32, id: Int64, ip: String, ipv6: String, port: Int32, username: String, password: String) + + public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { + switch self { + case .phoneConnection(let flags, let id, let ip, let ipv6, let port, let peerTag): + if boxed { + buffer.appendInt32(-1665063993) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt64(id, buffer: buffer, boxed: false) + serializeString(ip, buffer: buffer, boxed: false) + serializeString(ipv6, buffer: buffer, boxed: false) + serializeInt32(port, buffer: buffer, boxed: false) + serializeBytes(peerTag, buffer: buffer, boxed: false) + break + case .phoneConnectionWebrtc(let flags, let id, let ip, let ipv6, let port, let username, let password): + if boxed { + buffer.appendInt32(1667228533) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt64(id, buffer: buffer, boxed: false) + serializeString(ip, buffer: buffer, boxed: false) + serializeString(ipv6, buffer: buffer, boxed: false) + serializeInt32(port, buffer: buffer, boxed: false) + serializeString(username, buffer: buffer, boxed: false) + serializeString(password, buffer: buffer, boxed: false) + break + } + } + + public func descriptionFields() -> (String, [(String, Any)]) { + switch self { + case .phoneConnection(let flags, let id, let ip, let ipv6, let port, let peerTag): + return ("phoneConnection", [("flags", flags as Any), ("id", id as Any), ("ip", ip as Any), ("ipv6", ipv6 as Any), ("port", port as Any), ("peerTag", peerTag as Any)]) + case .phoneConnectionWebrtc(let flags, let id, let ip, let ipv6, let port, let username, let password): + return ("phoneConnectionWebrtc", [("flags", flags as Any), ("id", id as Any), ("ip", ip as Any), ("ipv6", ipv6 as Any), ("port", port as Any), ("username", username as Any), ("password", password as Any)]) + } + } + + public static func parse_phoneConnection(_ reader: BufferReader) -> PhoneConnection? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: String? + _3 = parseString(reader) + var _4: String? + _4 = parseString(reader) + var _5: Int32? + _5 = reader.readInt32() + var _6: Buffer? + _6 = parseBytes(reader) + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + let _c6 = _6 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 { + return Api.PhoneConnection.phoneConnection(flags: _1!, id: _2!, ip: _3!, ipv6: _4!, port: _5!, peerTag: _6!) + } + else { + return nil + } + } + public static func parse_phoneConnectionWebrtc(_ reader: BufferReader) -> PhoneConnection? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: String? + _3 = parseString(reader) + var _4: String? + _4 = parseString(reader) + var _5: Int32? + _5 = reader.readInt32() + var _6: String? + _6 = parseString(reader) + var _7: String? + _7 = parseString(reader) + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + let _c6 = _6 != nil + let _c7 = _7 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 { + return Api.PhoneConnection.phoneConnectionWebrtc(flags: _1!, id: _2!, ip: _3!, ipv6: _4!, port: _5!, username: _6!, password: _7!) + } + else { + return nil + } + } + + } +} public extension Api { enum Photo: TypeConstructorDescription { case photo(flags: Int32, id: Int64, accessHash: Int64, fileReference: Buffer, date: Int32, sizes: [Api.PhotoSize], videoSizes: [Api.VideoSize]?, dcId: Int32) diff --git a/submodules/TelegramApi/Sources/Api21.swift b/submodules/TelegramApi/Sources/Api21.swift index 337477512a..98fa90f06c 100644 --- a/submodules/TelegramApi/Sources/Api21.swift +++ b/submodules/TelegramApi/Sources/Api21.swift @@ -492,42 +492,46 @@ public extension Api { } public extension Api { enum StoryViews: TypeConstructorDescription { - case storyViews(recentViewers: [Int64], viewsCount: Int32) + case storyViews(flags: Int32, viewsCount: Int32, recentViewers: [Int64]?) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .storyViews(let recentViewers, let viewsCount): + case .storyViews(let flags, let viewsCount, let recentViewers): if boxed { - buffer.appendInt32(1368082392) - } - buffer.appendInt32(481674261) - buffer.appendInt32(Int32(recentViewers.count)) - for item in recentViewers { - serializeInt64(item, buffer: buffer, boxed: false) + buffer.appendInt32(-748199729) } + serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(viewsCount, buffer: buffer, boxed: false) + if Int(flags) & Int(1 << 0) != 0 {buffer.appendInt32(481674261) + buffer.appendInt32(Int32(recentViewers!.count)) + for item in recentViewers! { + serializeInt64(item, buffer: buffer, boxed: false) + }} break } } public func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .storyViews(let recentViewers, let viewsCount): - return ("storyViews", [("recentViewers", recentViewers as Any), ("viewsCount", viewsCount as Any)]) + case .storyViews(let flags, let viewsCount, let recentViewers): + return ("storyViews", [("flags", flags as Any), ("viewsCount", viewsCount as Any), ("recentViewers", recentViewers as Any)]) } } public static func parse_storyViews(_ reader: BufferReader) -> StoryViews? { - var _1: [Int64]? - if let _ = reader.readInt32() { - _1 = Api.parseVector(reader, elementSignature: 570911930, elementType: Int64.self) - } + var _1: Int32? + _1 = reader.readInt32() var _2: Int32? _2 = reader.readInt32() + var _3: [Int64]? + if Int(_1!) & Int(1 << 0) != 0 {if let _ = reader.readInt32() { + _3 = Api.parseVector(reader, elementSignature: 570911930, elementType: Int64.self) + } } let _c1 = _1 != nil let _c2 = _2 != nil - if _c1 && _c2 { - return Api.StoryViews.storyViews(recentViewers: _1!, viewsCount: _2!) + let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil + if _c1 && _c2 && _c3 { + return Api.StoryViews.storyViews(flags: _1!, viewsCount: _2!, recentViewers: _3) } else { return nil diff --git a/submodules/TelegramApi/Sources/Api29.swift b/submodules/TelegramApi/Sources/Api29.swift index f816774ffc..542cf81154 100644 --- a/submodules/TelegramApi/Sources/Api29.swift +++ b/submodules/TelegramApi/Sources/Api29.swift @@ -360,16 +360,17 @@ public extension Api.storage { } public extension Api.stories { enum AllStories: TypeConstructorDescription { - case allStories(flags: Int32, state: String, userStories: [Api.UserStories], users: [Api.User]) + case allStories(flags: Int32, count: Int32, state: String, userStories: [Api.UserStories], users: [Api.User]) case allStoriesNotModified(state: String) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .allStories(let flags, let state, let userStories, let users): + case .allStories(let flags, let count, let state, let userStories, let users): if boxed { - buffer.appendInt32(1528473228) + buffer.appendInt32(-2086796248) } serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(count, buffer: buffer, boxed: false) serializeString(state, buffer: buffer, boxed: false) buffer.appendInt32(481674261) buffer.appendInt32(Int32(userStories.count)) @@ -393,8 +394,8 @@ public extension Api.stories { public func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .allStories(let flags, let state, let userStories, let users): - return ("allStories", [("flags", flags as Any), ("state", state as Any), ("userStories", userStories as Any), ("users", users as Any)]) + case .allStories(let flags, let count, let state, let userStories, let users): + return ("allStories", [("flags", flags as Any), ("count", count as Any), ("state", state as Any), ("userStories", userStories as Any), ("users", users as Any)]) case .allStoriesNotModified(let state): return ("allStoriesNotModified", [("state", state as Any)]) } @@ -403,22 +404,25 @@ public extension Api.stories { public static func parse_allStories(_ reader: BufferReader) -> AllStories? { var _1: Int32? _1 = reader.readInt32() - var _2: String? - _2 = parseString(reader) - var _3: [Api.UserStories]? + var _2: Int32? + _2 = reader.readInt32() + var _3: String? + _3 = parseString(reader) + var _4: [Api.UserStories]? if let _ = reader.readInt32() { - _3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.UserStories.self) + _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.UserStories.self) } - var _4: [Api.User]? + var _5: [Api.User]? if let _ = reader.readInt32() { - _4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) + _5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self) } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = _3 != nil let _c4 = _4 != nil - if _c1 && _c2 && _c3 && _c4 { - return Api.stories.AllStories.allStories(flags: _1!, state: _2!, userStories: _3!, users: _4!) + let _c5 = _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return Api.stories.AllStories.allStories(flags: _1!, count: _2!, state: _3!, userStories: _4!, users: _5!) } else { return nil diff --git a/submodules/TelegramApi/Sources/Api30.swift b/submodules/TelegramApi/Sources/Api30.swift index b74ada1323..acf86c4503 100644 --- a/submodules/TelegramApi/Sources/Api30.swift +++ b/submodules/TelegramApi/Sources/Api30.swift @@ -5962,17 +5962,16 @@ public extension Api.functions.messages { } } public extension Api.functions.messages { - static func prolongWebView(flags: Int32, peer: Api.InputPeer, bot: Api.InputUser, queryId: Int64, replyToMsgId: Int32?, topMsgId: Int32?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func prolongWebView(flags: Int32, peer: Api.InputPeer, bot: Api.InputUser, queryId: Int64, replyTo: Api.InputReplyTo?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(2146648841) + buffer.appendInt32(-1328014717) serializeInt32(flags, buffer: buffer, boxed: false) peer.serialize(buffer, true) bot.serialize(buffer, true) serializeInt64(queryId, buffer: buffer, boxed: false) - if Int(flags) & Int(1 << 0) != 0 {serializeInt32(replyToMsgId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 9) != 0 {serializeInt32(topMsgId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 0) != 0 {replyTo!.serialize(buffer, true)} if Int(flags) & Int(1 << 13) != 0 {sendAs!.serialize(buffer, true)} - return (FunctionDescription(name: "messages.prolongWebView", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("bot", String(describing: bot)), ("queryId", String(describing: queryId)), ("replyToMsgId", String(describing: replyToMsgId)), ("topMsgId", String(describing: topMsgId)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in + return (FunctionDescription(name: "messages.prolongWebView", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("bot", String(describing: bot)), ("queryId", String(describing: queryId)), ("replyTo", String(describing: replyTo)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in let reader = BufferReader(buffer) var result: Api.Bool? if let signature = reader.readInt32() { @@ -6337,9 +6336,9 @@ public extension Api.functions.messages { } } public extension Api.functions.messages { - static func requestWebView(flags: Int32, peer: Api.InputPeer, bot: Api.InputUser, url: String?, startParam: String?, themeParams: Api.DataJSON?, platform: String, replyToMsgId: Int32?, topMsgId: Int32?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func requestWebView(flags: Int32, peer: Api.InputPeer, bot: Api.InputUser, url: String?, startParam: String?, themeParams: Api.DataJSON?, platform: String, replyTo: Api.InputReplyTo?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(395003915) + buffer.appendInt32(647873217) serializeInt32(flags, buffer: buffer, boxed: false) peer.serialize(buffer, true) bot.serialize(buffer, true) @@ -6347,10 +6346,9 @@ public extension Api.functions.messages { if Int(flags) & Int(1 << 3) != 0 {serializeString(startParam!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 2) != 0 {themeParams!.serialize(buffer, true)} serializeString(platform, buffer: buffer, boxed: false) - if Int(flags) & Int(1 << 0) != 0 {serializeInt32(replyToMsgId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 9) != 0 {serializeInt32(topMsgId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 0) != 0 {replyTo!.serialize(buffer, true)} if Int(flags) & Int(1 << 13) != 0 {sendAs!.serialize(buffer, true)} - return (FunctionDescription(name: "messages.requestWebView", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("bot", String(describing: bot)), ("url", String(describing: url)), ("startParam", String(describing: startParam)), ("themeParams", String(describing: themeParams)), ("platform", String(describing: platform)), ("replyToMsgId", String(describing: replyToMsgId)), ("topMsgId", String(describing: topMsgId)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.WebViewResult? in + return (FunctionDescription(name: "messages.requestWebView", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("bot", String(describing: bot)), ("url", String(describing: url)), ("startParam", String(describing: startParam)), ("themeParams", String(describing: themeParams)), ("platform", String(describing: platform)), ("replyTo", String(describing: replyTo)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.WebViewResult? in let reader = BufferReader(buffer) var result: Api.WebViewResult? if let signature = reader.readInt32() { @@ -6608,19 +6606,18 @@ public extension Api.functions.messages { } } public extension Api.functions.messages { - static func sendInlineBotResult(flags: Int32, peer: Api.InputPeer, replyToMsgId: Int32?, topMsgId: Int32?, randomId: Int64, queryId: Int64, id: String, scheduleDate: Int32?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func sendInlineBotResult(flags: Int32, peer: Api.InputPeer, replyTo: Api.InputReplyTo?, randomId: Int64, queryId: Int64, id: String, scheduleDate: Int32?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-738468661) + buffer.appendInt32(-138647366) serializeInt32(flags, buffer: buffer, boxed: false) peer.serialize(buffer, true) - if Int(flags) & Int(1 << 0) != 0 {serializeInt32(replyToMsgId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 9) != 0 {serializeInt32(topMsgId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 0) != 0 {replyTo!.serialize(buffer, true)} serializeInt64(randomId, buffer: buffer, boxed: false) serializeInt64(queryId, buffer: buffer, boxed: false) serializeString(id, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 10) != 0 {serializeInt32(scheduleDate!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 13) != 0 {sendAs!.serialize(buffer, true)} - return (FunctionDescription(name: "messages.sendInlineBotResult", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("replyToMsgId", String(describing: replyToMsgId)), ("topMsgId", String(describing: topMsgId)), ("randomId", String(describing: randomId)), ("queryId", String(describing: queryId)), ("id", String(describing: id)), ("scheduleDate", String(describing: scheduleDate)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in + return (FunctionDescription(name: "messages.sendInlineBotResult", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("replyTo", String(describing: replyTo)), ("randomId", String(describing: randomId)), ("queryId", String(describing: queryId)), ("id", String(describing: id)), ("scheduleDate", String(describing: scheduleDate)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in let reader = BufferReader(buffer) var result: Api.Updates? if let signature = reader.readInt32() { @@ -6631,13 +6628,12 @@ public extension Api.functions.messages { } } public extension Api.functions.messages { - static func sendMedia(flags: Int32, peer: Api.InputPeer, replyToMsgId: Int32?, topMsgId: Int32?, media: Api.InputMedia, message: String, randomId: Int64, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?, scheduleDate: Int32?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func sendMedia(flags: Int32, peer: Api.InputPeer, replyTo: Api.InputReplyTo?, media: Api.InputMedia, message: String, randomId: Int64, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?, scheduleDate: Int32?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(1967638886) + buffer.appendInt32(1926021693) serializeInt32(flags, buffer: buffer, boxed: false) peer.serialize(buffer, true) - if Int(flags) & Int(1 << 0) != 0 {serializeInt32(replyToMsgId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 9) != 0 {serializeInt32(topMsgId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 0) != 0 {replyTo!.serialize(buffer, true)} media.serialize(buffer, true) serializeString(message, buffer: buffer, boxed: false) serializeInt64(randomId, buffer: buffer, boxed: false) @@ -6649,7 +6645,7 @@ public extension Api.functions.messages { }} if Int(flags) & Int(1 << 10) != 0 {serializeInt32(scheduleDate!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 13) != 0 {sendAs!.serialize(buffer, true)} - return (FunctionDescription(name: "messages.sendMedia", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("replyToMsgId", String(describing: replyToMsgId)), ("topMsgId", String(describing: topMsgId)), ("media", String(describing: media)), ("message", String(describing: message)), ("randomId", String(describing: randomId)), ("replyMarkup", String(describing: replyMarkup)), ("entities", String(describing: entities)), ("scheduleDate", String(describing: scheduleDate)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in + return (FunctionDescription(name: "messages.sendMedia", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("replyTo", String(describing: replyTo)), ("media", String(describing: media)), ("message", String(describing: message)), ("randomId", String(describing: randomId)), ("replyMarkup", String(describing: replyMarkup)), ("entities", String(describing: entities)), ("scheduleDate", String(describing: scheduleDate)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in let reader = BufferReader(buffer) var result: Api.Updates? if let signature = reader.readInt32() { @@ -6660,13 +6656,12 @@ public extension Api.functions.messages { } } public extension Api.functions.messages { - static func sendMessage(flags: Int32, peer: Api.InputPeer, replyToMsgId: Int32?, topMsgId: Int32?, message: String, randomId: Int64, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?, scheduleDate: Int32?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func sendMessage(flags: Int32, peer: Api.InputPeer, replyTo: Api.InputReplyTo?, message: String, randomId: Int64, replyMarkup: Api.ReplyMarkup?, entities: [Api.MessageEntity]?, scheduleDate: Int32?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(482476935) + buffer.appendInt32(671943023) serializeInt32(flags, buffer: buffer, boxed: false) peer.serialize(buffer, true) - if Int(flags) & Int(1 << 0) != 0 {serializeInt32(replyToMsgId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 9) != 0 {serializeInt32(topMsgId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 0) != 0 {replyTo!.serialize(buffer, true)} serializeString(message, buffer: buffer, boxed: false) serializeInt64(randomId, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 2) != 0 {replyMarkup!.serialize(buffer, true)} @@ -6677,7 +6672,7 @@ public extension Api.functions.messages { }} if Int(flags) & Int(1 << 10) != 0 {serializeInt32(scheduleDate!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 13) != 0 {sendAs!.serialize(buffer, true)} - return (FunctionDescription(name: "messages.sendMessage", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("replyToMsgId", String(describing: replyToMsgId)), ("topMsgId", String(describing: topMsgId)), ("message", String(describing: message)), ("randomId", String(describing: randomId)), ("replyMarkup", String(describing: replyMarkup)), ("entities", String(describing: entities)), ("scheduleDate", String(describing: scheduleDate)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in + return (FunctionDescription(name: "messages.sendMessage", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("replyTo", String(describing: replyTo)), ("message", String(describing: message)), ("randomId", String(describing: randomId)), ("replyMarkup", String(describing: replyMarkup)), ("entities", String(describing: entities)), ("scheduleDate", String(describing: scheduleDate)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in let reader = BufferReader(buffer) var result: Api.Updates? if let signature = reader.readInt32() { @@ -6688,13 +6683,12 @@ public extension Api.functions.messages { } } public extension Api.functions.messages { - static func sendMultiMedia(flags: Int32, peer: Api.InputPeer, replyToMsgId: Int32?, topMsgId: Int32?, multiMedia: [Api.InputSingleMedia], scheduleDate: Int32?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func sendMultiMedia(flags: Int32, peer: Api.InputPeer, replyTo: Api.InputReplyTo?, multiMedia: [Api.InputSingleMedia], scheduleDate: Int32?, sendAs: Api.InputPeer?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-1225713124) + buffer.appendInt32(1164872071) serializeInt32(flags, buffer: buffer, boxed: false) peer.serialize(buffer, true) - if Int(flags) & Int(1 << 0) != 0 {serializeInt32(replyToMsgId!, buffer: buffer, boxed: false)} - if Int(flags) & Int(1 << 9) != 0 {serializeInt32(topMsgId!, buffer: buffer, boxed: false)} + if Int(flags) & Int(1 << 0) != 0 {replyTo!.serialize(buffer, true)} buffer.appendInt32(481674261) buffer.appendInt32(Int32(multiMedia.count)) for item in multiMedia { @@ -6702,7 +6696,7 @@ public extension Api.functions.messages { } if Int(flags) & Int(1 << 10) != 0 {serializeInt32(scheduleDate!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 13) != 0 {sendAs!.serialize(buffer, true)} - return (FunctionDescription(name: "messages.sendMultiMedia", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("replyToMsgId", String(describing: replyToMsgId)), ("topMsgId", String(describing: topMsgId)), ("multiMedia", String(describing: multiMedia)), ("scheduleDate", String(describing: scheduleDate)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in + return (FunctionDescription(name: "messages.sendMultiMedia", parameters: [("flags", String(describing: flags)), ("peer", String(describing: peer)), ("replyTo", String(describing: replyTo)), ("multiMedia", String(describing: multiMedia)), ("scheduleDate", String(describing: scheduleDate)), ("sendAs", String(describing: sendAs))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in let reader = BufferReader(buffer) var result: Api.Updates? if let signature = reader.readInt32() { @@ -6755,13 +6749,13 @@ public extension Api.functions.messages { } } public extension Api.functions.messages { - static func sendScreenshotNotification(peer: Api.InputPeer, replyToMsgId: Int32, randomId: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func sendScreenshotNotification(peer: Api.InputPeer, replyTo: Api.InputReplyTo, randomId: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-914493408) + buffer.appendInt32(-1589618665) peer.serialize(buffer, true) - serializeInt32(replyToMsgId, buffer: buffer, boxed: false) + replyTo.serialize(buffer, true) serializeInt64(randomId, buffer: buffer, boxed: false) - return (FunctionDescription(name: "messages.sendScreenshotNotification", parameters: [("peer", String(describing: peer)), ("replyToMsgId", String(describing: replyToMsgId)), ("randomId", String(describing: randomId))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in + return (FunctionDescription(name: "messages.sendScreenshotNotification", parameters: [("peer", String(describing: peer)), ("replyTo", String(describing: replyTo)), ("randomId", String(describing: randomId))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in let reader = BufferReader(buffer) var result: Api.Updates? if let signature = reader.readInt32() { @@ -8583,6 +8577,26 @@ public extension Api.functions.stories { }) } } +public extension Api.functions.stories { + static func incrementStoryViews(userId: Api.InputUser, id: [Int32]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + let buffer = Buffer() + buffer.appendInt32(571629863) + userId.serialize(buffer, true) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(id.count)) + for item in id { + serializeInt32(item, buffer: buffer, boxed: false) + } + return (FunctionDescription(name: "stories.incrementStoryViews", parameters: [("userId", String(describing: userId)), ("id", String(describing: id))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in + let reader = BufferReader(buffer) + var result: Api.Bool? + if let signature = reader.readInt32() { + result = Api.parse(reader, signature: signature) as? Api.Bool + } + return result + }) + } +} public extension Api.functions.stories { static func readStories(userId: Api.InputUser, maxId: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Int32]>) { let buffer = Buffer() diff --git a/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift b/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift index 861eb1963b..ccc5d3ee5c 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift @@ -250,6 +250,8 @@ func apiMessageAssociatedMessageIds(_ message: Api.Message) -> (replyIds: Refere var replyIds = ReferencedReplyMessageIds() replyIds.add(sourceId: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: id), targetId: targetId) return (replyIds, []) + case .messageReplyStoryHeader: + break } } case .messageEmpty: @@ -262,6 +264,8 @@ func apiMessageAssociatedMessageIds(_ message: Api.Message) -> (replyIds: Refere var replyIds = ReferencedReplyMessageIds() replyIds.add(sourceId: MessageId(peerId: chatPeerId.peerId, namespace: Namespaces.Message.Cloud, id: id), targetId: targetId) return (replyIds, []) + case .messageReplyStoryHeader: + break } } } @@ -479,6 +483,8 @@ extension StoreMessage { } } attributes.append(ReplyMessageAttribute(messageId: MessageId(peerId: replyPeerId, namespace: Namespaces.Message.Cloud, id: replyToMsgId), threadMessageId: threadMessageId)) + case .messageReplyStoryHeader: + break } } @@ -728,6 +734,8 @@ extension StoreMessage { break } attributes.append(ReplyMessageAttribute(messageId: MessageId(peerId: replyPeerId, namespace: Namespaces.Message.Cloud, id: replyToMsgId), threadMessageId: threadMessageId)) + case .messageReplyStoryHeader: + break } } else { switch action { diff --git a/submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift b/submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift index 70f51b3807..0d5c2a058c 100644 --- a/submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift +++ b/submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift @@ -659,13 +659,13 @@ final class MediaReferenceRevalidationContext { } } - func story(accountPeerId: PeerId, postbox: Postbox, network: Network, background: Bool, peer: PeerReference, id: Int32) -> Signal { + func story(accountPeerId: PeerId, postbox: Postbox, network: Network, background: Bool, peer: PeerReference, id: Int32) -> Signal { return self.genericItem(key: .story(peer: peer, id: id), background: background, request: { next, error in - return (_internal_getStoryById(accountPeerId: accountPeerId, postbox: postbox, network: network, peer: peer, id: id) + return (_internal_getStoriesById(accountPeerId: accountPeerId, postbox: postbox, network: network, peer: peer, ids: [id]) |> castError(RevalidateMediaReferenceError.self) - |> mapToSignal { result -> Signal in - if let result = result { - return .single(result) + |> mapToSignal { result -> Signal in + if let item = result.first { + return .single(item) } else { return .fail(.generic) } @@ -675,8 +675,8 @@ final class MediaReferenceRevalidationContext { error(.generic) }) }) - |> mapToSignal { next -> Signal in - if let next = next as? StoryListContext.Item { + |> mapToSignal { next -> Signal in + if let next = next as? Stories.StoredItem { return .single(next) } else { return .fail(.generic) @@ -834,10 +834,14 @@ func revalidateMediaResourceReference(accountPeerId: PeerId, postbox: Postbox, n case let .story(peer, id, _): return revalidationContext.story(accountPeerId: accountPeerId, postbox: postbox, network: network, background: info.preferBackgroundReferenceRevalidation, peer: peer, id: id) |> mapToSignal { storyItem -> Signal in - if let updatedResource = findUpdatedMediaResource(media: storyItem.media._asMedia(), previousMedia: nil, resource: resource) { - return .single(RevalidatedMediaResource(updatedResource: updatedResource, updatedReference: nil)) + guard case let .item(item) = storyItem, let media = item.media else { + return .fail(.generic) + } + if let updatedResource = findUpdatedMediaResource(media: media, previousMedia: nil, resource: resource) { + return .single(RevalidatedMediaResource(updatedResource: updatedResource, updatedReference: nil)) + } else { + return .fail(.generic) } - return .fail(.generic) } case let .standalone(media): if let file = media as? TelegramMediaFile { diff --git a/submodules/TelegramCore/Sources/PendingMessages/StandaloneSendMessage.swift b/submodules/TelegramCore/Sources/PendingMessages/StandaloneSendMessage.swift index 3a715fe788..d7b7f5952d 100644 --- a/submodules/TelegramCore/Sources/PendingMessages/StandaloneSendMessage.swift +++ b/submodules/TelegramCore/Sources/PendingMessages/StandaloneSendMessage.swift @@ -104,9 +104,6 @@ private func sendMessageContent(account: Account, peerId: PeerId, attributes: [M } } - if let _ = replyMessageId { - flags |= Int32(1 << 0) - } if let _ = messageEntities { flags |= Int32(1 << 3) } @@ -120,12 +117,28 @@ private func sendMessageContent(account: Account, peerId: PeerId, attributes: [M let sendMessageRequest: Signal switch content { case let .text(text): - sendMessageRequest = account.network.request(Api.functions.messages.sendMessage(flags: flags, peer: inputPeer, replyToMsgId: replyMessageId, topMsgId: nil, message: text, randomId: uniqueId, replyMarkup: nil, entities: messageEntities, scheduleDate: scheduleTime, sendAs: sendAsInputPeer)) + var replyTo: Api.InputReplyTo? + if let replyMessageId = replyMessageId { + flags |= 1 << 0 + + let replyFlags: Int32 = 0 + replyTo = .inputReplyToMessage(flags: replyFlags, replyToMsgId: replyMessageId, topMsgId: nil) + } + + sendMessageRequest = account.network.request(Api.functions.messages.sendMessage(flags: flags, peer: inputPeer, replyTo: replyTo, message: text, randomId: uniqueId, replyMarkup: nil, entities: messageEntities, scheduleDate: scheduleTime, sendAs: sendAsInputPeer)) |> `catch` { _ -> Signal in return .complete() } case let .media(inputMedia, text): - sendMessageRequest = account.network.request(Api.functions.messages.sendMedia(flags: flags, peer: inputPeer, replyToMsgId: replyMessageId, topMsgId: nil, media: inputMedia, message: text, randomId: uniqueId, replyMarkup: nil, entities: messageEntities, scheduleDate: scheduleTime, sendAs: sendAsInputPeer)) + var replyTo: Api.InputReplyTo? + if let replyMessageId = replyMessageId { + flags |= 1 << 0 + + let replyFlags: Int32 = 0 + replyTo = .inputReplyToMessage(flags: replyFlags, replyToMsgId: replyMessageId, topMsgId: nil) + } + + sendMessageRequest = account.network.request(Api.functions.messages.sendMedia(flags: flags, peer: inputPeer, replyTo: replyTo, media: inputMedia, message: text, randomId: uniqueId, replyMarkup: nil, entities: messageEntities, scheduleDate: scheduleTime, sendAs: sendAsInputPeer)) |> `catch` { _ -> Signal in return .complete() } diff --git a/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift b/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift index aefbe13201..ddd782e3de 100644 --- a/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift +++ b/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift @@ -4377,7 +4377,7 @@ func replayFinalState( ))) for storyItem in stories { - if let parsedItem = _internal_parseApiStoryItem(transaction: transaction, peerId: peerId, apiStory: storyItem) { + if let parsedItem = Stories.StoredItem(apiStoryItem: storyItem, peerId: peerId, transaction: transaction) { storyUpdates.append(InternalStoryUpdate.added(peerId: peerId, item: parsedItem)) } else { storyUpdates.append(InternalStoryUpdate.deleted(peerId: peerId, id: storyItem.id)) @@ -4385,6 +4385,20 @@ func replayFinalState( } } case let .UpdateReadStories(peerId, maxId): + var appliedMaxReadId = maxId + if let currentState = transaction.getPeerStoryState(peerId: peerId)?.get(Stories.PeerState.self) { + appliedMaxReadId = max(appliedMaxReadId, currentState.maxReadId) + } + + var subscriptionsOpaqueState: String? + if let state = transaction.getSubscriptionsStoriesState()?.get(Stories.SubscriptionsState.self) { + subscriptionsOpaqueState = state.opaqueState + } + transaction.setPeerStoryState(peerId: peerId, state: CodableEntry(Stories.PeerState( + subscriptionsOpaqueState: subscriptionsOpaqueState, + maxReadId: appliedMaxReadId + ))) + storyUpdates.append(InternalStoryUpdate.read(peerId: peerId, maxId: maxId)) } } diff --git a/submodules/TelegramCore/Sources/State/PendingMessageManager.swift b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift index f6d18ad042..a2f41a7539 100644 --- a/submodules/TelegramCore/Sources/State/PendingMessageManager.swift +++ b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift @@ -855,9 +855,6 @@ public final class PendingMessageManager { } } else { flags |= (1 << 7) - if let _ = replyMessageId { - flags |= Int32(1 << 0) - } var sendAsInputPeer: Api.InputPeer? if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeerOrSelf(sendAsPeer, accountPeerId: accountPeerId) { @@ -913,7 +910,18 @@ public final class PendingMessageManager { topMsgId = Int32(clamping: threadId) } - sendMessageRequest = network.request(Api.functions.messages.sendMultiMedia(flags: flags, peer: inputPeer, replyToMsgId: replyMessageId, topMsgId: topMsgId, multiMedia: singleMedias, scheduleDate: scheduleTime, sendAs: sendAsInputPeer)) + var replyTo: Api.InputReplyTo? + if let replyMessageId = replyMessageId { + flags |= 1 << 0 + + var replyFlags: Int32 = 0 + if topMsgId != nil { + replyFlags |= 1 << 0 + } + replyTo = .inputReplyToMessage(flags: replyFlags, replyToMsgId: replyMessageId, topMsgId: topMsgId) + } + + sendMessageRequest = network.request(Api.functions.messages.sendMultiMedia(flags: flags, peer: inputPeer, replyTo: replyTo, multiMedia: singleMedias, scheduleDate: scheduleTime, sendAs: sendAsInputPeer)) } return sendMessageRequest @@ -1141,25 +1149,35 @@ public final class PendingMessageManager { flags |= Int32(1 << 15) } - var topMsgId: Int32? - if let threadId = message.threadId { - flags |= Int32(1 << 9) - topMsgId = Int32(clamping: threadId) + var replyTo: Api.InputReplyTo? + if let replyMessageId = replyMessageId { + flags |= 1 << 0 + + var replyFlags: Int32 = 0 + if message.threadId != nil { + replyFlags |= 1 << 0 + } + replyTo = .inputReplyToMessage(flags: replyFlags, replyToMsgId: replyMessageId, topMsgId: message.threadId.flatMap(Int32.init(clamping:))) } - sendMessageRequest = network.requestWithAdditionalInfo(Api.functions.messages.sendMessage(flags: flags, peer: inputPeer, replyToMsgId: replyMessageId, topMsgId: topMsgId, message: message.text, randomId: uniqueId, replyMarkup: nil, entities: messageEntities, scheduleDate: scheduleTime, sendAs: sendAsInputPeer), info: .acknowledgement, tag: dependencyTag) + sendMessageRequest = network.requestWithAdditionalInfo(Api.functions.messages.sendMessage(flags: flags, peer: inputPeer, replyTo: replyTo, message: message.text, randomId: uniqueId, replyMarkup: nil, entities: messageEntities, scheduleDate: scheduleTime, sendAs: sendAsInputPeer), info: .acknowledgement, tag: dependencyTag) case let .media(inputMedia, text): if bubbleUpEmojiOrStickersets { flags |= Int32(1 << 15) } - var topMsgId: Int32? - if let threadId = message.threadId { - flags |= Int32(1 << 9) - topMsgId = Int32(clamping: threadId) + var replyTo: Api.InputReplyTo? + if let replyMessageId = replyMessageId { + flags |= 1 << 0 + + var replyFlags: Int32 = 0 + if message.threadId != nil { + replyFlags |= 1 << 0 + } + replyTo = .inputReplyToMessage(flags: replyFlags, replyToMsgId: replyMessageId, topMsgId: message.threadId.flatMap(Int32.init(clamping:))) } - sendMessageRequest = network.request(Api.functions.messages.sendMedia(flags: flags, peer: inputPeer, replyToMsgId: replyMessageId, topMsgId: topMsgId, media: inputMedia, message: text, randomId: uniqueId, replyMarkup: nil, entities: messageEntities, scheduleDate: scheduleTime, sendAs: sendAsInputPeer), tag: dependencyTag) + sendMessageRequest = network.request(Api.functions.messages.sendMedia(flags: flags, peer: inputPeer, replyTo: replyTo, media: inputMedia, message: text, randomId: uniqueId, replyMarkup: nil, entities: messageEntities, scheduleDate: scheduleTime, sendAs: sendAsInputPeer), tag: dependencyTag) |> map(NetworkRequestResult.result) case let .forward(sourceInfo): var topMsgId: Int32? @@ -1179,16 +1197,26 @@ public final class PendingMessageManager { flags |= Int32(1 << 11) } - var topMsgId: Int32? - if let threadId = message.threadId { - flags |= Int32(1 << 9) - topMsgId = Int32(clamping: threadId) + var replyTo: Api.InputReplyTo? + if let replyMessageId = replyMessageId { + flags |= 1 << 0 + + var replyFlags: Int32 = 0 + if message.threadId != nil { + replyFlags |= 1 << 0 + } + replyTo = .inputReplyToMessage(flags: replyFlags, replyToMsgId: replyMessageId, topMsgId: message.threadId.flatMap(Int32.init(clamping:))) } - sendMessageRequest = network.request(Api.functions.messages.sendInlineBotResult(flags: flags, peer: inputPeer, replyToMsgId: replyMessageId, topMsgId: topMsgId, randomId: uniqueId, queryId: chatContextResult.queryId, id: chatContextResult.id, scheduleDate: scheduleTime, sendAs: sendAsInputPeer)) + sendMessageRequest = network.request(Api.functions.messages.sendInlineBotResult(flags: flags, peer: inputPeer, replyTo: replyTo, randomId: uniqueId, queryId: chatContextResult.queryId, id: chatContextResult.id, scheduleDate: scheduleTime, sendAs: sendAsInputPeer)) |> map(NetworkRequestResult.result) case .messageScreenshot: - sendMessageRequest = network.request(Api.functions.messages.sendScreenshotNotification(peer: inputPeer, replyToMsgId: replyMessageId ?? 0, randomId: uniqueId)) + var replyTo: Api.InputReplyTo + + let replyFlags: Int32 = 0 + replyTo = .inputReplyToMessage(flags: replyFlags, replyToMsgId: replyMessageId ?? 0, topMsgId: nil) + + sendMessageRequest = network.request(Api.functions.messages.sendScreenshotNotification(peer: inputPeer, replyTo: replyTo, randomId: uniqueId)) |> map(NetworkRequestResult.result) case .secretMedia: assertionFailure() diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift index 4446c36a22..9b180daf84 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/BotWebView.swift @@ -63,7 +63,15 @@ public enum RequestWebViewError { private func keepWebViewSignal(network: Network, stateManager: AccountStateManager, flags: Int32, peer: Api.InputPeer, bot: Api.InputUser, queryId: Int64, replyToMessageId: MessageId?, threadId: Int64?, sendAs: Api.InputPeer?) -> Signal { let signal = Signal { subscriber in let poll = Signal { subscriber in - let signal: Signal = network.request(Api.functions.messages.prolongWebView(flags: flags, peer: peer, bot: bot, queryId: queryId, replyToMsgId: replyToMessageId?.id, topMsgId: threadId.flatMap(Int32.init(clamping:)), sendAs: sendAs)) + var replyTo: Api.InputReplyTo? + if let replyToMessageId = replyToMessageId { + var replyFlags: Int32 = 0 + if threadId != nil { + replyFlags |= 1 << 0 + } + replyTo = .inputReplyToMessage(flags: replyFlags, replyToMsgId: replyToMessageId.id, topMsgId: threadId.flatMap(Int32.init(clamping:))) + } + let signal: Signal = network.request(Api.functions.messages.prolongWebView(flags: flags, peer: peer, bot: bot, queryId: queryId, replyTo: replyTo, sendAs: sendAs)) |> mapError { _ -> KeepWebViewError in return .generic } @@ -120,22 +128,25 @@ func _internal_requestWebView(postbox: Postbox, network: Network, stateManager: if let _ = serializedThemeParams { flags |= (1 << 2) } - var replyToMsgId: Int32? - if let replyToMessageId = replyToMessageId { - flags |= (1 << 0) - replyToMsgId = replyToMessageId.id - } if let _ = payload { flags |= (1 << 3) } if fromMenu { flags |= (1 << 4) } - if threadId != nil { - flags |= (1 << 9) + + var replyTo: Api.InputReplyTo? + if let replyToMessageId = replyToMessageId { + flags |= (1 << 0) + + var replyFlags: Int32 = 0 + if threadId != nil { + replyFlags |= 1 << 0 + } + replyTo = .inputReplyToMessage(flags: replyFlags, replyToMsgId: replyToMessageId.id, topMsgId: threadId.flatMap(Int32.init(clamping:))) } - return network.request(Api.functions.messages.requestWebView(flags: flags, peer: inputPeer, bot: inputBot, url: url, startParam: payload, themeParams: serializedThemeParams, platform: botWebViewPlatform, replyToMsgId: replyToMsgId, topMsgId: threadId.flatMap(Int32.init(clamping:)), sendAs: nil)) + return network.request(Api.functions.messages.requestWebView(flags: flags, peer: inputPeer, bot: inputBot, url: url, startParam: payload, themeParams: serializedThemeParams, platform: botWebViewPlatform, replyTo: replyTo, sendAs: nil)) |> mapError { _ -> RequestWebViewError in return .generic } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift index 12644911c0..5616f6e264 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Stories.swift @@ -704,8 +704,12 @@ extension Api.StoryItem { extension Stories.Item.Views { init(apiViews: Api.StoryViews) { switch apiViews { - case let .storyViews(recentViewers, viewsCount): - self.init(seenCount: Int(viewsCount), seenPeerIds: recentViewers.map { PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value($0)) }) + case let .storyViews(_, viewsCount, recentViewers): + var seenPeerIds: [PeerId] = [] + if let recentViewers = recentViewers { + seenPeerIds = recentViewers.map { PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value($0)) } + } + self.init(seenCount: Int(viewsCount), seenPeerIds: seenPeerIds) } } } @@ -769,69 +773,42 @@ extension Stories.StoredItem { } } -func _internal_parseApiStoryItem(transaction: Transaction, peerId: PeerId, apiStory: Api.StoryItem) -> StoryListContext.Item? { - switch apiStory { - case let .storyItem(flags, id, date, caption, entities, media, privacy, views): - let _ = flags - let (parsedMedia, _, _, _) = textMediaAndExpirationTimerFromApiMedia(media, peerId) - if let parsedMedia = parsedMedia { - var parsedPrivacy: EngineStoryPrivacy? - if let privacy = privacy { - var base: EngineStoryPrivacy.Base = .everyone - var additionalPeerIds: [EnginePeer.Id] = [] - for rule in privacy { - switch rule { - case .privacyValueAllowAll: - base = .everyone - case .privacyValueAllowContacts: - base = .contacts - case .privacyValueAllowCloseFriends: - base = .closeFriends - case let .privacyValueAllowUsers(users): - for id in users { - additionalPeerIds.append(EnginePeer.Id(namespace: Namespaces.Peer.CloudUser, id: EnginePeer.Id.Id._internalFromInt64Value(id))) - } - case let .privacyValueAllowChatParticipants(chats): - for id in chats { - if let peer = transaction.getPeer(EnginePeer.Id(namespace: Namespaces.Peer.CloudGroup, id: EnginePeer.Id.Id._internalFromInt64Value(id))) { - additionalPeerIds.append(peer.id) - } else if let peer = transaction.getPeer(EnginePeer.Id(namespace: Namespaces.Peer.CloudChannel, id: EnginePeer.Id.Id._internalFromInt64Value(id))) { - additionalPeerIds.append(peer.id) - } - } - default: - break - } - } - parsedPrivacy = EngineStoryPrivacy(base: base, additionallyIncludePeers: additionalPeerIds) - } - - let item = StoryListContext.Item( - id: id, - timestamp: date, - media: EngineMedia(parsedMedia), - text: caption ?? "", - entities: entities.flatMap { entities in return messageTextEntitiesFromApiEntities(entities) } ?? [], - views: views.flatMap { _internal_parseApiStoryViews(transaction: transaction, views: $0) }, - privacy: parsedPrivacy - ) - return item - } else { - return nil - } - case .storyItemSkipped: - return nil - case .storyItemDeleted: - return nil +func _internal_getStoriesById(accountPeerId: PeerId, postbox: Postbox, network: Network, peer: PeerReference, ids: [Int32]) -> Signal<[Stories.StoredItem], NoError> { + guard let inputUser = peer.inputUser else { + return .single([]) } -} - -func _internal_parseApiStoryViews(transaction: Transaction, views: Api.StoryViews) -> StoryListContext.Views { - switch views { - case let .storyViews(recentViewers, viewsCount): - return StoryListContext.Views(seenCount: Int(viewsCount), seenPeers: recentViewers.compactMap { id -> EnginePeer? in - return transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(id))).flatMap(EnginePeer.init) - }) + + return network.request(Api.functions.stories.getStoriesByID(userId: inputUser, id: ids)) + |> map(Optional.init) + |> `catch` { _ -> Signal in + return .single(nil) + } + |> mapToSignal { result -> Signal<[Stories.StoredItem], NoError> in + guard let result = result else { + return .single([]) + } + return postbox.transaction { transaction -> [Stories.StoredItem] in + switch result { + case let .stories(_, stories, users): + var peers: [Peer] = [] + var peerPresences: [PeerId: Api.User] = [:] + + for user in users { + let telegramUser = TelegramUser(user: user) + peers.append(telegramUser) + peerPresences[telegramUser.id] = user + } + + updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer in + return updated + }) + updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: peerPresences) + + return stories.compactMap { apiStoryItem -> Stories.StoredItem? in + return Stories.StoredItem(apiStoryItem: apiStoryItem, peerId: peer.id, transaction: transaction) + } + } + } } } @@ -879,42 +856,6 @@ func _internal_getStoriesById(accountPeerId: PeerId, postbox: Postbox, network: } } -func _internal_getStoryById(accountPeerId: PeerId, postbox: Postbox, network: Network, peer: PeerReference, id: Int32) -> Signal { - guard let inputUser = peer.inputUser else { - return .single(nil) - } - return network.request(Api.functions.stories.getStoriesByID(userId: inputUser, id: [id])) - |> map(Optional.init) - |> `catch` { _ -> Signal in - return .single(nil) - } - |> mapToSignal { result -> Signal in - guard let result = result else { - return .single(nil) - } - return postbox.transaction { transaction -> StoryListContext.Item? in - switch result { - case let .stories(_, stories, users): - var peers: [Peer] = [] - var peerPresences: [PeerId: Api.User] = [:] - - for user in users { - let telegramUser = TelegramUser(user: user) - peers.append(telegramUser) - peerPresences[telegramUser.id] = user - } - - updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer in - return updated - }) - updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: peerPresences) - - return stories.first.flatMap { _internal_parseApiStoryItem(transaction: transaction, peerId: peer.id, apiStory: $0) } - } - } - } -} - public final class StoryViewList { public final class Item { public let peer: EnginePeer @@ -978,18 +919,18 @@ func _internal_getStoryViewList(account: Account, id: Int32, offsetTimestamp: In } } -func _internal_getStoryViews(account: Account, ids: [Int32]) -> Signal<[Int32: StoryListContext.Views], NoError> { +func _internal_getStoryViews(account: Account, ids: [Int32]) -> Signal<[Int32: Stories.Item.Views], NoError> { return account.network.request(Api.functions.stories.getStoriesViews(id: ids)) |> map(Optional.init) |> `catch` { _ -> Signal in return .single(nil) } - |> mapToSignal { result -> Signal<[Int32: StoryListContext.Views], NoError> in + |> mapToSignal { result -> Signal<[Int32: Stories.Item.Views], NoError> in guard let result = result else { return .single([:]) } - return account.postbox.transaction { transaction -> [Int32: StoryListContext.Views] in - var parsedViews: [Int32: StoryListContext.Views] = [:] + return account.postbox.transaction { transaction -> [Int32: Stories.Item.Views] in + var parsedViews: [Int32: Stories.Item.Views] = [:] switch result { case let .storyViews(views, users): var peers: [Peer] = [] @@ -1008,7 +949,7 @@ func _internal_getStoryViews(account: Account, ids: [Int32]) -> Signal<[Int32: S for i in 0 ..< views.count { if i < ids.count { - parsedViews[ids[i]] = _internal_parseApiStoryViews(transaction: transaction, views: views[i]) + parsedViews[ids[i]] = Stories.Item.Views(apiViews: views[i]) } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift index 6ae73d4b5e..ad4d0d552d 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift @@ -5,10 +5,75 @@ import SwiftSignalKit enum InternalStoryUpdate { case deleted(peerId: PeerId, id: Int32) - case added(peerId: PeerId, item: StoryListContext.Item) + case added(peerId: PeerId, item: Stories.StoredItem) case read(peerId: PeerId, maxId: Int32) } +public final class EngineStoryItem: Equatable { + public final class Views: Equatable { + public let seenCount: Int + public let seenPeers: [EnginePeer] + + public init(seenCount: Int, seenPeers: [EnginePeer]) { + self.seenCount = seenCount + self.seenPeers = seenPeers + } + + public static func ==(lhs: Views, rhs: Views) -> Bool { + if lhs.seenCount != rhs.seenCount { + return false + } + if lhs.seenPeers != rhs.seenPeers { + return false + } + return true + } + } + + public let id: Int32 + public let timestamp: Int32 + public let media: EngineMedia + public let text: String + public let entities: [MessageTextEntity] + public let views: Views? + public let privacy: EngineStoryPrivacy? + + public init(id: Int32, timestamp: Int32, media: EngineMedia, text: String, entities: [MessageTextEntity], views: Views?, privacy: EngineStoryPrivacy?) { + self.id = id + self.timestamp = timestamp + self.media = media + self.text = text + self.entities = entities + self.views = views + self.privacy = privacy + } + + public static func ==(lhs: EngineStoryItem, rhs: EngineStoryItem) -> Bool { + if lhs.id != rhs.id { + return false + } + if lhs.timestamp != rhs.timestamp { + return false + } + if lhs.media != rhs.media { + return false + } + if lhs.text != rhs.text { + return false + } + if lhs.entities != rhs.entities { + return false + } + if lhs.views != rhs.views { + return false + } + if lhs.privacy != rhs.privacy { + return false + } + return true + } +} + public final class StorySubscriptionsContext { private enum OpaqueStateMark: Equatable { case empty @@ -158,7 +223,9 @@ public final class StorySubscriptionsContext { refreshId: currentState?.refreshId ?? UInt64.random(in: 0 ... UInt64.max), hasMore: hasMore ))) - case let .allStories(flags, state, userStories, users): + case let .allStories(flags, _, state, userStories, users): + //TODO:count + var peers: [Peer] = [] var peerPresences: [PeerId: Api.User] = [:] @@ -264,927 +331,3 @@ public final class StorySubscriptionsContext { } } } - -public final class PeerStoryFocusContext { - private final class Impl { - private let queue: Queue - private let account: Account - private let peerId: PeerId - private let focusItemId: Int32? - - let state = Promise() - private var disposable: Disposable? - - private var isLoadingPlaceholder: Bool = false - private let loadDisposable = MetaDisposable() - private var placeholderLoadWasUnsuccessful: Bool = false - - init( - queue: Queue, - account: Account, - peerId: PeerId, - focusItemId: Int32? - ) { - self.queue = queue - self.account = account - self.peerId = peerId - self.focusItemId = focusItemId - - self.disposable = (account.postbox.combinedView(keys: [ - PostboxViewKey.storiesState(key: .peer(peerId)), - PostboxViewKey.storyItems(peerId: peerId) - ]) - |> deliverOn(self.queue)).start(next: { [weak self] views in - guard let `self` = self else { - return - } - guard let peerStateView = views.views[PostboxViewKey.storiesState(key: .peer(peerId))] as? StoryStatesView else { - return - } - guard let itemsView = views.views[PostboxViewKey.storyItems(peerId: peerId)] as? StoryItemsView else { - return - } - - let peerState = peerStateView.value?.get(Stories.PeerState.self) - - let items = itemsView.items.compactMap { $0.value.get(Stories.StoredItem.self) } - var item: (value: Stories.StoredItem, position: Int, previousId: Int32?, nextId: Int32?)? - - var focusItemId = self.focusItemId - if focusItemId == nil { - if let peerState = peerState { - focusItemId = peerState.maxReadId + 1 - } - } - - if let focusItemId = focusItemId { - if let index = items.firstIndex(where: { $0.id >= focusItemId }) { - var previousId: Int32? - var nextId: Int32? - if index != 0 { - previousId = items[index - 1].id - } - if index != items.count - 1 { - nextId = items[index + 1].id - } - - item = (items[index], index, previousId, nextId) - } else { - if !items.isEmpty { - var nextId: Int32? - if 0 != items.count - 1 { - nextId = items[0 + 1].id - } - item = (items[0], 0, nil, nextId) - } - } - } else { - if !items.isEmpty { - var nextId: Int32? - if 0 != items.count - 1 { - nextId = items[0 + 1].id - } - item = (items[0], 0, nil, nextId) - } - } - - if let (item, position, previousId, nextId) = item { - switch item { - case let .item(item): - self.state.set(.single(State(item: item, previousId: previousId, nextId: nextId, isLoading: false, count: items.count, position: position))) - case .placeholder: - let count = items.count - - if !self.isLoadingPlaceholder { - self.isLoadingPlaceholder = true - self.loadDisposable.set((_internal_getStoriesById( - accountPeerId: self.account.peerId, - postbox: self.account.postbox, - network: self.account.network, - peerId: self.peerId, - ids: [item.id] - ) - |> deliverOn(self.queue)).start(next: { [weak self] result in - guard let self else { - return - } - if let loadedItem = result.first, case let .item(item) = loadedItem { - self.state.set(.single(State(item: item, previousId: previousId, nextId: nextId, isLoading: false, count: count, position: position))) - } else { - self.placeholderLoadWasUnsuccessful = false - self.state.set(.single(State(item: nil, previousId: nil, nextId: nil, isLoading: !self.placeholderLoadWasUnsuccessful, count: count, position: position))) - } - })) - } - self.state.set(.single(State(item: nil, previousId: nil, nextId: nil, isLoading: !self.placeholderLoadWasUnsuccessful, count: count, position: position))) - } - } else { - self.state.set(.single(State(item: nil, previousId: nil, nextId: nil, isLoading: false, count: 0, position: 0))) - } - }) - } - - deinit { - self.disposable?.dispose() - self.loadDisposable.dispose() - } - } - - public final class State: Equatable { - public let item: Stories.Item? - public let previousId: Int32? - public let nextId: Int32? - public let isLoading: Bool - public let count: Int - public let position: Int - - public init( - item: Stories.Item?, - previousId: Int32?, - nextId: Int32?, - isLoading: Bool, - count: Int, - position: Int - ) { - self.item = item - self.previousId = previousId - self.nextId = nextId - self.isLoading = isLoading - self.count = count - self.position = position - } - - public static func ==(lhs: State, rhs: State) -> Bool { - if lhs.item != rhs.item { - return false - } - if lhs.previousId != rhs.previousId { - return false - } - if lhs.nextId != rhs.nextId { - return false - } - if lhs.isLoading != rhs.isLoading { - return false - } - if lhs.count != rhs.count { - return false - } - if lhs.position != rhs.position { - return false - } - return true - } - } - - private static let sharedQueue = Queue(name: "PeerStoryFocusContext") - private let queue: Queue - private let impl: QueueLocalObject - - public var state: Signal { - return self.impl.signalWith { impl, subscriber in - return impl.state.get().start(next: subscriber.putNext) - } - } - - init( - account: Account, - peerId: PeerId, - focusItemId: Int32? - ) { - let queue = PeerStoryFocusContext.sharedQueue - self.queue = queue - self.impl = QueueLocalObject(queue: queue, generate: { - return Impl(queue: queue, account: account, peerId: peerId, focusItemId: focusItemId) - }) - } -} - -public final class StoryListContext { - public enum Scope { - case all - case peer(EnginePeer.Id) - } - - public struct Views: Equatable { - public var seenCount: Int - public var seenPeers: [EnginePeer] - - public init(seenCount: Int, seenPeers: [EnginePeer]) { - self.seenCount = seenCount - self.seenPeers = seenPeers - } - } - - public final class Item: Equatable { - public let id: Int32 - public let timestamp: Int32 - public let media: EngineMedia - public let text: String - public let entities: [MessageTextEntity] - public let views: Views? - public let privacy: EngineStoryPrivacy? - - public init(id: Int32, timestamp: Int32, media: EngineMedia, text: String, entities: [MessageTextEntity], views: Views?, privacy: EngineStoryPrivacy?) { - self.id = id - self.timestamp = timestamp - self.media = media - self.text = text - self.entities = entities - self.views = views - self.privacy = privacy - } - - public static func ==(lhs: Item, rhs: Item) -> Bool { - if lhs.id != rhs.id { - return false - } - if lhs.timestamp != rhs.timestamp { - return false - } - if lhs.media != rhs.media { - return false - } - if lhs.text != rhs.text { - return false - } - if lhs.entities != rhs.entities { - return false - } - if lhs.views != rhs.views { - return false - } - if lhs.privacy != rhs.privacy { - return false - } - return true - } - } - - public final class PeerItemSet: Equatable { - public let peerId: EnginePeer.Id - public let peer: EnginePeer? - public var maxReadId: Int32 - public fileprivate(set) var items: [Item] - public fileprivate(set) var totalCount: Int? - - public init(peerId: EnginePeer.Id, peer: EnginePeer?, maxReadId: Int32, items: [Item], totalCount: Int?) { - self.peerId = peerId - self.peer = peer - self.maxReadId = maxReadId - self.items = items - self.totalCount = totalCount - } - - public static func ==(lhs: PeerItemSet, rhs: PeerItemSet) -> Bool { - if lhs.peerId != rhs.peerId { - return false - } - if lhs.peer != rhs.peer { - return false - } - if lhs.maxReadId != rhs.maxReadId { - return false - } - if lhs.items != rhs.items { - return false - } - if lhs.totalCount != rhs.totalCount { - return false - } - return true - } - } - - public final class LoadMoreToken: Equatable { - fileprivate let value: String? - - init(value: String?) { - self.value = value - } - - public static func ==(lhs: LoadMoreToken, rhs: LoadMoreToken) -> Bool { - if lhs.value != rhs.value { - return false - } - return true - } - } - - public struct State: Equatable { - public var itemSets: [PeerItemSet] - public var uploadProgress: CGFloat? - public var loadMoreToken: LoadMoreToken? - - public init(itemSets: [PeerItemSet], uploadProgress: CGFloat?, loadMoreToken: LoadMoreToken?) { - self.itemSets = itemSets - self.uploadProgress = uploadProgress - self.loadMoreToken = loadMoreToken - } - } - - private final class UploadContext { - let disposable = MetaDisposable() - - init() { - } - } - - private final class Impl { - private let queue: Queue - private let account: Account - private let scope: Scope - - private let loadMoreDisposable = MetaDisposable() - private var isLoadingMore = false - - private var pollDisposable: Disposable? - private var updatesDisposable: Disposable? - private var peerDisposables: [PeerId: Disposable] = [:] - - private var uploadContexts: [UploadContext] = [] { - didSet { - self.stateValue.uploadProgress = self.uploadContexts.isEmpty ? nil : 0.0 - } - } - - private var stateValue: State { - didSet { - self.state.set(.single(self.stateValue)) - } - } - let state = Promise() - - init(queue: Queue, account: Account, scope: Scope) { - self.queue = queue - self.account = account - self.scope = scope - - self.stateValue = State(itemSets: [], uploadProgress: nil, loadMoreToken: LoadMoreToken(value: nil)) - self.state.set(.single(self.stateValue)) - - if case .all = scope { - let _ = (account.postbox.transaction { transaction -> Peer? in - return transaction.getPeer(account.peerId) - } - |> deliverOnMainQueue).start(next: { [weak self] peer in - guard let `self` = self, let peer = peer else { - return - } - self.stateValue = State(itemSets: [ - PeerItemSet(peerId: peer.id, peer: EnginePeer(peer), maxReadId: 0, items: [], totalCount: 0) - ], uploadProgress: nil, loadMoreToken: LoadMoreToken(value: nil)) - }) - } - - self.updatesDisposable = (account.stateManager.storyUpdates - |> deliverOn(queue)).start(next: { [weak self] updates in - if updates.isEmpty { - return - } - - let _ = account.postbox.transaction({ transaction -> [PeerId: Peer] in - var peers: [PeerId: Peer] = [:] - - if let peer = transaction.getPeer(account.peerId) { - peers[peer.id] = peer - } - - for update in updates { - switch update { - case let .added(peerId, _): - if peers[peerId] == nil, let peer = transaction.getPeer(peerId) { - peers[peer.id] = peer - } - case .deleted: - break - case .read: - break - } - } - return peers - }).start(next: { peers in - guard let `self` = self else { - return - } - if self.isLoadingMore { - return - } - - var itemSets: [PeerItemSet] = self.stateValue.itemSets - - for update in updates { - switch update { - case let .deleted(peerId, id): - for i in 0 ..< itemSets.count { - if itemSets[i].peerId == peerId { - if let index = itemSets[i].items.firstIndex(where: { $0.id == id }) { - var items = itemSets[i].items - items.remove(at: index) - itemSets[i] = PeerItemSet( - peerId: itemSets[i].peerId, - peer: itemSets[i].peer, - maxReadId: itemSets[i].maxReadId, - items: items, - totalCount: items.count - ) - } - } - } - case let .added(peerId, item): - var found = false - for i in 0 ..< itemSets.count { - if itemSets[i].peerId == peerId { - found = true - - var items = itemSets[i].items - if let index = items.firstIndex(where: { $0.id == item.id }) { - items.remove(at: index) - } - - items.append(item) - - items.sort(by: { lhsItem, rhsItem in - if lhsItem.timestamp != rhsItem.timestamp { - switch scope { - case .all: - return lhsItem.timestamp < rhsItem.timestamp - case .peer: - return lhsItem.timestamp < rhsItem.timestamp - } - } - return lhsItem.id < rhsItem.id - }) - itemSets[i] = PeerItemSet( - peerId: itemSets[i].peerId, - peer: itemSets[i].peer, - maxReadId: itemSets[i].maxReadId, - items: items, - totalCount: items.count - ) - } - } - if !found, let peer = peers[peerId] { - let matchesScope: Bool - if case .all = scope { - matchesScope = true - } else if case .peer(peerId) = scope { - matchesScope = true - } else { - matchesScope = false - } - if matchesScope { - itemSets.insert(PeerItemSet( - peerId: peerId, - peer: EnginePeer(peer), - maxReadId: 0, - items: [item], - totalCount: 1 - ), at: 0) - } - } - case let .read(peerId, maxId): - for i in 0 ..< itemSets.count { - if itemSets[i].peerId == peerId { - let items = itemSets[i].items - itemSets[i] = PeerItemSet( - peerId: itemSets[i].peerId, - peer: itemSets[i].peer, - maxReadId: max(itemSets[i].maxReadId, maxId), - items: items, - totalCount: items.count - ) - } - } - } - } - - itemSets.sort(by: { lhs, rhs in - guard let lhsItem = lhs.items.last, let rhsItem = rhs.items.last else { - if lhs.items.first != nil { - return false - } else { - return true - } - } - - if lhsItem.timestamp != rhsItem.timestamp { - switch scope { - case .all: - return lhsItem.timestamp > rhsItem.timestamp - case .peer: - return lhsItem.timestamp < rhsItem.timestamp - } - } - return lhsItem.id > rhsItem.id - }) - - if !itemSets.contains(where: { $0.peerId == self.account.peerId }) { - if let peer = peers[self.account.peerId] { - itemSets.insert(PeerItemSet(peerId: peer.id, peer: EnginePeer(peer), maxReadId: 0, items: [], totalCount: 0), at: 0) - } - } - - self.stateValue.itemSets = itemSets - }) - }) - - self.loadMore(refresh: true) - } - - deinit { - self.loadMoreDisposable.dispose() - self.pollDisposable?.dispose() - for (_, disposable) in self.peerDisposables { - disposable.dispose() - } - } - - func loadPeer(id: EnginePeer.Id) { - if self.peerDisposables[id] == nil { - let disposable = MetaDisposable() - self.peerDisposables[id] = disposable - - let account = self.account - let queue = self.queue - - disposable.set((self.account.postbox.transaction { transaction -> Api.InputUser? in - return transaction.getPeer(id).flatMap(apiInputUser) - } - |> mapToSignal { inputPeer -> Signal in - guard let inputPeer = inputPeer else { - return .single(nil) - } - return account.network.request(Api.functions.stories.getUserStories(flags: 0, userId: inputPeer, offsetId: 0, limit: 30)) - |> map(Optional.init) - |> `catch` { _ -> Signal in - return .single(nil) - } - |> mapToSignal { stories -> Signal in - guard let stories = stories else { - return .single(nil) - } - return account.postbox.transaction { transaction -> PeerItemSet? in - switch stories { - case let .stories(_, apiStories, users): - var parsedItemSets: [PeerItemSet] = [] - - var peers: [Peer] = [] - var peerPresences: [PeerId: Api.User] = [:] - - for user in users { - let telegramUser = TelegramUser(user: user) - peers.append(telegramUser) - peerPresences[telegramUser.id] = user - } - - updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer in - return updated - }) - updatePeerPresences(transaction: transaction, accountPeerId: account.peerId, peerPresences: peerPresences) - - let peerId = id - - for apiStory in apiStories { - if let item = _internal_parseApiStoryItem(transaction: transaction, peerId: peerId, apiStory: apiStory) { - if !parsedItemSets.isEmpty && parsedItemSets[parsedItemSets.count - 1].peerId == peerId { - parsedItemSets[parsedItemSets.count - 1].items.append(item) - parsedItemSets[parsedItemSets.count - 1].totalCount = parsedItemSets[parsedItemSets.count - 1].items.count - } else { - parsedItemSets.append(StoryListContext.PeerItemSet(peerId: peerId, peer: transaction.getPeer(peerId).flatMap(EnginePeer.init), maxReadId: 0, items: [item], totalCount: 1)) - } - } - } - - return parsedItemSets.first - } - } - } - } - |> deliverOn(queue)).start(next: { [weak self] itemSet in - guard let `self` = self, let itemSet = itemSet else { - return - } - var itemSets = self.stateValue.itemSets - if let index = itemSets.firstIndex(where: { $0.peerId == id }) { - itemSets[index] = itemSet - } else { - itemSets.append(itemSet) - } - self.stateValue.itemSets = itemSets - })) - } - } - - func upload(media: EngineStoryInputMedia, text: String, entities: [MessageTextEntity], privacy: EngineStoryPrivacy) { - let uploadContext = UploadContext() - self.uploadContexts.append(uploadContext) - uploadContext.disposable.set((_internal_uploadStory(account: self.account, media: media, text: text, entities: entities, privacy: privacy) - |> deliverOn(self.queue)).start(next: { _ in - }, completed: { [weak self, weak uploadContext] in - guard let `self` = self, let uploadContext = uploadContext else { - return - } - if let index = self.uploadContexts.firstIndex(where: { $0 === uploadContext }) { - self.uploadContexts.remove(at: index) - } - })) - } - - func loadMore(refresh: Bool) { - if self.isLoadingMore { - return - } - - var effectiveLoadMoreToken: String? - if refresh { - effectiveLoadMoreToken = "" - } else if let loadMoreToken = self.stateValue.loadMoreToken { - effectiveLoadMoreToken = loadMoreToken.value ?? "" - } - guard let loadMoreToken = effectiveLoadMoreToken else { - return - } - let _ = loadMoreToken - - self.isLoadingMore = true - let account = self.account - let scope = self.scope - - self.pollDisposable?.dispose() - self.pollDisposable = nil - - switch scope { - case .all: - self.loadMoreDisposable.set((account.network.request(Api.functions.stories.getAllStories(flags: 0, state: nil)) - |> map(Optional.init) - |> `catch` { _ -> Signal in - return .single(nil) - } - |> mapToSignal { result -> Signal<([PeerItemSet], LoadMoreToken?), NoError> in - guard let result = result else { - return .single(([], nil)) - } - return account.postbox.transaction { transaction -> ([PeerItemSet], LoadMoreToken?) in - switch result { - case let .allStories(_, state, userStorySets, users): - let _ = state - var parsedItemSets: [PeerItemSet] = [] - - var peers: [Peer] = [] - var peerPresences: [PeerId: Api.User] = [:] - - for user in users { - let telegramUser = TelegramUser(user: user) - peers.append(telegramUser) - peerPresences[telegramUser.id] = user - } - - updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer in - return updated - }) - updatePeerPresences(transaction: transaction, accountPeerId: account.peerId, peerPresences: peerPresences) - - for userStories in userStorySets { - let apiUserId: Int64 - let apiStories: [Api.StoryItem] - var apiTotalCount: Int32? - var apiMaxReadId: Int32 = 0 - switch userStories { - case let .userStories(_, userId, maxReadId, stories): - apiUserId = userId - apiStories = stories - apiTotalCount = Int32(stories.count) - apiMaxReadId = maxReadId ?? 0 - } - - let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(apiUserId)) - for apiStory in apiStories { - if let item = _internal_parseApiStoryItem(transaction: transaction, peerId: peerId, apiStory: apiStory) { - if !parsedItemSets.isEmpty && parsedItemSets[parsedItemSets.count - 1].peerId == peerId { - parsedItemSets[parsedItemSets.count - 1].items.append(item) - } else { - parsedItemSets.append(StoryListContext.PeerItemSet( - peerId: peerId, - peer: transaction.getPeer(peerId).flatMap(EnginePeer.init), - maxReadId: apiMaxReadId, - items: [item], - totalCount: apiTotalCount.flatMap(Int.init) - )) - } - } - } - } - - if !parsedItemSets.contains(where: { $0.peerId == account.peerId }) { - if let peer = transaction.getPeer(account.peerId) { - parsedItemSets.insert(PeerItemSet(peerId: peer.id, peer: EnginePeer(peer), maxReadId: 0, items: [], totalCount: 0), at: 0) - } - } - - return (parsedItemSets, nil) - case .allStoriesNotModified: - return ([], nil) - } - } - } - |> deliverOn(self.queue)).start(next: { [weak self] result in - guard let `self` = self else { - return - } - self.isLoadingMore = false - - var itemSets = self.stateValue.itemSets - for itemSet in result.0 { - if let index = itemSets.firstIndex(where: { $0.peerId == itemSet.peerId }) { - let currentItemSet = itemSets[index] - - var items = currentItemSet.items - for item in itemSet.items { - if !items.contains(where: { $0.id == item.id }) { - items.append(item) - } - } - - items.sort(by: { lhsItem, rhsItem in - if lhsItem.timestamp != rhsItem.timestamp { - switch scope { - case .all: - return lhsItem.timestamp < rhsItem.timestamp - case .peer: - return lhsItem.timestamp < rhsItem.timestamp - } - } - return lhsItem.id < rhsItem.id - }) - - itemSets[index] = PeerItemSet( - peerId: itemSet.peerId, - peer: itemSet.peer, - maxReadId: itemSet.maxReadId, - items: items, - totalCount: items.count - ) - } else { - itemSet.items.sort(by: { lhsItem, rhsItem in - if lhsItem.timestamp != rhsItem.timestamp { - switch scope { - case .all: - return lhsItem.timestamp < rhsItem.timestamp - case .peer: - return lhsItem.timestamp < rhsItem.timestamp - } - } - return lhsItem.id < rhsItem.id - }) - itemSets.append(itemSet) - } - } - - itemSets.sort(by: { lhs, rhs in - guard let lhsItem = lhs.items.last, let rhsItem = rhs.items.last else { - if lhs.items.last != nil { - return false - } else { - return true - } - } - - if lhsItem.timestamp != rhsItem.timestamp { - switch scope { - case .all: - return lhsItem.timestamp > rhsItem.timestamp - case .peer: - return lhsItem.timestamp < rhsItem.timestamp - } - } - return lhsItem.id > rhsItem.id - }) - - self.stateValue = State(itemSets: itemSets, uploadProgress: self.stateValue.uploadProgress, loadMoreToken: result.1) - })) - case let .peer(peerId): - let account = self.account - let queue = self.queue - - self.loadMoreDisposable.set((self.account.postbox.transaction { transaction -> Api.InputUser? in - return transaction.getPeer(peerId).flatMap(apiInputUser) - } - |> mapToSignal { inputPeer -> Signal in - guard let inputPeer = inputPeer else { - return .single(nil) - } - return account.network.request(Api.functions.stories.getUserStories(flags: 0, userId: inputPeer, offsetId: 0, limit: 30)) - |> map(Optional.init) - |> `catch` { _ -> Signal in - return .single(nil) - } - |> mapToSignal { stories -> Signal in - guard let stories = stories else { - return .single(nil) - } - return account.postbox.transaction { transaction -> PeerItemSet? in - switch stories { - case let .stories(_, apiStories, users): - var parsedItemSets: [PeerItemSet] = [] - - var peers: [Peer] = [] - var peerPresences: [PeerId: Api.User] = [:] - - for user in users { - let telegramUser = TelegramUser(user: user) - peers.append(telegramUser) - peerPresences[telegramUser.id] = user - } - - updatePeers(transaction: transaction, peers: peers, update: { _, updated -> Peer in - return updated - }) - updatePeerPresences(transaction: transaction, accountPeerId: account.peerId, peerPresences: peerPresences) - - for apiStory in apiStories { - if let item = _internal_parseApiStoryItem(transaction: transaction, peerId: peerId, apiStory: apiStory) { - if !parsedItemSets.isEmpty && parsedItemSets[parsedItemSets.count - 1].peerId == peerId { - parsedItemSets[parsedItemSets.count - 1].items.append(item) - parsedItemSets[parsedItemSets.count - 1].totalCount = parsedItemSets[parsedItemSets.count - 1].items.count - } else { - parsedItemSets.append(StoryListContext.PeerItemSet(peerId: peerId, peer: transaction.getPeer(peerId).flatMap(EnginePeer.init), maxReadId: 0, items: [item], totalCount: 1)) - } - } - } - - return parsedItemSets.first - } - } - } - } - |> deliverOn(queue)).start(next: { [weak self] itemSet in - guard let `self` = self, let itemSet = itemSet else { - return - } - self.isLoadingMore = false - self.stateValue.itemSets = [itemSet] - })) - } - } - - func delete(id: Int32) { - let _ = _internal_deleteStory(account: self.account, id: id).start() - - var itemSets: [PeerItemSet] = self.stateValue.itemSets - for i in (0 ..< itemSets.count).reversed() { - if let index = itemSets[i].items.firstIndex(where: { $0.id == id }) { - var items = itemSets[i].items - items.remove(at: index) - if items.isEmpty { - itemSets.remove(at: i) - } else { - itemSets[i] = PeerItemSet( - peerId: itemSets[i].peerId, - peer: itemSets[i].peer, - maxReadId: itemSets[i].maxReadId, - items: items, - totalCount: items.count - ) - } - } - } - self.stateValue.itemSets = itemSets - } - } - - private let queue: Queue - private let impl: QueueLocalObject - - public var state: Signal { - return self.impl.signalWith { impl, subscriber in - return impl.state.get().start(next: subscriber.putNext) - } - } - - init(account: Account, scope: Scope) { - let queue = Queue.mainQueue() - self.queue = queue - self.impl = QueueLocalObject(queue: queue, generate: { - return Impl(queue: queue, account: account, scope: scope) - }) - } - - public func delete(id: Int32) { - self.impl.with { impl in - impl.delete(id: id) - } - } - - public func upload(media: EngineStoryInputMedia, text: String, entities: [MessageTextEntity], privacy: EngineStoryPrivacy) { - self.impl.with { impl in - impl.upload(media: media, text: text, entities: entities, privacy: privacy) - } - } - - public func loadPeer(id: EnginePeer.Id) { - self.impl.with { impl in - impl.loadPeer(id: id) - } - } -} diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift index e2fa3dca75..16daa8c10c 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -774,7 +774,7 @@ public extension TelegramEngine { let resource = MediaResourceReference.media(media: .story(peer: peerReference, id: item.id, media: file), resource: file.resource) resultResources[EngineMediaResource.Id(resource.resource.id)] = StoryPreloadInfo( resource: resource, - size: nil, + size: file.preloadSize, priority: .top(position: nextPriority) ) nextPriority += 1 @@ -788,10 +788,6 @@ public extension TelegramEngine { } } - public func peerStoryFocusContext(id: EnginePeer.Id, focusItemId: Int32?) -> PeerStoryFocusContext { - return PeerStoryFocusContext(account: self.account, peerId: id, focusItemId: focusItemId) - } - public func refreshStories(peerId: EnginePeer.Id, ids: [Int32]) -> Signal { return _internal_getStoriesById(accountPeerId: self.account.peerId, postbox: self.account.postbox, network: self.account.network, peerId: peerId, ids: ids) |> mapToSignal { result -> Signal in @@ -812,10 +808,6 @@ public extension TelegramEngine { } } - public func peerStories(id: EnginePeer.Id) -> StoryListContext { - return StoryListContext(account: self.account, scope: .peer(id)) - } - public func uploadStory(media: EngineStoryInputMedia, text: String, entities: [MessageTextEntity], privacy: EngineStoryPrivacy) -> Signal { return _internal_uploadStory(account: self.account, media: media, text: text, entities: entities, privacy: privacy) } diff --git a/submodules/TelegramUI/Components/PeerInfo/PeerInfoVisualMediaPaneNode/Sources/PeerInfoStoryPaneNode.swift b/submodules/TelegramUI/Components/PeerInfo/PeerInfoVisualMediaPaneNode/Sources/PeerInfoStoryPaneNode.swift index de94433426..216011c30d 100644 --- a/submodules/TelegramUI/Components/PeerInfo/PeerInfoVisualMediaPaneNode/Sources/PeerInfoStoryPaneNode.swift +++ b/submodules/TelegramUI/Components/PeerInfo/PeerInfoVisualMediaPaneNode/Sources/PeerInfoStoryPaneNode.swift @@ -81,7 +81,7 @@ private final class VisualMediaItem: SparseItemGrid.Item { } let localMonthTimestamp: Int32 let peer: PeerReference - let story: StoryListContext.Item + let story: EngineStoryItem override var id: AnyHashable { return AnyHashable(self.story.id) @@ -95,7 +95,7 @@ private final class VisualMediaItem: SparseItemGrid.Item { return VisualMediaHoleAnchor(index: self.index, storyId: self.story.id, localMonthTimestamp: self.localMonthTimestamp) } - init(index: Int, peer: PeerReference, story: StoryListContext.Item, localMonthTimestamp: Int32) { + init(index: Int, peer: PeerReference, story: EngineStoryItem, localMonthTimestamp: Int32) { self.indexValue = index self.peer = peer self.story = story @@ -738,7 +738,7 @@ private final class SparseItemGridBindingImpl: SparseItemGridBinding { } } -public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScrollViewDelegate, UIGestureRecognizerDelegate { +/*public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScrollViewDelegate, UIGestureRecognizerDelegate { public enum ContentType { case photoOrVideo case photo @@ -815,7 +815,7 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr private var animationTimer: SwiftSignalKit.Timer? public private(set) var calendarSource: SparseMessageCalendar? - private var listSource: StoryListContext + private var listSource: StorySubscriptionsContext public var openCurrentDate: (() -> Void)? public var paneDidScroll: (() -> Void)? @@ -848,7 +848,6 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr captureProtected: captureProtected ) - self.listSource = context.engine.messages.peerStories(id: self.peerId) //self.listSource = context.engine.messages.allStories() self.calendarSource = nil @@ -1934,3 +1933,4 @@ private class MediaListSelectionRecognizer: UIPanGestureRecognizer { } } } +*/ diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContent.swift index 7657f8fdbc..3118de5307 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContent.swift @@ -45,7 +45,7 @@ public final class StoryContentItem { public let centerInfoComponent: AnyComponent? public let rightInfoComponent: AnyComponent? public let peerId: EnginePeer.Id? - public let storyItem: StoryListContext.Item + public let storyItem: EngineStoryItem public let preload: Signal? public let delete: (() -> Void)? public let markAsSeen: (() -> Void)? @@ -59,7 +59,7 @@ public final class StoryContentItem { centerInfoComponent: AnyComponent?, rightInfoComponent: AnyComponent?, peerId: EnginePeer.Id?, - storyItem: StoryListContext.Item, + storyItem: EngineStoryItem, preload: Signal?, delete: (() -> Void)?, markAsSeen: (() -> Void)?, diff --git a/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryChatContent.swift b/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryChatContent.swift index 4bab173e6d..2ca8b0d7e5 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryChatContent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryChatContent.swift @@ -112,7 +112,7 @@ public final class StoryContentContextImpl: StoryContentContext { } if let item = itemsView.items[focusedIndex].value.get(Stories.StoredItem.self), case let .item(item) = item, let media = item.media { - let mappedItem = StoryListContext.Item( + let mappedItem = EngineStoryItem( id: item.id, timestamp: item.timestamp, media: EngineMedia(media), @@ -507,198 +507,3 @@ public final class StoryContentContextImpl: StoryContentContext { } } } - -public enum StoryChatContent { - public static func peerStories(context: AccountContext, peerId: EnginePeer.Id, focusItem: Int32?) -> Signal<[StoryContentItemSlice], NoError> { - let focusContext = context.engine.messages.peerStoryFocusContext(id: peerId, focusItemId: focusItem) - return combineLatest( - context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)), - focusContext.state - ) - |> mapToSignal { peer, state -> Signal<[StoryContentItemSlice], NoError> in - let _ = focusContext - - if let peer, let item = state.item, let media = item.media { - let mappedItem = StoryListContext.Item( - id: item.id, - timestamp: item.timestamp, - media: EngineMedia(media), - text: item.text, - entities: item.entities, - views: nil, - privacy: nil - ) - - let slice = StoryContentItemSlice( - id: AnyHashable(peerId), - focusedItemId: AnyHashable(item.id), - items: [ - StoryContentItem( - id: AnyHashable(item.id), - position: state.position, - component: AnyComponent(StoryItemContentComponent( - context: context, - peer: peer, - item: mappedItem - )), - centerInfoComponent: AnyComponent(StoryAuthorInfoComponent( - context: context, - peer: peer, - timestamp: item.timestamp - )), - rightInfoComponent: AnyComponent(StoryAvatarInfoComponent( - context: context, - peer: peer - )), - peerId: peer.id, - storyItem: mappedItem, - preload: nil, - delete: { [weak context] in - guard let context else { - return - } - let _ = context - }, - markAsSeen: { [weak context] in - guard let context else { - return - } - let _ = context.engine.messages.markStoryAsSeen(peerId: peerId, id: item.id).start() - }, - hasLike: false, - isMy: peerId == context.account.peerId - ) - ], - totalCount: state.count, - previousItemId: state.previousId, - nextItemId: state.nextId, - update: { requestedItemSet, itemId in - var focusItem: Int32? - if let id = itemId.base as? Int32 { - focusItem = id - } - - return StoryChatContent.peerStories(context: context, peerId: peerId, focusItem: focusItem) - |> mapToSignal { result in - if let first = result.first { - return .single(first) - } else { - return .never() - } - } - } - ) - return .single([slice]) - } else { - return .single([]) - } - } - } - - public static func subscriptionsStories(context: AccountContext, peerId: EnginePeer.Id?) -> Signal<[StoryContentItemSlice], NoError> { - return context.engine.messages.storySubscriptions() - |> mapToSignal { subscriptions -> Signal<[StoryContentItemSlice], NoError> in - var signals: [Signal<[StoryContentItemSlice], NoError>] = [] - for item in subscriptions.items { - signals.append(peerStories(context: context, peerId: item.peer.id, focusItem: nil)) - } - return combineLatest(queue: .mainQueue(), signals) - |> map { peerItems -> [StoryContentItemSlice] in - var result: [StoryContentItemSlice] = [] - - for item in peerItems { - result.append(contentsOf: item) - } - - return result - } - } - } - - public static func stories(context: AccountContext, storyList: StoryListContext, focusItem: Int32?) -> Signal<[StoryContentItemSlice], NoError> { - return storyList.state - |> map { state -> [StoryContentItemSlice] in - var itemSlices: [StoryContentItemSlice] = [] - - for itemSet in state.itemSets { - var items: [StoryContentItem] = [] - - guard let peer = itemSet.peer else { - continue - } - let peerId = itemSet.peerId - - for item in itemSet.items { - items.append(StoryContentItem( - id: AnyHashable(item.id), - position: items.count, - component: AnyComponent(StoryItemContentComponent( - context: context, - peer: peer, - item: item - )), - centerInfoComponent: AnyComponent(StoryAuthorInfoComponent( - context: context, - peer: itemSet.peer, - timestamp: item.timestamp - )), - rightInfoComponent: itemSet.peer.flatMap { author -> AnyComponent in - return AnyComponent(StoryAvatarInfoComponent( - context: context, - peer: author - )) - }, - peerId: itemSet.peerId, - storyItem: item, - preload: nil, - delete: { [weak storyList] in - storyList?.delete(id: item.id) - }, - markAsSeen: { [weak context] in - guard let context else { - return - } - let _ = context.engine.messages.markStoryAsSeen(peerId: peerId, id: item.id).start() - }, - hasLike: false, - isMy: itemSet.peerId == context.account.peerId - )) - } - - var sliceFocusedItemId: AnyHashable? - if let focusItem, items.contains(where: { ($0.id.base as? Int32) == focusItem }) { - sliceFocusedItemId = AnyHashable(focusItem) - } else { - if let id = itemSet.items.first(where: { $0.id > itemSet.maxReadId })?.id { - sliceFocusedItemId = AnyHashable(id) - } - } - - itemSlices.append(StoryContentItemSlice( - id: AnyHashable(itemSet.peerId), - focusedItemId: sliceFocusedItemId, - items: items, - totalCount: items.count, - previousItemId: nil, - nextItemId: nil, - update: { requestedItemSet, itemId in - var focusItem: Int32? - if let id = itemId.base as? Int32 { - focusItem = id - } - return StoryChatContent.stories(context: context, storyList: storyList, focusItem: focusItem) - |> mapToSignal { result -> Signal in - if let foundItemSet = result.first(where: { $0.id == requestedItemSet.id }) { - return .single(foundItemSet) - } else { - return .never() - } - } - } - )) - } - - return itemSlices - } - } -} diff --git a/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryItemContentComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryItemContentComponent.swift index aa432dda2f..78ea5c2d5b 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryItemContentComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryItemContentComponent.swift @@ -17,9 +17,9 @@ final class StoryItemContentComponent: Component { let context: AccountContext let peer: EnginePeer - let item: StoryListContext.Item + let item: EngineStoryItem - init(context: AccountContext, peer: EnginePeer, item: StoryListContext.Item) { + init(context: AccountContext, peer: EnginePeer, item: EngineStoryItem) { self.context = context self.peer = peer self.item = item diff --git a/submodules/TelegramUI/Components/Stories/StoryFooterPanelComponent/Sources/StoryFooterPanelComponent.swift b/submodules/TelegramUI/Components/Stories/StoryFooterPanelComponent/Sources/StoryFooterPanelComponent.swift index 948f98aafb..7c96bddc23 100644 --- a/submodules/TelegramUI/Components/Stories/StoryFooterPanelComponent/Sources/StoryFooterPanelComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryFooterPanelComponent/Sources/StoryFooterPanelComponent.swift @@ -11,13 +11,13 @@ import TelegramCore public final class StoryFooterPanelComponent: Component { public let context: AccountContext - public let storyItem: StoryListContext.Item? + public let storyItem: EngineStoryItem? public let deleteAction: () -> Void public let moreAction: (UIView, ContextGesture?) -> Void public init( context: AccountContext, - storyItem: StoryListContext.Item?, + storyItem: EngineStoryItem?, deleteAction: @escaping () -> Void, moreAction: @escaping (UIView, ContextGesture?) -> Void ) { diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoPaneContainerNode.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoPaneContainerNode.swift index 71884a94e7..da7240e65a 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoPaneContainerNode.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoPaneContainerNode.swift @@ -368,7 +368,8 @@ private final class PeerInfoPendingPane { let paneNode: PeerInfoPaneNode switch key { case .stories: - let visualPaneNode = PeerInfoStoryPaneNode(context: context, chatControllerInteraction: chatControllerInteraction, peerId: peerId, chatLocation: chatLocation, chatLocationContextHolder: chatLocationContextHolder, contentType: .photoOrVideo, captureProtected: captureProtected) + //let visualPaneNode = PeerInfoStoryPaneNode(context: context, chatControllerInteraction: chatControllerInteraction, peerId: peerId, chatLocation: chatLocation, chatLocationContextHolder: chatLocationContextHolder, contentType: .photoOrVideo, captureProtected: captureProtected) + let visualPaneNode = PeerInfoVisualMediaPaneNode(context: context, chatControllerInteraction: chatControllerInteraction, peerId: peerId, chatLocation: chatLocation, chatLocationContextHolder: chatLocationContextHolder, contentType: .photoOrVideo, captureProtected: captureProtected) paneNode = visualPaneNode visualPaneNode.openCurrentDate = { openMediaCalendar() diff --git a/submodules/TelegramUI/Sources/TelegramRootController.swift b/submodules/TelegramUI/Sources/TelegramRootController.swift index 0ee08d73e5..341d78ebce 100644 --- a/submodules/TelegramUI/Sources/TelegramRootController.swift +++ b/submodules/TelegramUI/Sources/TelegramRootController.swift @@ -367,7 +367,6 @@ public final class TelegramRootController: NavigationController, TelegramRootCon switch mediaResult { case let .image(image, dimensions, caption): if let imageData = compressImageToJPEG(image, quality: 0.6) { - //storyListContext.upload(media: .image(dimensions: dimensions, data: imageData), text: caption?.string ?? "", entities: [], privacy: privacy) let _ = self.context.engine.messages.uploadStory(media: .image(dimensions: dimensions, data: imageData), text: caption?.string ?? "", entities: [], privacy: privacy).start() Queue.mainQueue().after(0.2, { [weak chatListController] in chatListController?.animateStoryUploadRipple()