Fix decoding Account.moved on Mastodon
This commit is contained in:
parent
f9ffb240ef
commit
cece8825ad
|
@ -26,9 +26,44 @@ public class Account: Decodable {
|
||||||
public let headerStatic: URL
|
public let headerStatic: URL
|
||||||
public private(set) var emojis: [Emoji]
|
public private(set) var emojis: [Emoji]
|
||||||
public let moved: Bool?
|
public let moved: Bool?
|
||||||
|
public let movedTo: Account?
|
||||||
public let fields: [Field]?
|
public let fields: [Field]?
|
||||||
public let bot: Bool?
|
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<Relationship> {
|
public static func authorizeFollowRequest(_ account: Account) -> Request<Relationship> {
|
||||||
return Request<Relationship>(method: .post, path: "/api/v1/follow_requests/\(account.id)/authorize")
|
return Request<Relationship>(method: .post, path: "/api/v1/follow_requests/\(account.id)/authorize")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue