diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index d4382ef9..d1c9cae5 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -367,12 +367,21 @@ class ComposeViewController: UIViewController { let description = mediaView.descriptionTextView.text ?? "" 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! - if let currentDraft = self.currentDraft { - currentDraft.update(accountID: account.id, text: self.statusTextView.text, contentWarning: cw, attachments: attachments) + if attachments.count == 0, statusText.isEmpty, cw?.isEmpty ?? true { + if let currentDraft = self.currentDraft { + DraftsManager.shared.remove(currentDraft) + } else { + return + } } else { - self.currentDraft = DraftsManager.shared.create(accountID: account.id, text: self.statusTextView.text, contentWarning: cw, inReplyToID: inReplyToID, attachments: attachments) + 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() }