From b21703f6d99b9e3a0a898cf9cd7e0a1f2fb91325 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 11 May 2023 16:15:36 -0400 Subject: [PATCH] Fix decoding polls on Calckey See #362 --- .../Pachyderm/Sources/Pachyderm/Model/Poll.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Packages/Pachyderm/Sources/Pachyderm/Model/Poll.swift b/Packages/Pachyderm/Sources/Pachyderm/Model/Poll.swift index 6e6668f8..d1c7a663 100644 --- a/Packages/Pachyderm/Sources/Pachyderm/Model/Poll.swift +++ b/Packages/Pachyderm/Sources/Pachyderm/Model/Poll.swift @@ -24,6 +24,20 @@ public struct Poll: Codable, Sendable { expired || (expiresAt != nil && expiresAt! < Date()) } + public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decode(String.self, forKey: .id) + self.expiresAt = try container.decodeIfPresent(Date.self, forKey: .expiresAt) + self.expired = try container.decode(Bool.self, forKey: .expired) + self.multiple = try container.decode(Bool.self, forKey: .multiple) + self.votesCount = try container.decode(Int.self, forKey: .votesCount) + self.votersCount = try container.decodeIfPresent(Int.self, forKey: .votersCount) + self.voted = try container.decodeIfPresent(Bool.self, forKey: .voted) + self.ownVotes = try container.decodeIfPresent([Int].self, forKey: .ownVotes) + self.options = try container.decode([Poll.Option].self, forKey: .options) + self.emojis = try container.decodeIfPresent([Emoji].self, forKey: .emojis) ?? [] + } + public static func vote(_ pollID: String, choices: [Int]) -> Request { return Request(method: .post, path: "/api/v1/polls/\(pollID)/votes", body: FormDataBody("choices" => choices, nil)) }