diff --git a/Tusker/DraftsManager.swift b/Tusker/DraftsManager.swift index c3258854a5..65ca778d2c 100644 --- a/Tusker/DraftsManager.swift +++ b/Tusker/DraftsManager.swift @@ -37,8 +37,8 @@ class DraftsManager: Codable { return drafts.sorted(by: { $0.lastModified > $1.lastModified }) } - func create(text: String, attachments: [DraftAttachment]) { - drafts.append(Draft(text: text, lastModified: Date(), attachments: attachments)) + func create(text: String, contentWarning: String?, attachments: [DraftAttachment]) { + drafts.append(Draft(text: text, contentWarning: contentWarning, lastModified: Date(), attachments: attachments)) } func remove(_ draft: Draft) { @@ -52,18 +52,21 @@ extension DraftsManager { class Draft: Codable, Equatable { let id: UUID private(set) var text: String + private(set) var contentWarning: String? private(set) var lastModified: Date private(set) var attachments: [DraftAttachment] - init(text: String, lastModified: Date, attachments: [DraftAttachment]) { + init(text: String, contentWarning: String?, lastModified: Date, attachments: [DraftAttachment]) { self.id = UUID() self.text = text + self.contentWarning = contentWarning self.lastModified = lastModified self.attachments = attachments } - func update(text: String, attachments: [DraftAttachment]) { + func update(text: String, contentWarning: String?, attachments: [DraftAttachment]) { self.text = text + self.contentWarning = contentWarning self.lastModified = Date() self.attachments = attachments } diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index 2cf02e59d4..2801b357d4 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -271,9 +271,10 @@ class ComposeViewController: UIViewController { func updateHasChanges() { if let currentDraft = currentDraft { - hasChanges = statusTextView.text != currentDraft.text + let cw = contentWarningEnabled ? contentWarningTextField.text : nil + hasChanges = statusTextView.text != currentDraft.text || cw != currentDraft.contentWarning } else { - hasChanges = !statusTextView.text.isEmpty + hasChanges = !statusTextView.text.isEmpty || (contentWarningEnabled && !(contentWarningTextField.text?.isEmpty ?? true)) } } @@ -319,10 +320,11 @@ class ComposeViewController: UIViewController { attachments.append(DraftsManager.DraftAttachment(assetIdentifier: asset.localIdentifier, description: description)) } + let cw = contentWarningEnabled ? contentWarningTextField.text : nil if let currentDraft = self.currentDraft { - currentDraft.update(text: self.statusTextView.text, attachments: attachments) + currentDraft.update(text: self.statusTextView.text, contentWarning: cw, attachments: attachments) } else { - DraftsManager.shared.create(text: self.statusTextView.text, attachments: attachments) + DraftsManager.shared.create(text: self.statusTextView.text, contentWarning: cw, attachments: attachments) } } @@ -577,9 +579,11 @@ extension ComposeViewController: DraftsTableViewControllerDelegate { self.currentDraft = draft statusTextView.text = draft.text + contentWarningEnabled = draft.contentWarning != nil + contentWarningTextField.text = draft.contentWarning + updatePlaceholder() updateCharactersRemaining() - let result = PHAsset.fetchAssets(withLocalIdentifiers: draft.attachments.map { $0.assetIdentifier }, options: nil) var assets = [String: (asset: PHAsset, description: String)]() diff --git a/Tusker/Screens/Compose/Drafts/DraftTableViewCell.swift b/Tusker/Screens/Compose/Drafts/DraftTableViewCell.swift index d09de621d9..5b8dfb2240 100644 --- a/Tusker/Screens/Compose/Drafts/DraftTableViewCell.swift +++ b/Tusker/Screens/Compose/Drafts/DraftTableViewCell.swift @@ -11,12 +11,15 @@ import Photos class DraftTableViewCell: UITableViewCell { + @IBOutlet weak var contentWarningLabel: UILabel! @IBOutlet weak var contentLabel: UILabel! @IBOutlet weak var lastModifiedLabel: UILabel! @IBOutlet weak var attachmentsStackViewContainer: UIView! @IBOutlet weak var attachmentsStackView: UIStackView! func updateUI(for draft: DraftsManager.Draft) { + contentWarningLabel.text = draft.contentWarning + contentWarningLabel.isHidden = draft.contentWarning == nil contentLabel.text = draft.text lastModifiedLabel.text = draft.lastModified.timeAgoString() diff --git a/Tusker/Screens/Compose/Drafts/DraftTableViewCell.xib b/Tusker/Screens/Compose/Drafts/DraftTableViewCell.xib index 993cd72634..7aef51e858 100644 --- a/Tusker/Screens/Compose/Drafts/DraftTableViewCell.xib +++ b/Tusker/Screens/Compose/Drafts/DraftTableViewCell.xib @@ -1,28 +1,33 @@ - + - + - - - + + - + - + - - + + + - @@ -45,7 +50,7 @@ - + @@ -77,9 +82,10 @@ + - +