Vernissage/CoreData/AttachmentData+Attachment.s...

31 lines
1.1 KiB
Swift
Raw Normal View History

2023-01-05 11:55:20 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
2023-03-28 10:35:38 +02:00
// Licensed under the Apache License 2.0.
2023-01-05 11:55:20 +01:00
//
import Foundation
2023-02-19 10:32:38 +01:00
import PixelfedKit
2023-01-05 11:55:20 +01:00
extension AttachmentData {
2023-01-22 13:49:19 +01:00
func copyFrom(_ attachment: MediaAttachment) {
2023-01-05 11:55:20 +01:00
self.id = attachment.id
self.url = attachment.url
self.blurhash = attachment.blurhash
self.previewUrl = attachment.previewUrl
self.remoteUrl = attachment.remoteUrl
self.text = attachment.description
self.type = attachment.type.rawValue
2023-02-09 19:24:41 +01:00
// We can set image width only when it wasn't previusly recalculated.
if let width = (attachment.meta as? ImageMetadata)?.original?.width, self.metaImageWidth <= 0 && width > 0 {
self.metaImageWidth = Int32(width)
}
2023-02-09 19:24:41 +01:00
// We can set image height only when it wasn't previusly recalculated.
if let height = (attachment.meta as? ImageMetadata)?.original?.height, self.metaImageHeight <= 0 && height > 0 {
self.metaImageHeight = Int32(height)
}
2023-01-05 11:55:20 +01:00
}
}