From 3a19246f786d6405ca2990471a3bcaaeb1ee477d Mon Sep 17 00:00:00 2001 From: Micha Date: Sun, 16 Nov 2025 13:03:02 +0100 Subject: [PATCH] Default server pingable flag when decoding --- Model/API/Server.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Model/API/Server.swift b/Model/API/Server.swift index 1f0f0d4..259240b 100644 --- a/Model/API/Server.swift +++ b/Model/API/Server.swift @@ -36,4 +36,20 @@ struct Server: Identifiable, Codable, Hashable, Equatable { enum CodingKeys: String, CodingKey { case id, hostname, info, pingable } + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + id = try container.decode(UUID.self, forKey: .id) + hostname = try container.decode(String.self, forKey: .hostname) + info = try container.decodeIfPresent(ServerInfo.self, forKey: .info) + pingable = try container.decodeIfPresent(Bool.self, forKey: .pingable) ?? false + } + + func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(hostname, forKey: .hostname) + try container.encodeIfPresent(info, forKey: .info) + try container.encode(pingable, forKey: .pingable) + } }