Don't generate videos for single frame animated stickers

This commit is contained in:
Ilya Laktyushin 2023-07-05 00:34:40 +02:00
parent 01067bd1f2
commit d5ea353b92
2 changed files with 20 additions and 2 deletions

View File

@ -145,8 +145,11 @@ public final class DrawingStickerEntityView: DrawingEntityView {
self.animationNode = animationNode self.animationNode = animationNode
animationNode.started = { [weak self, weak animationNode] in animationNode.started = { [weak self, weak animationNode] in
self?.imageNode.isHidden = true self?.imageNode.isHidden = true
if let animationNode = animationNode { if let animationNode = animationNode {
if animationNode.currentFrameCount == 1 {
self?.stickerEntity.isExplicitlyStatic = true
}
let _ = (animationNode.status let _ = (animationNode.status
|> take(1) |> take(1)
|> deliverOnMainQueue).start(next: { [weak self] status in |> deliverOnMainQueue).start(next: { [weak self] status in

View File

@ -62,6 +62,7 @@ public final class DrawingStickerEntity: DrawingEntity, Codable {
case scale case scale
case rotation case rotation
case mirrored case mirrored
case isExplicitlyStatic
} }
public let uuid: UUID public let uuid: UUID
@ -72,6 +73,8 @@ public final class DrawingStickerEntity: DrawingEntity, Codable {
public var scale: CGFloat public var scale: CGFloat
public var rotation: CGFloat public var rotation: CGFloat
public var mirrored: Bool public var mirrored: Bool
public var isExplicitlyStatic: Bool
public var color: DrawingColor = DrawingColor.clear public var color: DrawingColor = DrawingColor.clear
public var lineWidth: CGFloat = 0.0 public var lineWidth: CGFloat = 0.0
@ -88,7 +91,11 @@ public final class DrawingStickerEntity: DrawingEntity, Codable {
public var isAnimated: Bool { public var isAnimated: Bool {
switch self.content { switch self.content {
case let .file(file): case let .file(file):
return file.isAnimatedSticker || file.isVideoSticker || file.mimeType == "video/webm" if self.isExplicitlyStatic {
return false
} else {
return file.isAnimatedSticker || file.isVideoSticker || file.mimeType == "video/webm"
}
case .image: case .image:
return false return false
case .video: case .video:
@ -123,6 +130,8 @@ public final class DrawingStickerEntity: DrawingEntity, Codable {
self.scale = 1.0 self.scale = 1.0
self.rotation = 0.0 self.rotation = 0.0
self.mirrored = false self.mirrored = false
self.isExplicitlyStatic = false
} }
public init(from decoder: Decoder) throws { public init(from decoder: Decoder) throws {
@ -150,6 +159,7 @@ public final class DrawingStickerEntity: DrawingEntity, Codable {
self.scale = try container.decode(CGFloat.self, forKey: .scale) self.scale = try container.decode(CGFloat.self, forKey: .scale)
self.rotation = try container.decode(CGFloat.self, forKey: .rotation) self.rotation = try container.decode(CGFloat.self, forKey: .rotation)
self.mirrored = try container.decode(Bool.self, forKey: .mirrored) self.mirrored = try container.decode(Bool.self, forKey: .mirrored)
self.isExplicitlyStatic = try container.decodeIfPresent(Bool.self, forKey: .isExplicitlyStatic) ?? false
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -185,6 +195,7 @@ public final class DrawingStickerEntity: DrawingEntity, Codable {
try container.encode(self.scale, forKey: .scale) try container.encode(self.scale, forKey: .scale)
try container.encode(self.rotation, forKey: .rotation) try container.encode(self.rotation, forKey: .rotation)
try container.encode(self.mirrored, forKey: .mirrored) try container.encode(self.mirrored, forKey: .mirrored)
try container.encode(self.isExplicitlyStatic, forKey: .isExplicitlyStatic)
} }
public func duplicate() -> DrawingEntity { public func duplicate() -> DrawingEntity {
@ -194,6 +205,7 @@ public final class DrawingStickerEntity: DrawingEntity, Codable {
newEntity.scale = self.scale newEntity.scale = self.scale
newEntity.rotation = self.rotation newEntity.rotation = self.rotation
newEntity.mirrored = self.mirrored newEntity.mirrored = self.mirrored
newEntity.isExplicitlyStatic = self.isExplicitlyStatic
return newEntity return newEntity
} }
@ -222,6 +234,9 @@ public final class DrawingStickerEntity: DrawingEntity, Codable {
if self.mirrored != other.mirrored { if self.mirrored != other.mirrored {
return false return false
} }
if self.isExplicitlyStatic != other.isExplicitlyStatic {
return false
}
return true return true
} }
} }