Browse Source

Fix decoding Account.moved on Mastodon

master
Shadowfacts 1 month ago
parent
commit
cece8825ad
Signed by: Shadowfacts <me@shadowfacts.net> GPG Key ID: 94A5AB95422746E5
1 changed files with 35 additions and 0 deletions
  1. 35
    0
      Pachyderm/Model/Account.swift

+ 35
- 0
Pachyderm/Model/Account.swift View File

@@ -26,9 +26,44 @@ public class Account: Decodable {
26 26
     public let headerStatic: URL
27 27
     public private(set) var emojis: [Emoji]
28 28
     public let moved: Bool?
29
+    public let movedTo: Account?
29 30
     public let fields: [Field]?
30 31
     public let bot: Bool?
31 32
     
33
+    public required init(from decoder: Decoder) throws {
34
+        let container = try decoder.container(keyedBy: CodingKeys.self)
35
+        
36
+        self.id = try container.decode(String.self, forKey: .id)
37
+        self.username = try container.decode(String.self, forKey: .username)
38
+        self.acct = try container.decode(String.self, forKey: .acct)
39
+        self.displayName = try container.decode(String.self, forKey: .displayName)
40
+        self.locked = try container.decode(Bool.self, forKey: .locked)
41
+        self.createdAt = try container.decode(Date.self, forKey: .createdAt)
42
+        self.followersCount = try container.decode(Int.self, forKey: .followersCount)
43
+        self.followingCount = try container.decode(Int.self, forKey: .followingCount)
44
+        self.statusesCount = try container.decode(Int.self, forKey: .statusesCount)
45
+        self.note = try container.decode(String.self, forKey: .note)
46
+        self.url = try container.decode(URL.self, forKey: .url)
47
+        self.avatar = try container.decode(URL.self, forKey: .avatar)
48
+        self.avatarStatic = try container.decode(URL.self, forKey: .avatarStatic)
49
+        self.header = try container.decode(URL.self, forKey: .header)
50
+        self.headerStatic = try container.decode(URL.self, forKey: .url)
51
+        self.emojis = try container.decode([Emoji].self, forKey: .emojis)
52
+        self.fields = try? container.decode([Field].self, forKey: .fields)
53
+        self.bot = try? container.decode(Bool.self, forKey: .bot)
54
+        
55
+        if let moved = try? container.decode(Bool.self, forKey: .moved) {
56
+            self.moved = moved
57
+            self.movedTo = nil
58
+        } else if let account = try? container.decode(Account.self, forKey: .moved) {
59
+            self.moved = true
60
+            self.movedTo = account
61
+        } else {
62
+            self.moved = false
63
+            self.movedTo = nil
64
+        }
65
+    }
66
+    
32 67
     public static func authorizeFollowRequest(_ account: Account) -> Request<Relationship> {
33 68
         return Request<Relationship>(method: .post, path: "/api/v1/follow_requests/\(account.id)/authorize")
34 69
     }

Loading…
Cancel
Save