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(Draft): Single message thread only #925

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
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
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
Loading