Merge pull request #618 from mastodon/fix-compose-content-validate

Fix compose content could not post media only issue
This commit is contained in:
Marcus Kida 2022-11-17 13:53:48 +01:00 committed by GitHub
commit d93d094734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 10 deletions

View File

@ -359,7 +359,7 @@ extension ComposeContentViewModel {
let isMediaUploadAllSuccess = $attachmentViewModels let isMediaUploadAllSuccess = $attachmentViewModels
.map { attachmentViewModels in .map { attachmentViewModels in
return Publishers.MergeMany(attachmentViewModels.map { $0.$uploadState }) return Publishers.MergeMany(attachmentViewModels.map { $0.$uploadState })
.delay(for: 0.5, scheduler: DispatchQueue.main) // convert to outputs with delay. Due to @Published emit before changes .delay(for: 0.3, scheduler: DispatchQueue.main) // convert to outputs with delay. Due to @Published emit before changes
.map { _ in attachmentViewModels.map { $0.uploadState } } .map { _ in attachmentViewModels.map { $0.uploadState } }
} }
.switchToLatest() .switchToLatest()
@ -367,17 +367,19 @@ extension ComposeContentViewModel {
guard outputs.allSatisfy({ $0 == .finish }) else { return false } guard outputs.allSatisfy({ $0 == .finish }) else { return false }
return true return true
} }
.prepend(true)
let isPollOptionsAllValid = $pollOptions let isPollOptionsAllValid = $pollOptions
.map { options in .map { options in
return Publishers.MergeMany(options.map { $0.$text }) return Publishers.MergeMany(options.map { $0.$text })
.delay(for: 0.5, scheduler: DispatchQueue.main) // convert to outputs with delay. Due to @Published emit before changes .delay(for: 0.3, scheduler: DispatchQueue.main) // convert to outputs with delay. Due to @Published emit before changes
.map { _ in options.map { $0.text } } .map { _ in options.map { $0.text } }
} }
.switchToLatest() .switchToLatest()
.map { outputs in .map { outputs in
return outputs.allSatisfy { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } return outputs.allSatisfy { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
} }
.prepend(true)
let isPublishBarButtonItemEnabledPrecondition1 = Publishers.CombineLatest4( let isPublishBarButtonItemEnabledPrecondition1 = Publishers.CombineLatest4(
isComposeContentEmpty, isComposeContentEmpty,
@ -394,17 +396,15 @@ extension ComposeContentViewModel {
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()
let isPublishBarButtonItemEnabledPrecondition2 = Publishers.CombineLatest4( let isPublishBarButtonItemEnabledPrecondition2 = Publishers.CombineLatest(
isComposeContentEmpty,
isComposeContentValid,
$isPollActive, $isPollActive,
isPollOptionsAllValid isPollOptionsAllValid
) )
.map { isComposeContentEmpty, isComposeContentValid, isPollComposing, isPollOptionsAllValid -> Bool in .map { isPollActive, isPollOptionsAllValid -> Bool in
if isPollComposing { if isPollActive {
return isComposeContentValid && !isComposeContentEmpty && isPollOptionsAllValid return isPollOptionsAllValid
} else { } else {
return isComposeContentValid && !isComposeContentEmpty return true
} }
} }
.eraseToAnyPublisher() .eraseToAnyPublisher()