Skip to content

Commit

Permalink
fix: Message uids always use string
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed May 11, 2023
1 parent 3b3ee29 commit 53a6ae3
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions MailCore/Models/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import MailResources
import RealmSwift

public class MessageUidsResult: Decodable {
public let messageShortUids: [Int]
public let messageShortUids: [String]
public let cursor: String

private enum CodingKeys: String, CodingKey {
Expand All @@ -35,7 +35,7 @@ public class MessageByUidsResult: Decodable {
}

public class MessageDeltaResult: Decodable {
public let deletedShortUids: [Int]
public let deletedShortUids: [String]
public let addedShortUids: [String]
public let updated: [MessageFlags]
public let cursor: String
Expand All @@ -46,6 +46,24 @@ public class MessageDeltaResult: Decodable {
case updated
case cursor = "signature"
}

// FIXME: Remove this constructor when mixed Int/String arrayis fixed by backend
public required init(from decoder: Decoder) throws {
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)

if let deletedShortUids = try? container.decode([String].self, forKey: .deletedShortUids) {
self.deletedShortUids = deletedShortUids
} else {
deletedShortUids = try container.decode([Int].self, forKey: .deletedShortUids).map { "\($0)" }
}
if let addedShortUids = try? container.decode([String].self, forKey: .addedShortUids) {
self.addedShortUids = addedShortUids
} else {
addedShortUids = try container.decode([Int].self, forKey: .addedShortUids).map { "\($0)" }
}
updated = try container.decode([MessageFlags].self, forKey: .updated)
cursor = try container.decode(String.self, forKey: .cursor)
}
}

public class MessageFlags: Decodable {
Expand Down

0 comments on commit 53a6ae3

Please sign in to comment.