Various improvements

This commit is contained in:
Ilya Laktyushin 2025-01-28 23:37:17 +04:00
parent d4bc3277a3
commit 340075d4f1
4 changed files with 24 additions and 5 deletions

View File

@ -77,7 +77,10 @@ private func mediaForMessage(message: Message) -> [(Media, TelegramMediaImage?)]
case let .Loaded(content):
if let embedUrl = content.embedUrl, !embedUrl.isEmpty {
return [(webpage, nil)]
} else if let file = content.file {
} else if var file = content.file {
if content.imageIsVideoCover, let image = content.image {
file = file.withUpdatedVideoCover(image)
}
if let result = galleryMediaForMedia(media: file) {
return [(result, content.image)]
}

View File

@ -922,6 +922,10 @@ public final class TelegramMediaFile: Media, Equatable, Codable {
public func withUpdatedAttributes(_ attributes: [TelegramMediaFileAttribute]) -> TelegramMediaFile {
return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, videoThumbnails: self.videoThumbnails, videoCover: self.videoCover, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: attributes, alternativeRepresentations: self.alternativeRepresentations)
}
public func withUpdatedVideoCover(_ videoCover: TelegramMediaImage?) -> TelegramMediaFile {
return TelegramMediaFile(fileId: self.fileId, partialReference: self.partialReference, resource: self.resource, previewRepresentations: self.previewRepresentations, videoThumbnails: self.videoThumbnails, videoCover: videoCover, immediateThumbnailData: self.immediateThumbnailData, mimeType: self.mimeType, size: self.size, attributes: self.attributes, alternativeRepresentations: self.alternativeRepresentations)
}
}
public func ==(lhs: TelegramMediaFile, rhs: TelegramMediaFile) -> Bool {

View File

@ -360,7 +360,9 @@ public final class ChatMessageAttachedContentNode: ASDisplayNode {
contentMediaAutomaticDownload = .prefetch
}
if file.isAnimated {
if let _ = file.videoCover {
contentMediaAutomaticPlayback = false
} else if file.isAnimated {
contentMediaAutomaticPlayback = context.sharedContext.energyUsageSettings.autoplayGif
} else if file.isVideo && context.sharedContext.energyUsageSettings.autoplayVideo {
var willDownloadOrLocal = false

View File

@ -344,7 +344,11 @@ public final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContent
}
}
default:
if let file = mainMedia as? TelegramMediaFile, webpage.type != "telegram_theme" {
if var file = mainMedia as? TelegramMediaFile, webpage.type != "telegram_theme" {
if webpage.imageIsVideoCover, let image = webpage.image {
file = file.withUpdatedVideoCover(image)
}
if let embedUrl = webpage.embedUrl, !embedUrl.isEmpty {
if automaticPlayback {
mediaAndFlags = ([file], [.preferMediaBeforeText])
@ -689,7 +693,10 @@ public final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContent
if let image = content.image {
mediaList.append(image)
}
if let file = content.file {
if var file = content.file {
if content.imageIsVideoCover, let image = content.image {
file = file.withUpdatedVideoCover(image)
}
mediaList.append(file)
}
updatedMedia = mediaList
@ -698,7 +705,10 @@ public final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContent
if let image = content.image {
mediaList.append(image)
}
if let file = content.file {
if var file = content.file {
if content.imageIsVideoCover, let image = content.image {
file = file.withUpdatedVideoCover(image)
}
mediaList.append(file)
}
updatedMedia = mediaList