Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-04-19 00:46:00 +02:00
parent ce19d00de3
commit a11d88d365
14 changed files with 2947 additions and 76 deletions
+10 -2
View File
@@ -13,6 +13,7 @@ final class AppViewModel {
var composeDraft = ComposeDraft()
var threads: [MailThread] = []
var isLoading = false
var isSending = false
var errorMessage: String?
var mailboxNavigationToken = UUID()
var threadNavigationToken = UUID()
@@ -158,6 +159,7 @@ final class AppViewModel {
func beginBackendControl() async {
guard !isListeningForBackendCommands else { return }
isListeningForBackendCommands = true
defer { isListeningForBackendCommands = false }
for await command in controlService.commands() {
apply(command: command)
@@ -206,17 +208,23 @@ final class AppViewModel {
}
}
func sendCurrentDraft() async {
func sendCurrentDraft() async -> Bool {
guard !isSending else { return false }
let draft = composeDraft
isComposing = false
isSending = true
defer { isSending = false }
do {
let sentThread = try await service.send(draft: draft)
threads.insert(sentThread, at: 0)
selectedMailbox = .sent
openThread(withID: sentThread.id)
isComposing = false
return true
} catch {
errorMessage = "Unable to send message."
return false
}
}