Use video thumbnails from API when possible

This commit is contained in:
Shadowfacts 2021-11-07 15:10:18 -05:00
parent 5a26739b78
commit 1ec85ca095
1 changed files with 20 additions and 9 deletions

View File

@ -184,6 +184,16 @@ class AttachmentView: UIImageView, GIFAnimatable {
} }
func loadVideo() { func loadVideo() {
if let previewURL = self.attachment.previewURL {
attachmentRequest = ImageCache.attachments.get(previewURL, completion: { [weak self] (data, _ )in
guard let self = self, let data = data else { return }
DispatchQueue.main.async {
self.attachmentRequest = nil
self.source = .imageData(previewURL, data)
self.displayImage()
}
})
} else {
let attachmentURL = self.attachment.url let attachmentURL = self.attachment.url
// todo: use a single dispatch queue // todo: use a single dispatch queue
DispatchQueue.global(qos: .userInitiated).async { DispatchQueue.global(qos: .userInitiated).async {
@ -194,6 +204,7 @@ class AttachmentView: UIImageView, GIFAnimatable {
self.source = .cgImage(attachmentURL, image) self.source = .cgImage(attachmentURL, image)
self.displayImage() self.displayImage()
} }
}
let playImageView = UIImageView(image: UIImage(systemName: "play.circle.fill")) let playImageView = UIImageView(image: UIImage(systemName: "play.circle.fill"))
playImageView.translatesAutoresizingMaskIntoConstraints = false playImageView.translatesAutoresizingMaskIntoConstraints = false