Skip to content

Commit

Permalink
fix(Draft): Single message thread only
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambrdctr committed Aug 14, 2023
1 parent 982ae75 commit fbcd09b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion MailCore/Cache/MailboxManager/MailboxManager+Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public extension MailboxManager {
var threadsToUpdate = Set<Thread>()

let existingThreads = Array(realm.objects(Thread.self)
.where { $0.messageIds.containsAny(in: message.linkedUids) /* && $0.isConversationThread == true */ })
.where { $0.messageIds.containsAny(in: message.linkedUids) })

if let newThread = createNewThreadIfRequired(
for: message,
Expand Down Expand Up @@ -418,6 +418,11 @@ public extension MailboxManager {
}

private func createNewThreadIfRequired(for message: Message, folder: Folder, existingThreads: [Thread]) -> Thread? {
guard folder.role != .draft else {
let thread = message.toThread().detached()
folder.threads.insert(thread)
return thread
}
guard !existingThreads.contains(where: { $0.folder == folder }) else { return nil }

let thread = message.toThread().detached()
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Models/Thread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public class Thread: Object, Decodable, Identifiable {
let shouldAddMessage: Bool
switch folderRole {
case .draft:
shouldAddMessage = newMessage.isDraft
shouldAddMessage = false
case .trash:
shouldAddMessage = newMessage.inTrash
default:
Expand Down

0 comments on commit fbcd09b

Please sign in to comment.