Fix media validation

This commit is contained in:
Ali 2020-09-25 22:01:11 +04:00
parent c197d9cd4c
commit 5a65539234
8 changed files with 55 additions and 2 deletions

View File

@ -9,6 +9,7 @@ private let typeVideo: Int32 = 4
private let typeAudio: Int32 = 5
private let typeHasLinkedStickers: Int32 = 6
private let typeHintFileIsLarge: Int32 = 7
private let typeHintIsValidated: Int32 = 8
public enum StickerPackReference: PostboxCoding, Hashable, Equatable {
case id(id: Int64, accessHash: Int64)
@ -131,6 +132,7 @@ public enum TelegramMediaFileAttribute: PostboxCoding {
case Audio(isVoice: Bool, duration: Int, title: String?, performer: String?, waveform: MemoryBuffer?)
case HasLinkedStickers
case hintFileIsLarge
case hintIsValidated
public init(decoder: PostboxDecoder) {
let type: Int32 = decoder.decodeInt32ForKey("t", orElse: 0)
@ -156,6 +158,8 @@ public enum TelegramMediaFileAttribute: PostboxCoding {
self = .HasLinkedStickers
case typeHintFileIsLarge:
self = .hintFileIsLarge
case typeHintIsValidated:
self = .hintIsValidated
default:
preconditionFailure()
}
@ -208,6 +212,8 @@ public enum TelegramMediaFileAttribute: PostboxCoding {
encoder.encodeInt32(typeHasLinkedStickers, forKey: "t")
case .hintFileIsLarge:
encoder.encodeInt32(typeHintFileIsLarge, forKey: "t")
case .hintIsValidated:
encoder.encodeInt32(typeHintIsValidated, forKey: "t")
}
}
}

View File

@ -0,0 +1,13 @@
import Foundation
import Postbox
public class ValidationMessageAttribute: MessageAttribute {
public init() {
}
required public init(decoder: PostboxDecoder) {
}
public func encode(_ encoder: PostboxEncoder) {
}
}

View File

@ -167,6 +167,7 @@ private var declaredEncodables: Void = {
declareEncodable(Country.self, f: { Country(decoder: $0) })
declareEncodable(Country.CountryCode.self, f: { Country.CountryCode(decoder: $0) })
declareEncodable(CountriesList.self, f: { CountriesList(decoder: $0) })
declareEncodable(ValidationMessageAttribute.self, f: { ValidationMessageAttribute(decoder: $0) })
return
}()

View File

@ -540,7 +540,18 @@ func revalidateMediaResourceReference(postbox: Postbox, network: Network, revali
if let updatedResource = findUpdatedMediaResource(media: item.file, previousMedia: media, resource: resource) {
return postbox.transaction { transaction -> RevalidatedMediaResource in
if let id = media.id {
updateMessageMedia(transaction: transaction, id: id, media: item.file)
var attributes = item.file.attributes
if !attributes.contains(where: { attribute in
if case .hintIsValidated = attribute {
return true
} else {
return false
}
}) {
attributes.append(.hintIsValidated)
}
let file = item.file.withUpdatedAttributes(attributes)
updateMessageMedia(transaction: transaction, id: id, media: file)
}
return RevalidatedMediaResource(updatedResource: updatedResource, updatedReference: nil)
}

View File

@ -523,6 +523,8 @@ private func decryptedAttributes46(_ attributes: [TelegramMediaFileAttribute], t
break
case .hintFileIsLarge:
break
case .hintIsValidated:
break
}
}
return result
@ -580,6 +582,10 @@ private func decryptedAttributes73(_ attributes: [TelegramMediaFileAttribute], t
break
case .hintFileIsLarge:
break
case .hintIsValidated:
break
case .hintIsValidated:
break
}
}
return result
@ -637,6 +643,8 @@ private func decryptedAttributes101(_ attributes: [TelegramMediaFileAttribute],
break
case .hintFileIsLarge:
break
case .hintIsValidated:
break
}
}
return result

View File

@ -489,6 +489,8 @@ func inputDocumentAttributesFromFileAttributes(_ fileAttributes: [TelegramMediaF
attributes.append(.documentAttributeHasStickers)
case .hintFileIsLarge:
break
case .hintIsValidated:
break
case let .Video(duration, size, videoFlags):
var flags: Int32 = 0
if videoFlags.contains(.instantRoundVideo) {

View File

@ -155,7 +155,9 @@ func telegramMediaFileThumbnailRepresentationsFromApiSizes(datacenterId: Int32,
func telegramMediaFileFromApiDocument(_ document: Api.Document) -> TelegramMediaFile? {
switch document {
case let .document(_, id, accessHash, fileReference, _, mimeType, size, thumbs, videoThumbs, dcId, attributes):
let parsedAttributes = telegramMediaFileAttributesFromApiAttributes(attributes)
var parsedAttributes = telegramMediaFileAttributesFromApiAttributes(attributes)
parsedAttributes.append(.hintIsValidated)
let (immediateThumbnail, previewRepresentations) = telegramMediaFileThumbnailRepresentationsFromApiSizes(datacenterId: dcId, documentId: id, accessHash: accessHash, fileReference: fileReference.makeData(), sizes: thumbs ?? [])
var videoThumbnails: [TelegramMediaFile.VideoThumbnail] = []

View File

@ -347,10 +347,20 @@ public final class ChatMessageItem: ListViewItem, CustomStringConvertible {
if telegramFile.isAnimatedSticker, (self.message.id.peerId.namespace == Namespaces.Peer.SecretChat || !telegramFile.previewRepresentations.isEmpty), let size = telegramFile.size, size > 0 && size <= 128 * 1024 {
if self.message.id.peerId.namespace == Namespaces.Peer.SecretChat {
if telegramFile.fileId.namespace == Namespaces.Media.CloudFile {
var isValidated = false
for attribute in telegramFile.attributes {
if case .hintIsValidated = attribute {
isValidated = true
break
}
}
inner: for attribute in telegramFile.attributes {
if case let .Sticker(_, packReference, _) = attribute {
if case .name = packReference {
viewClassName = ChatMessageAnimatedStickerItemNode.self
} else if isValidated {
viewClassName = ChatMessageAnimatedStickerItemNode.self
}
break inner
}