Sesame-iOS/Sesame/History/HistoryItem.swift

56 lines
1.2 KiB
Swift
Raw Normal View History

import Foundation
2023-12-12 17:33:42 +01:00
import SwiftData
2023-12-12 17:33:42 +01:00
@Model
final class HistoryItem {
2023-12-12 17:33:42 +01:00
let startDate: Date
2023-12-12 17:33:42 +01:00
let message: Message
2023-12-12 17:33:42 +01:00
let route: TransmissionType
2023-12-12 17:33:42 +01:00
let finishDate: Date
2023-12-12 17:33:42 +01:00
init(message: Message, startDate: Date, route: TransmissionType, finishDate: Date) {
self.startDate = startDate
self.message = message
self.finishDate = finishDate
self.route = route
}
2023-12-12 17:33:42 +01:00
var roundTripTime: TimeInterval {
finishDate.timeIntervalSince(startDate)
}
2023-12-12 17:33:42 +01:00
var response: MessageResult {
message.result
}
}
extension HistoryItem: Identifiable {
2023-12-12 17:33:42 +01:00
var id: Double {
startDate.timeIntervalSince1970
}
}
extension HistoryItem: Comparable {
2023-12-12 17:33:42 +01:00
static func < (lhs: HistoryItem, rhs: HistoryItem) -> Bool {
2023-12-12 17:33:42 +01:00
lhs.startDate < rhs.startDate
}
}
extension HistoryItem {
2023-12-12 17:33:42 +01:00
static var mock: HistoryItem {
2023-12-12 17:33:42 +01:00
let message = Message(messageType: .request, clientChallenge: 123, serverChallenge: 234, result: .unlocked)
2023-08-14 10:39:29 +02:00
return .init(
2023-12-12 17:33:42 +01:00
message: message,
startDate: Date.now.addingTimeInterval(-5),
route: .throughServer,
finishDate: Date.now)
}
}