From be255ff53b504dbf2efd8f667f53dd1298d99b86 Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 17 Nov 2022 20:41:55 +0800 Subject: [PATCH] fix: compose content could not post media only issue --- .../ComposeContentViewModel.swift | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift index 06d84566b..61ccd9e3a 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift @@ -359,7 +359,7 @@ extension ComposeContentViewModel { let isMediaUploadAllSuccess = $attachmentViewModels .map { attachmentViewModels in 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 } } } .switchToLatest() @@ -367,18 +367,20 @@ extension ComposeContentViewModel { guard outputs.allSatisfy({ $0 == .finish }) else { return false } return true } + .prepend(true) let isPollOptionsAllValid = $pollOptions .map { options in 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 } } } .switchToLatest() .map { outputs in return outputs.allSatisfy { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } } - + .prepend(true) + let isPublishBarButtonItemEnabledPrecondition1 = Publishers.CombineLatest4( isComposeContentEmpty, isComposeContentValid, @@ -394,17 +396,15 @@ extension ComposeContentViewModel { } .eraseToAnyPublisher() - let isPublishBarButtonItemEnabledPrecondition2 = Publishers.CombineLatest4( - isComposeContentEmpty, - isComposeContentValid, + let isPublishBarButtonItemEnabledPrecondition2 = Publishers.CombineLatest( $isPollActive, isPollOptionsAllValid ) - .map { isComposeContentEmpty, isComposeContentValid, isPollComposing, isPollOptionsAllValid -> Bool in - if isPollComposing { - return isComposeContentValid && !isComposeContentEmpty && isPollOptionsAllValid + .map { isPollActive, isPollOptionsAllValid -> Bool in + if isPollActive { + return isPollOptionsAllValid } else { - return isComposeContentValid && !isComposeContentEmpty + return true } } .eraseToAnyPublisher()