From 5dc0cb0cc583d989806c68694410d76fd05d07c7 Mon Sep 17 00:00:00 2001 From: CMK Date: Wed, 30 Jun 2021 16:14:01 +0800 Subject: [PATCH] fix: post attachment task not trigger on queue issue --- Mastodon/Scene/Compose/ComposeViewModel.swift | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/Mastodon/Scene/Compose/ComposeViewModel.swift b/Mastodon/Scene/Compose/ComposeViewModel.swift index 68880e81..15dd0ef3 100644 --- a/Mastodon/Scene/Compose/ComposeViewModel.swift +++ b/Mastodon/Scene/Compose/ComposeViewModel.swift @@ -292,33 +292,32 @@ final class ComposeViewModel: NSObject { .store(in: &disposeBag) // setup attribute updater - Publishers.CombineLatest( - attachmentServices, - context.timestampUpdatePublisher - ) - .sink { attachmentServices, _ in - // drive service upload state - // make image upload in the queue - for attachmentService in attachmentServices { - // skip when prefix N task when task finish OR fail OR uploading - guard let currentState = attachmentService.uploadStateMachine.currentState else { break } - if currentState is MastodonAttachmentService.UploadState.Fail { - continue - } - if currentState is MastodonAttachmentService.UploadState.Finish { - continue - } - if currentState is MastodonAttachmentService.UploadState.Uploading { - break - } - // trigger uploading one by one - if currentState is MastodonAttachmentService.UploadState.Initial { - attachmentService.uploadStateMachine.enter(MastodonAttachmentService.UploadState.Uploading.self) - break + attachmentServices + .receive(on: DispatchQueue.main) + .debounce(for: 0.3, scheduler: DispatchQueue.main) + .sink { attachmentServices in + // drive service upload state + // make image upload in the queue + for attachmentService in attachmentServices { + // skip when prefix N task when task finish OR fail OR uploading + guard let currentState = attachmentService.uploadStateMachine.currentState else { break } + if currentState is MastodonAttachmentService.UploadState.Fail { + continue + } + if currentState is MastodonAttachmentService.UploadState.Finish { + continue + } + if currentState is MastodonAttachmentService.UploadState.Uploading { + break + } + // trigger uploading one by one + if currentState is MastodonAttachmentService.UploadState.Initial { + attachmentService.uploadStateMachine.enter(MastodonAttachmentService.UploadState.Uploading.self) + break + } } } - } - .store(in: &disposeBag) + .store(in: &disposeBag) // bind delegate attachmentServices