Prevent empty drafts from being saved
This commit is contained in:
parent
a814ee37cc
commit
d9bae42f81
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue