mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Update API
This commit is contained in:
@@ -85,8 +85,43 @@ public final class TelegramMediaImage: Media, Equatable, Codable {
|
||||
case data
|
||||
}
|
||||
|
||||
public final class VideoRepresentation: Equatable, PostboxCoding {
|
||||
public let dimensions: PixelDimensions
|
||||
public let resource: TelegramMediaResource
|
||||
|
||||
public init(dimensions: PixelDimensions, resource: TelegramMediaResource) {
|
||||
self.dimensions = dimensions
|
||||
self.resource = resource
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.dimensions = PixelDimensions(width: decoder.decodeInt32ForKey("w", orElse: 0), height: decoder.decodeInt32ForKey("h", orElse: 0))
|
||||
self.resource = decoder.decodeObjectForKey("r") as! TelegramMediaResource
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.dimensions.width, forKey: "w")
|
||||
encoder.encodeInt32(self.dimensions.height, forKey: "h")
|
||||
encoder.encodeObject(self.resource, forKey: "r")
|
||||
}
|
||||
|
||||
public static func ==(lhs: VideoRepresentation, rhs: VideoRepresentation) -> Bool {
|
||||
if lhs === rhs {
|
||||
return true
|
||||
}
|
||||
if lhs.dimensions != rhs.dimensions {
|
||||
return false
|
||||
}
|
||||
if !lhs.resource.isEqual(to: rhs.resource) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public let imageId: MediaId
|
||||
public let representations: [TelegramMediaImageRepresentation]
|
||||
public let videoRepresentations: [TelegramMediaImage.VideoRepresentation]
|
||||
public let immediateThumbnailData: Data?
|
||||
public let reference: TelegramMediaImageReference?
|
||||
public let partialReference: PartialMediaReference?
|
||||
@@ -97,9 +132,10 @@ public final class TelegramMediaImage: Media, Equatable, Codable {
|
||||
return self.imageId
|
||||
}
|
||||
|
||||
public init(imageId: MediaId, representations: [TelegramMediaImageRepresentation], immediateThumbnailData: Data?, reference: TelegramMediaImageReference?, partialReference: PartialMediaReference?, flags: TelegramMediaImageFlags) {
|
||||
public init(imageId: MediaId, representations: [TelegramMediaImageRepresentation], videoRepresentations: [TelegramMediaImage.VideoRepresentation] = [], immediateThumbnailData: Data?, reference: TelegramMediaImageReference?, partialReference: PartialMediaReference?, flags: TelegramMediaImageFlags) {
|
||||
self.imageId = imageId
|
||||
self.representations = representations
|
||||
self.videoRepresentations = videoRepresentations
|
||||
self.immediateThumbnailData = immediateThumbnailData
|
||||
self.reference = reference
|
||||
self.partialReference = partialReference
|
||||
@@ -109,6 +145,7 @@ public final class TelegramMediaImage: Media, Equatable, Codable {
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.imageId = MediaId(decoder.decodeBytesForKeyNoCopy("i")!)
|
||||
self.representations = decoder.decodeObjectArrayForKey("r")
|
||||
self.videoRepresentations = decoder.decodeObjectArrayForKey("vr")
|
||||
self.immediateThumbnailData = decoder.decodeDataForKey("itd")
|
||||
self.reference = decoder.decodeObjectForKey("rf", decoder: { TelegramMediaImageReference(decoder: $0) }) as? TelegramMediaImageReference
|
||||
self.partialReference = decoder.decodeAnyObjectForKey("prf", decoder: { PartialMediaReference(decoder: $0) }) as? PartialMediaReference
|
||||
@@ -120,6 +157,7 @@ public final class TelegramMediaImage: Media, Equatable, Codable {
|
||||
self.imageId.encodeToBuffer(buffer)
|
||||
encoder.encodeBytes(buffer, forKey: "i")
|
||||
encoder.encodeObjectArray(self.representations, forKey: "r")
|
||||
encoder.encodeObjectArray(self.videoRepresentations, forKey: "vr")
|
||||
if let immediateThumbnailData = self.immediateThumbnailData {
|
||||
encoder.encodeData(immediateThumbnailData, forKey: "itd")
|
||||
} else {
|
||||
@@ -147,6 +185,7 @@ public final class TelegramMediaImage: Media, Equatable, Codable {
|
||||
}
|
||||
self.imageId = object.imageId
|
||||
self.representations = object.representations
|
||||
self.videoRepresentations = object.videoRepresentations
|
||||
self.immediateThumbnailData = object.immediateThumbnailData
|
||||
self.reference = object.reference
|
||||
self.partialReference = object.partialReference
|
||||
@@ -196,6 +235,9 @@ public final class TelegramMediaImage: Media, Equatable, Codable {
|
||||
if other.representations != self.representations {
|
||||
return false
|
||||
}
|
||||
if other.videoRepresentations != self.videoRepresentations {
|
||||
return false
|
||||
}
|
||||
if other.immediateThumbnailData != self.immediateThumbnailData {
|
||||
return false
|
||||
}
|
||||
@@ -218,6 +260,9 @@ public final class TelegramMediaImage: Media, Equatable, Codable {
|
||||
if other.representations.count != self.representations.count {
|
||||
return false
|
||||
}
|
||||
if other.videoRepresentations.count != self.videoRepresentations.count {
|
||||
return false
|
||||
}
|
||||
for i in 0 ..< self.representations.count {
|
||||
if !self.representations[i].isSemanticallyEqual(to: other.representations[i]) {
|
||||
return false
|
||||
@@ -240,7 +285,7 @@ public final class TelegramMediaImage: Media, Equatable, Codable {
|
||||
}
|
||||
|
||||
public func withUpdatedPartialReference(_ partialReference: PartialMediaReference?) -> TelegramMediaImage {
|
||||
return TelegramMediaImage(imageId: self.imageId, representations: self.representations, immediateThumbnailData: self.immediateThumbnailData, reference: self.reference, partialReference: partialReference, flags: self.flags)
|
||||
return TelegramMediaImage(imageId: self.imageId, representations: self.representations, videoRepresentations: self.videoRepresentations, immediateThumbnailData: self.immediateThumbnailData, reference: self.reference, partialReference: partialReference, flags: self.flags)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user