2017-07-02 02:22:19 +02:00
|
|
|
//
|
|
|
|
// Attachment.swift
|
|
|
|
// DataModel
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 7/1/17.
|
|
|
|
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2017-07-17 04:36:38 +02:00
|
|
|
public struct Attachment: Hashable {
|
2017-07-02 02:22:19 +02:00
|
|
|
|
2017-08-21 07:43:46 +02:00
|
|
|
public let attachmentID: String // Calculated
|
2017-07-08 02:49:16 +02:00
|
|
|
public let url: String
|
2017-07-02 02:22:19 +02:00
|
|
|
public let mimeType: String?
|
|
|
|
public let title: String?
|
|
|
|
public let sizeInBytes: Int?
|
|
|
|
public let durationInSeconds: Int?
|
2017-07-17 04:36:38 +02:00
|
|
|
public let hashValue: Int
|
2017-07-02 02:22:19 +02:00
|
|
|
|
2017-08-21 07:43:46 +02:00
|
|
|
public init(attachmentID: String?, url: String, mimeType: String?, title: String?, sizeInBytes: Int?, durationInSeconds: Int?) {
|
2017-07-02 02:22:19 +02:00
|
|
|
|
|
|
|
self.url = url
|
|
|
|
self.mimeType = mimeType
|
|
|
|
self.title = title
|
2017-09-13 06:19:45 +02:00
|
|
|
if let sizeInBytes = sizeInBytes, sizeInBytes > 0 {
|
|
|
|
self.sizeInBytes = sizeInBytes
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.sizeInBytes = nil
|
|
|
|
}
|
|
|
|
if let durationInSeconds = durationInSeconds, durationInSeconds > 0 {
|
|
|
|
self.durationInSeconds = durationInSeconds
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.durationInSeconds = nil
|
|
|
|
}
|
2017-07-17 04:36:38 +02:00
|
|
|
|
2017-08-21 07:43:46 +02:00
|
|
|
var s = url
|
2017-07-17 04:36:38 +02:00
|
|
|
s += mimeType ?? ""
|
|
|
|
s += title ?? ""
|
|
|
|
if let sizeInBytes = sizeInBytes {
|
|
|
|
s += "\(sizeInBytes)"
|
|
|
|
}
|
|
|
|
if let durationInSeconds = durationInSeconds {
|
|
|
|
s += "\(durationInSeconds)"
|
|
|
|
}
|
|
|
|
self.hashValue = s.hashValue
|
|
|
|
|
2017-08-21 07:43:46 +02:00
|
|
|
if let attachmentID = attachmentID {
|
|
|
|
self.attachmentID = attachmentID
|
2017-07-17 04:36:38 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-08-21 07:43:46 +02:00
|
|
|
self.attachmentID = databaseIDWithString(s)
|
2017-07-17 04:36:38 +02:00
|
|
|
}
|
2017-07-02 02:22:19 +02:00
|
|
|
}
|
|
|
|
|
2017-07-03 19:29:44 +02:00
|
|
|
public static func ==(lhs: Attachment, rhs: Attachment) -> Bool {
|
2017-07-02 02:22:19 +02:00
|
|
|
|
2017-09-05 02:10:02 +02:00
|
|
|
return lhs.hashValue == rhs.hashValue && lhs.attachmentID == rhs.attachmentID
|
2017-07-02 02:22:19 +02:00
|
|
|
}
|
|
|
|
}
|