1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Foundation
extension AppModel {
func loadSavedDrafts(cursor: String?) async throws -> SavedPostDraftPage {
guard account != nil, !isSigningOut else { throw ServiceError.noSession }
let generation = sessionGeneration
let page = try await service.loadDrafts(cursor: cursor)
guard generation == sessionGeneration, !isSigningOut else { throw ServiceError.noSession }
return page
}
func loadSavedDraft(id: String) async throws -> ComposerDraft {
guard account != nil, !isSigningOut else { throw ServiceError.noSession }
let generation = sessionGeneration
let draft = try await service.loadDraft(id: id)
guard generation == sessionGeneration, !isSigningOut else { throw ServiceError.noSession }
for postID in [draft.replyTo, draft.quotePostID].compactMap({ $0 }) {
if post(id: postID) == nil { await loadPost(id: postID) }
guard generation == sessionGeneration, !isSigningOut else { throw ServiceError.noSession }
guard let context = post(id: postID), canShowTimelineContent(context) else {
throw ServiceError.postReferenceUnavailable
}
}
guard generation == sessionGeneration, !isSigningOut else { throw ServiceError.noSession }
return draft
}
func saveSavedDraft(_ draft: ComposerDraft, id: String?) async throws -> String {
guard account != nil, !isSigningOut else { throw ServiceError.noSession }
let generation = sessionGeneration
let savedID = try await service.saveDraft(draft, id: id)
guard generation == sessionGeneration, !isSigningOut else { throw ServiceError.noSession }
return savedID
}
func deleteSavedDraft(id: String) async throws {
guard account != nil, !isSigningOut else { throw ServiceError.noSession }
let generation = sessionGeneration
try await service.deleteDraft(id: id)
guard generation == sessionGeneration, !isSigningOut else { throw ServiceError.noSession }
}
}