From e2ff0c8deb251e7c52d416422ca96d1beb5d44fb Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Tue, 28 Nov 2023 15:05:41 +0100 Subject: [PATCH] Remove duplicate publisher (#898) --- ...eTimelineNavigationBarTitleViewModel.swift | 55 +++---------------- 1 file changed, 8 insertions(+), 47 deletions(-) diff --git a/Mastodon/Scene/HomeTimeline/View/HomeTimelineNavigationBarTitleViewModel.swift b/Mastodon/Scene/HomeTimeline/View/HomeTimelineNavigationBarTitleViewModel.swift index 9f736619b..483586d06 100644 --- a/Mastodon/Scene/HomeTimeline/View/HomeTimelineNavigationBarTitleViewModel.swift +++ b/Mastodon/Scene/HomeTimeline/View/HomeTimelineNavigationBarTitleViewModel.swift @@ -20,8 +20,7 @@ final class HomeTimelineNavigationBarTitleViewModel { // input let context: AppContext var networkErrorCount = CurrentValueSubject(0) - var networkErrorPublisher = PassthroughSubject() - + // output let state = CurrentValueSubject(.logo) let hasNewPosts = CurrentValueSubject(false) @@ -32,15 +31,7 @@ final class HomeTimelineNavigationBarTitleViewModel { init(context: AppContext) { self.context = context - - networkErrorPublisher - .receive(on: DispatchQueue.main) - .sink { [weak self] _ in - guard let self = self else { return } - self.networkErrorCount.value = self.networkErrorCount.value + 1 - } - .store(in: &disposeBag) - + networkErrorCount .receive(on: DispatchQueue.main) .map { count in @@ -131,23 +122,18 @@ extension HomeTimelineNavigationBarTitleViewModel { // MARK: - Offline state extension HomeTimelineNavigationBarTitleViewModel { - - func resetOfflineCounterListener() { - networkErrorCount.value = 0 - } - func receiveLoadingStateCompletion(_ completion: Subscribers.Completion) { switch completion { - case .failure: - networkErrorPublisher.send() - case .finished: - resetOfflineCounterListener() + case .failure: + networkErrorCount.value += 1 + case .finished: + networkErrorCount.value = 0 } } - + func handleScrollViewDidScroll(_ scrollView: UIScrollView) { guard hasNewPosts.value else { return } - + let contentOffsetY = scrollView.contentOffset.y let isScrollToTop = contentOffsetY < -scrollView.contentInset.top guard isScrollToTop else { return } @@ -155,28 +141,3 @@ extension HomeTimelineNavigationBarTitleViewModel { } } - -// MARK: Publish post state -//extension HomeTimelineNavigationBarTitleViewModel { -// -// func setupPublishingProgress() { -// let progressUpdatePublisher = Timer.publish(every: 0.016, on: .main, in: .common) // ~ 60FPS -// .autoconnect() -// .share() -// .eraseToAnyPublisher() -// -// publishingProgressSubscription = progressUpdatePublisher -// .map { _ in Float(0) } -// .scan(0.0) { progress, _ -> Float in -// return 0.95 * progress + 0.05 // progress + 0.05 * (1.0 - progress). ~ 1 sec to 0.95 (under 60FPS) -// } -// .subscribe(publishingProgress) -// } -// -// func suspendPublishingProgress() { -// publishingProgressSubscription = nil -// publishingProgress.send(0) -// } -// -//} -