Fix drafts from share sheet not being saved
This commit is contained in:
parent
3d3fc3f515
commit
74a157d26c
|
@ -143,8 +143,6 @@ public final class ComposeController: ViewController {
|
|||
func cancel(deleteDraft: Bool) {
|
||||
if deleteDraft {
|
||||
DraftsManager.shared.remove(draft)
|
||||
} else {
|
||||
DraftsManager.save()
|
||||
}
|
||||
config.dismiss(.cancel)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
import Foundation
|
||||
import Combine
|
||||
import OSLog
|
||||
|
||||
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "DraftsManager")
|
||||
|
||||
public class DraftsManager: Codable, ObservableObject {
|
||||
|
||||
|
@ -21,19 +24,26 @@ public class DraftsManager: Codable, ObservableObject {
|
|||
public static func save() {
|
||||
saveQueue.async {
|
||||
let encoder = PropertyListEncoder()
|
||||
let data = try? encoder.encode(shared)
|
||||
try? data?.write(to: archiveURL, options: .noFileProtection)
|
||||
do {
|
||||
let data = try encoder.encode(shared)
|
||||
try data.write(to: archiveURL, options: .noFileProtection)
|
||||
} catch {
|
||||
logger.error("Save failed: \(String(describing: error))")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func load() -> DraftsManager {
|
||||
let decoder = PropertyListDecoder()
|
||||
if let data = try? Data(contentsOf: archiveURL),
|
||||
let draftsManager = try? decoder.decode(DraftsManager.self, from: data) {
|
||||
do {
|
||||
let data = try Data(contentsOf: archiveURL)
|
||||
let draftsManager = try decoder.decode(DraftsManager.self, from: data)
|
||||
return draftsManager
|
||||
}
|
||||
} catch {
|
||||
logger.error("Load failed: \(String(describing: error))")
|
||||
return DraftsManager()
|
||||
}
|
||||
}
|
||||
|
||||
public static func migrate(from url: URL) -> Result<Void, any Error> {
|
||||
do {
|
||||
|
|
|
@ -57,11 +57,11 @@ class ShareViewController: UIViewController {
|
|||
text: text,
|
||||
contentWarning: "",
|
||||
inReplyToID: nil,
|
||||
// TODO: get the default visibility from preferences
|
||||
visibility: .public,
|
||||
visibility: Preferences.shared.defaultPostVisibility,
|
||||
localOnly: false
|
||||
)
|
||||
draft.attachments = attachments
|
||||
DraftsManager.shared.add(draft)
|
||||
return draft
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue