Prevent empty drafts from being saved

This commit is contained in:
Shadowfacts 2020-02-22 15:43:17 -05:00
parent a814ee37cc
commit d9bae42f81
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 13 additions and 4 deletions

View File

@ -367,12 +367,21 @@ class ComposeViewController: UIViewController {
let description = mediaView.descriptionTextView.text ?? "" let description = mediaView.descriptionTextView.text ?? ""
attachments.append(.init(attachment: attachment, description: description)) attachments.append(.init(attachment: attachment, description: description))
} }
let cw = contentWarningEnabled ? contentWarningTextField.text : nil let statusText = statusTextView.text.trimmingCharacters(in: .whitespacesAndNewlines)
let cw = contentWarningEnabled ? contentWarningTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) : nil
let account = mastodonController.accountInfo! let account = mastodonController.accountInfo!
if attachments.count == 0, statusText.isEmpty, cw?.isEmpty ?? true {
if let currentDraft = self.currentDraft { if let currentDraft = self.currentDraft {
currentDraft.update(accountID: account.id, text: self.statusTextView.text, contentWarning: cw, attachments: attachments) DraftsManager.shared.remove(currentDraft)
} else { } else {
self.currentDraft = DraftsManager.shared.create(accountID: account.id, text: self.statusTextView.text, contentWarning: cw, inReplyToID: inReplyToID, attachments: attachments) return
}
} else {
if let currentDraft = self.currentDraft {
currentDraft.update(accountID: account.id, text: statusText, contentWarning: cw, attachments: attachments)
} else {
self.currentDraft = DraftsManager.shared.create(accountID: account.id, text: statusText, contentWarning: cw, inReplyToID: inReplyToID, attachments: attachments)
}
} }
DraftsManager.save() DraftsManager.save()
} }