Merge commit 'b09f4647600fc7b3a89090332f1e1e8d7741bf66'

This commit is contained in:
Ali 2020-06-02 16:46:33 +04:00
commit d01053229d
5 changed files with 34 additions and 7 deletions

View File

@ -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")
}
}
}

View File

@ -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

View File

@ -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 {
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)

View File

@ -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) {

View File

@ -299,15 +299,19 @@ public func searchStickerSets(postbox: Postbox, query: String) -> Signal<FoundSt
} |> switchToLatest
}
public func searchGifs(account: Account, query: String) -> Signal<ChatContextResultCollection?, NoError> {
return resolvePeerByName(account: account, name: "gif")
|> filter { $0 != nil }
public func searchGifs(account: Account, query: String, nextOffset: String = "") -> Signal<ChatContextResultCollection?, NoError> {
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<Peer, NoError> in
return account.postbox.loadedPeerWithId(peerId)
}
|> mapToSignal { peer -> Signal<ChatContextResultCollection?, NoError> 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
}