2020-08-28 21:56:28 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
2020-08-31 01:33:11 +02:00
|
|
|
import Mastodon
|
2020-08-28 21:56:28 +02:00
|
|
|
|
2020-09-01 09:33:49 +02:00
|
|
|
public struct AttachmentViewModel {
|
|
|
|
public let attachment: Attachment
|
2020-08-28 21:56:28 +02:00
|
|
|
|
2020-10-22 07:05:50 +02:00
|
|
|
private let status: Status
|
|
|
|
|
|
|
|
init(attachment: Attachment, status: Status) {
|
2020-08-28 21:56:28 +02:00
|
|
|
self.attachment = attachment
|
2020-10-22 07:05:50 +02:00
|
|
|
self.status = status
|
2020-08-28 21:56:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 09:33:49 +02:00
|
|
|
public extension AttachmentViewModel {
|
2020-10-22 07:05:50 +02:00
|
|
|
var tag: Int {
|
|
|
|
attachment.id.appending(status.id).hashValue
|
|
|
|
}
|
|
|
|
|
2020-08-28 21:56:28 +02:00
|
|
|
var aspectRatio: Double? {
|
|
|
|
if
|
|
|
|
let info = attachment.meta?.original,
|
|
|
|
let width = info.width,
|
|
|
|
let height = info.height,
|
|
|
|
width != 0,
|
|
|
|
height != 0 {
|
|
|
|
let aspectRatio = Double(width) / Double(height)
|
|
|
|
|
|
|
|
return aspectRatio.isNaN ? nil : aspectRatio
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|