Skip to content

Commit

Permalink
fix: Provide default date when decoding Thread
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed Dec 14, 2023
1 parent 610f302 commit 023ef4c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions MailCore/Models/Thread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ public class Thread: Object, Decodable, Identifiable {
self.answered = answered
self.forwarded = forwarded
}

public required init(from decoder: Decoder) throws {
super.init()

let container = try decoder.container(keyedBy: CodingKeys.self)
uid = try container.decode(String.self, forKey: .uid)
messages = try container.decode(List<Message>.self, forKey: .messages)
unseenMessages = try container.decode(Int.self, forKey: .unseenMessages)
from = try container.decode(List<Recipient>.self, forKey: .from)
to = try container.decode(List<Recipient>.self, forKey: .to)
subject = try container.decode(String?.self, forKey: .subject)
date = try container.decodeIfPresent(Date.self, forKey: .date) ?? Date()
hasAttachments = try container.decode(Bool.self, forKey: .hasAttachments)
hasDrafts = try container.decode(Bool.self, forKey: .hasDrafts)
flagged = try container.decode(Bool.self, forKey: .flagged)
answered = try container.decode(Bool.self, forKey: .answered)
forwarded = try container.decode(Bool.self, forKey: .forwarded)
}

override public init() {
super.init()
}
}

public extension Thread {
Expand Down

0 comments on commit 023ef4c

Please sign in to comment.