Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Message uids always use string #744

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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