From 7bbe3cbc41da76d0930e416d4442798111669349 Mon Sep 17 00:00:00 2001 From: Yusuke Arakawa <108506642+nekolaboratory@users.noreply.github.com> Date: Tue, 14 Feb 2023 20:19:23 +0900 Subject: [PATCH] Fixed non-existing Json key decoding error (#832) Co-authored-by: Yusuke Arakawa --- .../Models/Sources/Models/Relationship.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Packages/Models/Sources/Models/Relationship.swift b/Packages/Models/Sources/Models/Relationship.swift index 29712121..09965d5c 100644 --- a/Packages/Models/Sources/Models/Relationship.swift +++ b/Packages/Models/Sources/Models/Relationship.swift @@ -31,3 +31,22 @@ public struct Relationship: Codable { notifying: false) } } + +public extension Relationship { + init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decodeIfPresent(String.self, forKey: .id) ?? "" + following = try values.decodeIfPresent(Bool.self, forKey: .following) ?? false + showingReblogs = try values.decodeIfPresent(Bool.self, forKey: .showingReblogs) ?? false + followedBy = try values.decodeIfPresent(Bool.self, forKey: .followedBy) ?? false + blocking = try values.decodeIfPresent(Bool.self, forKey: .blocking) ?? false + blockedBy = try values.decodeIfPresent(Bool.self, forKey: .blockedBy) ?? false + muting = try values.decodeIfPresent(Bool.self, forKey: .muting) ?? false + mutingNotifications = try values.decodeIfPresent(Bool.self, forKey: .mutingNotifications) ?? false + requested = try values.decodeIfPresent(Bool.self, forKey: .requested) ?? false + domainBlocking = try values.decodeIfPresent(Bool.self, forKey: .domainBlocking) ?? false + endorsed = try values.decodeIfPresent(Bool.self, forKey: .endorsed) ?? false + note = try values.decodeIfPresent(String.self, forKey: .note) ?? "" + notifying = try values.decodeIfPresent(Bool.self, forKey: .notifying) ?? false + } +}