diff --git a/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentsListController.swift b/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentsListController.swift index 215506d02f..51a4f0aad9 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentsListController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentsListController.swift @@ -17,18 +17,20 @@ class AttachmentsListController: ViewController { var isValid: Bool { !requiresAttachmentDescriptions && validAttachmentCombination } - + private var requiresAttachmentDescriptions: Bool { if parent.config.requireAttachmentDescriptions { - return draft.attachments.allSatisfy { - !$0.attachmentDescription.isEmpty + if draft.attachments.isEmpty { + return false + } else { + return !parent.attachmentsMissingDescriptions.isEmpty } } else { return false } } - private var validAttachmentCombination: Bool { + var validAttachmentCombination: Bool { if !parent.mastodonController.instanceFeatures.mastodonAttachmentRestrictions { return true } else if draft.attachments.contains(where: { $0.data.type == .video }) && @@ -139,6 +141,13 @@ class AttachmentsListController: ViewController { .onDrag { NSItemProvider(object: attachment) } + .onReceive(attachment.$attachmentDescription.map(\.isEmpty).removeDuplicates()) { isEmpty in + if isEmpty { + controller.parent.attachmentsMissingDescriptions.insert(attachment.id) + } else { + controller.parent.attachmentsMissingDescriptions.remove(attachment.id) + } + } } .onMove(perform: controller.moveAttachments) .onDelete(perform: controller.deleteAttachments) diff --git a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift index df2db56331..00a946d265 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/ComposeController.swift @@ -32,6 +32,9 @@ public final class ComposeController: ViewController { @Published var toolbarController: ToolbarController! @Published var attachmentsListController: AttachmentsListController! + // this property is here rather than on the AttachmentsListController so that the ComposeView + // updates when it changes, because changes to it may alter postButtonEnabled + @Published var attachmentsMissingDescriptions = Set() @Published var contentWarningBecomeFirstResponder = false @Published var mainComposeTextViewBecomeFirstResponder = false @Published var currentInput: (any ComposeInput)? = nil