Fix some polls crashing at decoding
This commit is contained in:
parent
d9cf9ea59a
commit
5b3afc72de
|
@ -20,12 +20,24 @@ public struct Poll: Codable, Equatable, Hashable {
|
|||
}
|
||||
|
||||
public let id: String
|
||||
public let expiresAt: ServerDate
|
||||
public let expiresAt: NullableString
|
||||
public let expired: Bool
|
||||
public let multiple: Bool
|
||||
public let votesCount: Int
|
||||
public let votersCount: Int?
|
||||
public let voted: Bool?
|
||||
public let ownVotes: [Int]?
|
||||
public let options: [Option]
|
||||
}
|
||||
|
||||
public struct NullableString: Codable, Equatable, Hashable {
|
||||
public let value: String?
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
do {
|
||||
let container = try decoder.singleValueContainer()
|
||||
self.value = try container.decode(String.self)
|
||||
} catch {
|
||||
self.value = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,9 +72,9 @@ public struct StatusPollView: View {
|
|||
Text(" ⸱ ")
|
||||
if viewModel.poll.expired {
|
||||
Text("status.poll.closed")
|
||||
} else {
|
||||
} else if let date = viewModel.poll.expiresAt.value?.asDate {
|
||||
Text("status.poll.closes-in")
|
||||
Text(viewModel.poll.expiresAt.asDate, style: .timer)
|
||||
Text(date, style: .timer)
|
||||
}
|
||||
}
|
||||
.font(.scaledFootnote)
|
||||
|
|
Loading…
Reference in New Issue