From cece8825adb58ee807e5e7640bdd3890a33ef452 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 20 Jan 2020 12:10:10 -0500 Subject: [PATCH] Fix decoding Account.moved on Mastodon --- Pachyderm/Model/Account.swift | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Pachyderm/Model/Account.swift b/Pachyderm/Model/Account.swift index 63202d75..66b2d9cb 100644 --- a/Pachyderm/Model/Account.swift +++ b/Pachyderm/Model/Account.swift @@ -26,9 +26,44 @@ public class Account: Decodable { public let headerStatic: URL public private(set) var emojis: [Emoji] public let moved: Bool? + public let movedTo: Account? public let fields: [Field]? public let bot: Bool? + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.id = try container.decode(String.self, forKey: .id) + self.username = try container.decode(String.self, forKey: .username) + self.acct = try container.decode(String.self, forKey: .acct) + self.displayName = try container.decode(String.self, forKey: .displayName) + self.locked = try container.decode(Bool.self, forKey: .locked) + self.createdAt = try container.decode(Date.self, forKey: .createdAt) + self.followersCount = try container.decode(Int.self, forKey: .followersCount) + self.followingCount = try container.decode(Int.self, forKey: .followingCount) + self.statusesCount = try container.decode(Int.self, forKey: .statusesCount) + self.note = try container.decode(String.self, forKey: .note) + self.url = try container.decode(URL.self, forKey: .url) + self.avatar = try container.decode(URL.self, forKey: .avatar) + self.avatarStatic = try container.decode(URL.self, forKey: .avatarStatic) + self.header = try container.decode(URL.self, forKey: .header) + self.headerStatic = try container.decode(URL.self, forKey: .url) + self.emojis = try container.decode([Emoji].self, forKey: .emojis) + self.fields = try? container.decode([Field].self, forKey: .fields) + self.bot = try? container.decode(Bool.self, forKey: .bot) + + if let moved = try? container.decode(Bool.self, forKey: .moved) { + self.moved = moved + self.movedTo = nil + } else if let account = try? container.decode(Account.self, forKey: .moved) { + self.moved = true + self.movedTo = account + } else { + self.moved = false + self.movedTo = nil + } + } + public static func authorizeFollowRequest(_ account: Account) -> Request { return Request(method: .post, path: "/api/v1/follow_requests/\(account.id)/authorize") }