mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Serialization update
This commit is contained in:
@@ -28,9 +28,9 @@ import GenerateStickerPlaceholderImage
|
||||
|
||||
public struct EmojiComponentReactionItem: Equatable {
|
||||
public var reaction: MessageReaction.Reaction
|
||||
public var file: TelegramMediaFile
|
||||
public var file: TelegramMediaFile.Accessor
|
||||
|
||||
public init(reaction: MessageReaction.Reaction, file: TelegramMediaFile) {
|
||||
public init(reaction: MessageReaction.Reaction, file: TelegramMediaFile.Accessor) {
|
||||
self.reaction = reaction
|
||||
self.file = file
|
||||
}
|
||||
@@ -60,16 +60,35 @@ public final class EntityKeyboardAnimationData: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
public enum Resource: Equatable {
|
||||
case resource(MediaResourceReference)
|
||||
case file(PartialMediaReference?, TelegramMediaFile.Accessor)
|
||||
|
||||
func _parse() -> MediaResourceReference {
|
||||
switch self {
|
||||
case let .resource(resource):
|
||||
return resource
|
||||
case let .file(partialReference, file):
|
||||
let file = file._parse()
|
||||
if let partialReference {
|
||||
return partialReference.mediaReference(file).resourceReference(file.resource)
|
||||
} else {
|
||||
return .standalone(resource: file.resource)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public let id: Id
|
||||
public let type: ItemType
|
||||
public let resource: MediaResourceReference
|
||||
public let resource: Resource
|
||||
public let dimensions: CGSize
|
||||
public let immediateThumbnailData: Data?
|
||||
public let isReaction: Bool
|
||||
public let isTemplate: Bool
|
||||
public let particleColor: UIColor?
|
||||
|
||||
public init(id: Id, type: ItemType, resource: MediaResourceReference, dimensions: CGSize, immediateThumbnailData: Data?, isReaction: Bool, isTemplate: Bool, particleColor: UIColor? = nil) {
|
||||
public init(id: Id, type: ItemType, resource: Resource, dimensions: CGSize, immediateThumbnailData: Data?, isReaction: Bool, isTemplate: Bool, particleColor: UIColor? = nil) {
|
||||
self.id = id
|
||||
self.type = type
|
||||
self.resource = resource
|
||||
@@ -80,7 +99,7 @@ public final class EntityKeyboardAnimationData: Equatable {
|
||||
self.particleColor = particleColor
|
||||
}
|
||||
|
||||
public convenience init(file: TelegramMediaFile, isReaction: Bool = false, partialReference: PartialMediaReference? = nil) {
|
||||
public convenience init(file: TelegramMediaFile.Accessor, isReaction: Bool = false, partialReference: PartialMediaReference? = nil) {
|
||||
let type: ItemType
|
||||
if file.isVideoSticker || file.isVideoEmoji {
|
||||
type = .video
|
||||
@@ -91,13 +110,8 @@ public final class EntityKeyboardAnimationData: Equatable {
|
||||
}
|
||||
let isTemplate = file.isCustomTemplateEmoji
|
||||
|
||||
let resourceReference: MediaResourceReference
|
||||
if let partialReference {
|
||||
resourceReference = partialReference.mediaReference(file).resourceReference(file.resource)
|
||||
} else {
|
||||
resourceReference = .standalone(resource: file.resource)
|
||||
}
|
||||
self.init(id: .file(file.fileId), type: type, resource: resourceReference, dimensions: file.dimensions?.cgSize ?? CGSize(width: 512.0, height: 512.0), immediateThumbnailData: file.immediateThumbnailData, isReaction: isReaction, isTemplate: isTemplate)
|
||||
let resource: Resource = .file(partialReference, file)
|
||||
self.init(id: .file(file.fileId), type: type, resource: resource, dimensions: file.dimensions?.cgSize ?? CGSize(width: 512.0, height: 512.0), immediateThumbnailData: file.immediateThumbnailData, isReaction: isReaction, isTemplate: isTemplate)
|
||||
}
|
||||
|
||||
public convenience init?(gift: StarGift.UniqueGift) {
|
||||
@@ -113,7 +127,7 @@ public final class EntityKeyboardAnimationData: Equatable {
|
||||
}
|
||||
if let file, let color {
|
||||
let resourceReference: MediaResourceReference = .standalone(resource: file.resource)
|
||||
self.init(id: .gift(gift.slug), type: .lottie, resource: resourceReference, dimensions: file.dimensions?.cgSize ?? CGSize(width: 512.0, height: 512.0), immediateThumbnailData: file.immediateThumbnailData, isReaction: false, isTemplate: false, particleColor: color)
|
||||
self.init(id: .gift(gift.slug), type: .lottie, resource: .resource(resourceReference), dimensions: file.dimensions?.cgSize ?? CGSize(width: 512.0, height: 512.0), immediateThumbnailData: file.immediateThumbnailData, isReaction: false, isTemplate: false, particleColor: color)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
@@ -124,7 +138,7 @@ public final class EntityKeyboardAnimationData: Equatable {
|
||||
return true
|
||||
}
|
||||
|
||||
if lhs.resource.resource.id != rhs.resource.resource.id {
|
||||
if lhs.resource != rhs.resource {
|
||||
return false
|
||||
}
|
||||
if lhs.dimensions != rhs.dimensions {
|
||||
@@ -401,7 +415,7 @@ public final class EmojiPagerContentComponent: Component {
|
||||
|
||||
public let animationData: EntityKeyboardAnimationData?
|
||||
public let content: ItemContent
|
||||
public let itemFile: TelegramMediaFile?
|
||||
public let itemFile: TelegramMediaFile.Accessor?
|
||||
public let itemGift: StarGift.UniqueGift?
|
||||
public let subgroupId: Int32?
|
||||
public let icon: Icon
|
||||
@@ -410,7 +424,7 @@ public final class EmojiPagerContentComponent: Component {
|
||||
public init(
|
||||
animationData: EntityKeyboardAnimationData?,
|
||||
content: ItemContent,
|
||||
itemFile: TelegramMediaFile?,
|
||||
itemFile: TelegramMediaFile.Accessor?,
|
||||
itemGift: StarGift.UniqueGift? = nil,
|
||||
subgroupId: Int32?,
|
||||
icon: Icon,
|
||||
@@ -429,7 +443,7 @@ public final class EmojiPagerContentComponent: Component {
|
||||
if lhs === rhs {
|
||||
return true
|
||||
}
|
||||
if lhs.animationData?.resource.resource.id != rhs.animationData?.resource.resource.id {
|
||||
if lhs.animationData?.resource != rhs.animationData?.resource {
|
||||
return false
|
||||
}
|
||||
if lhs.content != rhs.content {
|
||||
@@ -1723,7 +1737,7 @@ public final class EmojiPagerContentComponent: Component {
|
||||
})
|
||||
}
|
||||
|
||||
component.animationRenderer.setFrameIndex(itemId: animationData.resource.resource.id.stringRepresentation, size: itemLayer.pixelSize, frameIndex: sourceItem.frameIndex, placeholder: sourceItem.placeholder)
|
||||
component.animationRenderer.setFrameIndex(itemId: animationData.resource._parse().resource.id.stringRepresentation, size: itemLayer.pixelSize, frameIndex: sourceItem.frameIndex, placeholder: sourceItem.placeholder)
|
||||
} else {
|
||||
let distance = itemLayer.position.y - itemLayout.frame(groupIndex: 0, itemIndex: 0).midY
|
||||
let maxDistance = self.bounds.height
|
||||
@@ -4126,7 +4140,7 @@ public final class EmojiPagerContentComponent: Component {
|
||||
if itemLayer.displayPlaceholder {
|
||||
return nil
|
||||
}
|
||||
return (item.1.groupId, itemLayer, file)
|
||||
return (item.1.groupId, itemLayer, file._parse())
|
||||
})
|
||||
|
||||
let keyboardChildEnvironment = environment[EntityKeyboardChildEnvironment.self].value
|
||||
|
||||
Reference in New Issue
Block a user