mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Group image and video metadata in specialised structs (#3518)
This commit is contained in:
@@ -215,11 +215,111 @@ struct SendHandleProxy: Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
extension Receipt {
|
||||
var dateTimestamp: Date? {
|
||||
guard let timestamp else {
|
||||
return nil
|
||||
}
|
||||
return Date(timeIntervalSince1970: TimeInterval(timestamp / 1000))
|
||||
struct VideoInfoProxy: Hashable {
|
||||
let source: MediaSourceProxy
|
||||
private(set) var duration: TimeInterval
|
||||
private(set) var size: CGSize?
|
||||
private(set) var aspectRatio: CGFloat?
|
||||
private(set) var mimeType: String?
|
||||
|
||||
init(source: MediaSource, duration: TimeInterval, width: UInt64?, height: UInt64?, mimeType: String?) {
|
||||
self.source = MediaSourceProxy(source: source, mimeType: mimeType)
|
||||
self.duration = duration
|
||||
|
||||
let mediaInfo = MediaInfoProxy(width: width, height: height, mimeType: mimeType)
|
||||
size = mediaInfo.size
|
||||
aspectRatio = mediaInfo.aspectRatio
|
||||
self.mimeType = mediaInfo.mimeType
|
||||
}
|
||||
|
||||
// MARK: - Mocks
|
||||
|
||||
private init(source: MediaSourceProxy, duration: TimeInterval, size: CGSize?, aspectRatio: CGFloat?, mimeType: String?) {
|
||||
self.source = source
|
||||
self.duration = duration
|
||||
self.size = size
|
||||
self.aspectRatio = aspectRatio
|
||||
self.mimeType = mimeType
|
||||
}
|
||||
|
||||
static var mockVideo: VideoInfoProxy {
|
||||
.init(source: .init(url: .picturesDirectory, mimeType: nil),
|
||||
duration: 100,
|
||||
size: .init(width: 1920, height: 1080),
|
||||
aspectRatio: 1.78,
|
||||
mimeType: nil)
|
||||
}
|
||||
}
|
||||
|
||||
struct ImageInfoProxy: Hashable {
|
||||
let source: MediaSourceProxy
|
||||
private(set) var size: CGSize?
|
||||
private(set) var aspectRatio: CGFloat?
|
||||
private(set) var mimeType: String?
|
||||
|
||||
init?(source: MediaSource?, width: UInt64?, height: UInt64?, mimeType: String?) {
|
||||
guard let source else {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.init(source: .init(source: source, mimeType: mimeType), width: width, height: height, mimeType: mimeType)
|
||||
}
|
||||
|
||||
init(source: MediaSource, width: UInt64?, height: UInt64?, mimeType: String?) {
|
||||
self.init(source: .init(source: source, mimeType: mimeType), width: width, height: height, mimeType: mimeType)
|
||||
}
|
||||
|
||||
init(url: URL, width: UInt64?, height: UInt64?, mimeType: String?) {
|
||||
self.init(source: .init(url: url, mimeType: mimeType), width: width, height: height, mimeType: mimeType)
|
||||
}
|
||||
|
||||
init(source: MediaSourceProxy, width: UInt64?, height: UInt64?, mimeType: String?) {
|
||||
self.source = source
|
||||
|
||||
let mediaInfo = MediaInfoProxy(width: width, height: height, mimeType: mimeType)
|
||||
size = mediaInfo.size
|
||||
aspectRatio = mediaInfo.aspectRatio
|
||||
self.mimeType = mediaInfo.mimeType
|
||||
}
|
||||
|
||||
// MARK: - Mocks
|
||||
|
||||
private init(source: MediaSourceProxy, size: CGSize?, aspectRatio: CGFloat?, mimeType: String?) {
|
||||
self.source = source
|
||||
self.size = size
|
||||
self.aspectRatio = aspectRatio
|
||||
self.mimeType = mimeType
|
||||
}
|
||||
|
||||
static var mockImage: ImageInfoProxy {
|
||||
.init(source: .init(url: .picturesDirectory, mimeType: "image/png"),
|
||||
size: .init(width: 100, height: 100),
|
||||
aspectRatio: 1,
|
||||
mimeType: "image/png")
|
||||
}
|
||||
|
||||
static var mockThumbnail: ImageInfoProxy {
|
||||
.init(source: .init(url: .picturesDirectory, mimeType: nil),
|
||||
size: nil,
|
||||
aspectRatio: nil,
|
||||
mimeType: nil)
|
||||
}
|
||||
}
|
||||
|
||||
struct MediaInfoProxy: Hashable {
|
||||
private(set) var size: CGSize?
|
||||
private(set) var mimeType: String?
|
||||
private(set) var aspectRatio: CGFloat?
|
||||
|
||||
init(width: UInt64?, height: UInt64?, mimeType: String?) {
|
||||
if let width, let height {
|
||||
size = .init(width: CGFloat(width), height: CGFloat(height))
|
||||
|
||||
if width > 0, height > 0 {
|
||||
aspectRatio = CGFloat(width) / CGFloat(height)
|
||||
}
|
||||
}
|
||||
|
||||
self.mimeType = mimeType
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user