Attempt to fix history item bug on WatchOS
This commit is contained in:
parent
973f0cb1c1
commit
e4f93d94a9
@ -6,7 +6,11 @@ final class HistoryItem {
|
||||
|
||||
let startDate: Date
|
||||
|
||||
let message: HistoryMessage
|
||||
let messageData: Data
|
||||
|
||||
var message: Message {
|
||||
try! .init(decodeFrom: messageData)
|
||||
}
|
||||
|
||||
let route: TransmissionType
|
||||
|
||||
@ -14,11 +18,7 @@ final class HistoryItem {
|
||||
|
||||
init(message: Message, startDate: Date, route: TransmissionType, finishDate: Date) {
|
||||
self.startDate = startDate
|
||||
self.message = .init(
|
||||
messageType: message.messageType,
|
||||
clientChallenge: Int(message.clientChallenge),
|
||||
serverChallenge: Int(message.serverChallenge),
|
||||
result: message.result)
|
||||
self.messageData = message.encoded
|
||||
self.finishDate = finishDate
|
||||
self.route = route
|
||||
}
|
||||
@ -32,59 +32,6 @@ final class HistoryItem {
|
||||
}
|
||||
}
|
||||
|
||||
struct HistoryMessage {
|
||||
|
||||
/// The type of message being sent.
|
||||
let messageType: MessageType
|
||||
|
||||
/**
|
||||
* The random nonce created by the remote
|
||||
*
|
||||
* This nonce is a random number created by the remote, different for each unlock request.
|
||||
* It is set for all message types.
|
||||
*/
|
||||
let clientChallenge: Int
|
||||
|
||||
/**
|
||||
* A random number to sign by the remote
|
||||
*
|
||||
* This nonce is set by the server after receiving an initial message.
|
||||
* It is set for the message types `challenge`, `request`, and `response`.
|
||||
*/
|
||||
let serverChallenge: Int
|
||||
|
||||
/**
|
||||
* The response status for the previous message.
|
||||
*
|
||||
* It is set only for messages from the server, e.g. the `challenge` and `response` message types.
|
||||
* Must be set to `MessageAccepted` for other messages.
|
||||
*/
|
||||
let result: MessageResult
|
||||
}
|
||||
|
||||
extension HistoryMessage: Encodable {
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.unkeyedContainer()
|
||||
try container.encode(messageType)
|
||||
try container.encode(clientChallenge)
|
||||
try container.encode(serverChallenge)
|
||||
try container.encode(result)
|
||||
}
|
||||
}
|
||||
|
||||
extension HistoryMessage: Decodable {
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
var container = try decoder.unkeyedContainer()
|
||||
self.messageType = try container.decode(MessageType.self)
|
||||
self.clientChallenge = try container.decode(Int.self)
|
||||
self.serverChallenge = try container.decode(Int.self)
|
||||
self.result = try container.decode(MessageResult.self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension HistoryItem: Identifiable {
|
||||
|
||||
var id: Double {
|
||||
|
Loading…
Reference in New Issue
Block a user