Fix some polls crashing at decoding

This commit is contained in:
Thomas Ricouard 2023-01-24 21:19:14 +01:00
parent d9cf9ea59a
commit 5b3afc72de
2 changed files with 16 additions and 4 deletions

View file

@ -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
}
}
}

View file

@ -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)