diff --git a/submodules/SyncCore/Sources/TelegramMediaFile.swift b/submodules/SyncCore/Sources/TelegramMediaFile.swift index 293bef9d3f..1948aa9477 100644 --- a/submodules/SyncCore/Sources/TelegramMediaFile.swift +++ b/submodules/SyncCore/Sources/TelegramMediaFile.swift @@ -8,6 +8,7 @@ private let typeAnimated: Int32 = 3 private let typeVideo: Int32 = 4 private let typeAudio: Int32 = 5 private let typeHasLinkedStickers: Int32 = 6 +private let typeHintFileIsLarge: Int32 = 7 public enum StickerPackReference: PostboxCoding, Hashable, Equatable { case id(id: Int64, accessHash: Int64) @@ -129,6 +130,7 @@ public enum TelegramMediaFileAttribute: PostboxCoding { case Video(duration: Int, size: PixelDimensions, flags: TelegramMediaVideoFlags) case Audio(isVoice: Bool, duration: Int, title: String?, performer: String?, waveform: MemoryBuffer?) case HasLinkedStickers + case hintFileIsLarge public init(decoder: PostboxDecoder) { let type: Int32 = decoder.decodeInt32ForKey("t", orElse: 0) @@ -152,6 +154,8 @@ public enum TelegramMediaFileAttribute: PostboxCoding { self = .Audio(isVoice: decoder.decodeInt32ForKey("iv", orElse: 0) != 0, duration: Int(decoder.decodeInt32ForKey("du", orElse: 0)), title: decoder.decodeOptionalStringForKey("ti"), performer: decoder.decodeOptionalStringForKey("pe"), waveform: waveform) case typeHasLinkedStickers: self = .HasLinkedStickers + case typeHintFileIsLarge: + self = .hintFileIsLarge default: preconditionFailure() } @@ -202,6 +206,8 @@ public enum TelegramMediaFileAttribute: PostboxCoding { } case .HasLinkedStickers: encoder.encodeInt32(typeHasLinkedStickers, forKey: "t") + case .hintFileIsLarge: + encoder.encodeInt32(typeHintFileIsLarge, forKey: "t") } } } diff --git a/submodules/TelegramCore/Sources/ManagedSecretChatOutgoingOperations.swift b/submodules/TelegramCore/Sources/ManagedSecretChatOutgoingOperations.swift index d38214e8b0..6ab9af549c 100644 --- a/submodules/TelegramCore/Sources/ManagedSecretChatOutgoingOperations.swift +++ b/submodules/TelegramCore/Sources/ManagedSecretChatOutgoingOperations.swift @@ -521,6 +521,8 @@ private func decryptedAttributes46(_ attributes: [TelegramMediaFileAttribute], t result.append(.documentAttributeAudio(flags: flags, duration: Int32(duration), title: title, performer: performer, waveform: waveformBuffer)) case .HasLinkedStickers: break + case .hintFileIsLarge: + break } } return result @@ -576,6 +578,8 @@ private func decryptedAttributes73(_ attributes: [TelegramMediaFileAttribute], t result.append(.documentAttributeAudio(flags: flags, duration: Int32(duration), title: title, performer: performer, waveform: waveformBuffer)) case .HasLinkedStickers: break + case .hintFileIsLarge: + break } } return result @@ -631,6 +635,8 @@ private func decryptedAttributes101(_ attributes: [TelegramMediaFileAttribute], result.append(.documentAttributeAudio(flags: flags, duration: Int32(duration), title: title, performer: performer, waveform: waveformBuffer)) case .HasLinkedStickers: break + case .hintFileIsLarge: + break } } return result diff --git a/submodules/TelegramCore/Sources/PendingMessageUploadedContent.swift b/submodules/TelegramCore/Sources/PendingMessageUploadedContent.swift index 3c885ec960..16b490b314 100644 --- a/submodules/TelegramCore/Sources/PendingMessageUploadedContent.swift +++ b/submodules/TelegramCore/Sources/PendingMessageUploadedContent.swift @@ -487,6 +487,8 @@ func inputDocumentAttributesFromFileAttributes(_ fileAttributes: [TelegramMediaF attributes.append(.documentAttributeSticker(flags: flags, alt: displayText, stickerset: stickerSet, maskCoords: inputMaskCoords)) case .HasLinkedStickers: attributes.append(.documentAttributeHasStickers) + case .hintFileIsLarge: + break case let .Video(duration, size, videoFlags): var flags: Int32 = 0 if videoFlags.contains(.instantRoundVideo) { @@ -588,9 +590,18 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili } else if let resource = file.resource as? LocalFileReferenceMediaResource, let size = resource.size { hintSize = Int(size) } - if (file.resource.headerSize != 0 || file.mimeType.hasPrefix("video/mp4")) && !file.isAnimated { - hintFileIsLarge = true + + loop: for attr in file.attributes { + switch attr { + case .hintFileIsLarge: + hintFileIsLarge = true + break loop + default: + break loop + } } + + let fileReference: AnyMediaReference if let partialReference = file.partialReference { fileReference = partialReference.mediaReference(file) diff --git a/submodules/TelegramCore/Sources/RequestChatContextResults.swift b/submodules/TelegramCore/Sources/RequestChatContextResults.swift index d891599d2e..2c820c7d2c 100644 --- a/submodules/TelegramCore/Sources/RequestChatContextResults.swift +++ b/submodules/TelegramCore/Sources/RequestChatContextResults.swift @@ -136,7 +136,7 @@ public func requestChatContextResults(account: Account, botId: PeerId, peerId: P } return account.postbox.transaction { transaction -> RequestChatContextResultsResult? in - if result.cacheTimeout > 10 { + if result.cacheTimeout > 10, offset.isEmpty && location == nil { if let resultData = try? JSONEncoder().encode(result) { let requestData = RequestData(version: requestVersion, botId: botId, peerId: peerId, query: query) if let keyData = try? JSONEncoder().encode(requestData) { diff --git a/submodules/TelegramCore/Sources/SearchStickers.swift b/submodules/TelegramCore/Sources/SearchStickers.swift index 9a5cfecf8c..5a1a7b380d 100644 --- a/submodules/TelegramCore/Sources/SearchStickers.swift +++ b/submodules/TelegramCore/Sources/SearchStickers.swift @@ -299,15 +299,19 @@ public func searchStickerSets(postbox: Postbox, query: String) -> Signal switchToLatest } -public func searchGifs(account: Account, query: String) -> Signal { - return resolvePeerByName(account: account, name: "gif") - |> filter { $0 != nil } +public func searchGifs(account: Account, query: String, nextOffset: String = "") -> Signal { + return account.postbox.transaction { transaction -> String in + let configuration = currentSearchBotsConfiguration(transaction: transaction) + return configuration.gifBotUsername ?? "gif" + } |> mapToSignal { + return resolvePeerByName(account: account, name: $0) + } |> filter { $0 != nil } |> map { $0! } |> mapToSignal { peerId -> Signal in return account.postbox.loadedPeerWithId(peerId) } |> mapToSignal { peer -> Signal in - return requestChatContextResults(account: account, botId: peer.id, peerId: account.peerId, query: query, offset: "") + return requestChatContextResults(account: account, botId: peer.id, peerId: account.peerId, query: query, offset: nextOffset) |> map { results -> ChatContextResultCollection? in return results?.results }