@@ -53,6 +53,9 @@ public class DraftContentManager: ObservableObject {
53
53
self . draftLocalUUID = draftLocalUUID
54
54
self . messageReply = messageReply
55
55
self . mailboxManager = mailboxManager
56
+ }
57
+
58
+ public func startObservingDraft( ) {
56
59
draftContentObservation = _draftContent
57
60
. projectedValue
58
61
. throttle ( for: . milliseconds( 1000 ) , scheduler: DispatchQueue . global ( qos: . userInitiated) , latest: true )
@@ -238,14 +241,13 @@ public extension DraftContentManager {
238
241
shouldAddSignatureText: Bool ,
239
242
attachments: [ Attachment ] ,
240
243
draftPrimaryKey: String
241
- ) throws {
242
- var fetchedDraft : Draft ?
244
+ ) async throws {
245
+ var updatedDraftBody : String ?
243
246
try mailboxManager. writeTransaction { writableRealm in
244
247
guard let liveIncompleteDraft = getLiveDraft ( realm: writableRealm, draftPrimaryKey: draftPrimaryKey) else {
245
248
return
246
249
}
247
250
248
- fetchedDraft = liveIncompleteDraft
249
251
if let signature, liveIncompleteDraft. identityId == nil || liveIncompleteDraft. identityId? . isEmpty == true {
250
252
liveIncompleteDraft. identityId = " \( signature. id) "
251
253
if shouldAddSignatureText {
@@ -259,11 +261,17 @@ public extension DraftContentManager {
259
261
for attachment in attachments {
260
262
liveIncompleteDraft. attachments. append ( attachment)
261
263
}
264
+
265
+ updatedDraftBody = liveIncompleteDraft. body
262
266
}
263
267
264
- guard fetchedDraft != nil else {
268
+ guard let updatedDraftBody else {
265
269
throw MailError . unknownError
266
270
}
271
+
272
+ await Task { @MainActor in
273
+ self . draftContent = updatedDraftBody
274
+ } . value
267
275
}
268
276
}
269
277
0 commit comments