Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user