This commit is contained in:
overtake 2017-04-13 21:01:37 +03:00
commit 18beabff2e
8 changed files with 37 additions and 14 deletions

View File

@ -577,7 +577,7 @@ public struct Api {
return parser(reader)
}
else {
print("Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
Logger.shared.log("TL", "Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
return nil
}
}

View File

@ -79,7 +79,7 @@ public struct MacosLegacy {
return parser(reader)
}
else {
print("Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
Logger.log("TL", "Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
return nil
}
}

View File

@ -408,7 +408,7 @@ private func decryptedAttributes46(_ attributes: [TelegramMediaFileAttribute]) -
result.append(.documentAttributeSticker(alt: displayText, stickerset: stickerSet))
case let .ImageSize(size):
result.append(.documentAttributeImageSize(w: Int32(size.width), h: Int32(size.height)))
case let .Video(duration, size):
case let .Video(duration, size, videoFlags):
result.append(.documentAttributeVideo(duration: Int32(duration), w: Int32(size.width), h: Int32(size.height)))
case let .Audio(isVoice, duration, title, performer, waveform):
var flags: Int32 = 0

View File

@ -114,8 +114,12 @@ func inputDocumentAttributesFromFileAttributes(_ fileAttributes: [TelegramMediaF
attributes.append(.documentAttributeSticker(flags: flags, alt: displayText, stickerset: stickerSet, maskCoords: nil))
case .HasLinkedStickers:
attributes.append(.documentAttributeHasStickers)
case let .Video(duration, size):
attributes.append(.documentAttributeVideo(flags: 0, duration: Int32(duration), w: Int32(size.width), h: Int32(size.height)))
case let .Video(duration, size, videoFlags):
var flags: Int32 = 0
if videoFlags.contains(.instantRoundVideo) {
flags |= (1 << 0)
}
attributes.append(.documentAttributeVideo(flags: flags, duration: Int32(duration), w: Int32(size.width), h: Int32(size.height)))
case let .Audio(isVoice, duration, title, performer, waveform):
var flags: Int32 = 0
if isVoice {

View File

@ -430,7 +430,7 @@ extension TelegramMediaFileAttribute {
}
self = .Sticker(displayText: alt, packReference: packReference)
case let .documentAttributeVideo(duration, w, h):
self = .Video(duration: Int(duration), size: CGSize(width: CGFloat(w), height: CGFloat(h)))
self = .Video(duration: Int(duration), size: CGSize(width: CGFloat(w), height: CGFloat(h)), flags: [])
default:
return nil
}
@ -497,7 +497,7 @@ private func parseMessage(peerId: PeerId, authorId: PeerId, tagLocalIndex: Int32
text = caption
}
if let file = file {
var parsedAttributes: [TelegramMediaFileAttribute] = [.Video(duration: Int(duration), size: CGSize(width: CGFloat(w), height: CGFloat(h))), .FileName(fileName: "video.mov")]
var parsedAttributes: [TelegramMediaFileAttribute] = [.Video(duration: Int(duration), size: CGSize(width: CGFloat(w), height: CGFloat(h)), flags: []), .FileName(fileName: "video.mov")]
var previewRepresentations: [TelegramMediaImageRepresentation] = []
if thumb.size != 0 {
let resource = LocalFileMediaResource(fileId: arc4random64())

View File

@ -82,7 +82,7 @@ public struct SecretApi46 {
return parser(reader)
}
else {
print("Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
Logger.shared.log("TL", "Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
return nil
}
}

View File

@ -48,7 +48,7 @@ public struct SecretApi8 {
return parser(reader)
}
else {
print("Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
Logger.shared.log("TL", "Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
return nil
}
}

View File

@ -42,12 +42,26 @@ public enum StickerPackReference: Coding {
}
}
public struct TelegramMediaVideoFlags: OptionSet {
public var rawValue: Int32
public init() {
self.rawValue = 0
}
public init(rawValue: Int32) {
self.rawValue = rawValue
}
public static let instantRoundVideo = TelegramMediaVideoFlags(rawValue: 1 << 0)
}
public enum TelegramMediaFileAttribute: Coding {
case FileName(fileName: String)
case Sticker(displayText: String, packReference: StickerPackReference?)
case ImageSize(size: CGSize)
case Animated
case Video(duration: Int, size: CGSize)
case Video(duration: Int, size: CGSize, flags: TelegramMediaVideoFlags)
case Audio(isVoice: Bool, duration: Int, title: String?, performer: String?, waveform: MemoryBuffer?)
case HasLinkedStickers
@ -63,7 +77,7 @@ public enum TelegramMediaFileAttribute: Coding {
case typeAnimated:
self = .Animated
case typeVideo:
self = .Video(duration: Int(decoder.decodeInt32ForKey("du")), size: CGSize(width: CGFloat(decoder.decodeInt32ForKey("w")), height: CGFloat(decoder.decodeInt32ForKey("h"))))
self = .Video(duration: Int(decoder.decodeInt32ForKey("du")), size: CGSize(width: CGFloat(decoder.decodeInt32ForKey("w")), height: CGFloat(decoder.decodeInt32ForKey("h"))), flags: TelegramMediaVideoFlags(rawValue: decoder.decodeInt32ForKey("f")))
case typeAudio:
let waveformBuffer = decoder.decodeBytesForKeyNoCopy("wf")
var waveform: MemoryBuffer?
@ -97,11 +111,12 @@ public enum TelegramMediaFileAttribute: Coding {
encoder.encodeInt32(Int32(size.height), forKey: "h")
case .Animated:
encoder.encodeInt32(typeAnimated, forKey: "t")
case let .Video(duration, size):
case let .Video(duration, size, flags):
encoder.encodeInt32(typeVideo, forKey: "t")
encoder.encodeInt32(Int32(duration), forKey: "du")
encoder.encodeInt32(Int32(size.width), forKey: "w")
encoder.encodeInt32(Int32(size.height), forKey: "h")
encoder.encodeInt32(flags.rawValue, forKey: "f")
case let .Audio(isVoice, duration, title, performer, waveform):
encoder.encodeInt32(typeAudio, forKey: "t")
encoder.encodeInt32(isVoice ? 1 : 0, forKey: "iv")
@ -233,7 +248,7 @@ public final class TelegramMediaFile: Media, Equatable {
public var dimensions: CGSize? {
for attribute in self.attributes {
switch attribute {
case let .Video(_, size):
case let .Video(_, size, _):
return size
case let .ImageSize(size):
return size
@ -313,7 +328,11 @@ public func telegramMediaFileAttributesFromApiAttributes(_ attributes: [Api.Docu
case .documentAttributeAnimated:
result.append(.Animated)
case let .documentAttributeVideo(flags, duration, w, h):
result.append(.Video(duration: Int(duration), size: CGSize(width: CGFloat(w), height: CGFloat(h))))
var videoFlags = TelegramMediaVideoFlags()
if (flags & (1 << 0)) != 0 {
videoFlags.insert(.instantRoundVideo)
}
result.append(.Video(duration: Int(duration), size: CGSize(width: CGFloat(w), height: CGFloat(h)), flags: videoFlags))
case let .documentAttributeAudio(flags, duration, title, performer, waveform):
let isVoice = (flags & (1 << 10)) != 0
var waveformBuffer: MemoryBuffer?