From 5c8aaed54c500403cdb7f348ba92d796c3ab52a9 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 25 Jul 2020 12:46:33 -0500 Subject: [PATCH] Reenabled mac toolbar validation --- Multiplatform/Shared/SceneModel.swift | 39 ++++++++++++------- .../Shared/Timeline/TimelineModel.swift | 8 ++++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Multiplatform/Shared/SceneModel.swift b/Multiplatform/Shared/SceneModel.swift index aa3690f98..3e221caa3 100644 --- a/Multiplatform/Shared/SceneModel.swift +++ b/Multiplatform/Shared/SceneModel.swift @@ -128,20 +128,31 @@ private extension SceneModel { // MARK: Subscriptions func subscribeToToolbarChangeEvents() { -// NotificationCenter.default.publisher(for: .UnreadCountDidChange) -// .compactMap { $0.object as? AccountManager } -// .sink { [weak self] accountManager in -// self?.updateNextUnreadButtonState(accountManager: accountManager) -// }.store(in: &cancellables) -// -// let blankNotification = Notification(name: .StatusesDidChange) -// let statusesDidChangePublisher = NotificationCenter.default.publisher(for: .StatusesDidChange).prepend(blankNotification) -// let combinedPublisher = timelineModel.$articles.combineLatest(timelineModel.$selectedArticles, statusesDidChangePublisher) -// -// combinedPublisher.sink { [weak self] (articles, selectedArticles, _) in -// self?.updateMarkAllAsReadButtonsState(articles: articles) -// self?.updateArticleButtonsState(selectedArticles: selectedArticles) -// }.store(in: &cancellables) + guard let selectedArticlesPublisher = timelineModel.selectedArticlesPublisher, + let articlesPublisher = timelineModel.articlesPublisher else { return } + + NotificationCenter.default.publisher(for: .UnreadCountDidChange) + .compactMap { $0.object as? AccountManager } + .sink { [weak self] accountManager in + self?.updateNextUnreadButtonState(accountManager: accountManager) + }.store(in: &cancellables) + + let blankNotification = Notification(name: .StatusesDidChange) + let statusesDidChangePublisher = NotificationCenter.default.publisher(for: .StatusesDidChange).prepend(blankNotification) + + statusesDidChangePublisher + .combineLatest(selectedArticlesPublisher) + .sink { [weak self] _, selectedArticles in + self?.updateArticleButtonsState(selectedArticles: selectedArticles) + } + .store(in: &cancellables) + + statusesDidChangePublisher + .combineLatest(articlesPublisher) + .sink { [weak self] _, articles in + self?.updateMarkAllAsReadButtonsState(articles: articles) + } + .store(in: &cancellables) } func subscribeToAccountSyncErrors() { diff --git a/Multiplatform/Shared/Timeline/TimelineModel.swift b/Multiplatform/Shared/Timeline/TimelineModel.swift index 085c7e89a..78e6d3285 100644 --- a/Multiplatform/Shared/Timeline/TimelineModel.swift +++ b/Multiplatform/Shared/Timeline/TimelineModel.swift @@ -31,6 +31,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner { @Published var isReadFiltered: Bool? = nil var timelineItemsPublisher: AnyPublisher, Never>? + var articlesPublisher: AnyPublisher<[Article], Never>? var selectedTimelineItemsPublisher: AnyPublisher<[TimelineItem], Never>? var selectedArticlesPublisher: AnyPublisher<[Article], Never>? @@ -80,6 +81,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner { // }.store(in: &cancellables) // } + // TODO: Don't forget to redo this!!! func subscribeToReadFilterChanges() { guard let selectedFeedsPublisher = delegate?.selectedFeedsPublisher else { return } @@ -132,6 +134,12 @@ class TimelineModel: ObservableObject, UndoableCommandRunner { .share(replay: 1) .eraseToAnyPublisher() + articlesPublisher = timelineItemsPublisher! + .map { timelineItems in + timelineItems.values.values.map { $0.article } + } + .eraseToAnyPublisher() + // Set the timeline name for display selectedFeedsPublisher .map { feeds -> String in