From 8fc6e81ddf1ebb2d5f13237801532532b3e5f906 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 29 May 2019 10:24:30 -0500 Subject: [PATCH] Update the Today timeline and unread count when the day changes. Issue #627 --- Mac/MainWindow/Sidebar/SidebarViewController.swift | 7 +++++++ .../Timeline/TimelineViewController.swift | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index cb890af36..c206be8aa 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -60,6 +60,7 @@ protocol SidebarDelegate: class { NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(userDidRequestSidebarSelection(_:)), name: .UserDidRequestSidebarSelection, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(calendarDayChanged(_:)), name: .NSCalendarDayChanged, object: nil) outlineView.reloadData() @@ -165,6 +166,12 @@ protocol SidebarDelegate: class { revealAndSelectRepresentedObject(feed as AnyObject) } + @objc func calendarDayChanged(_ note: Notification) { + DispatchQueue.main.async { + SmartFeedsController.shared.todayFeed.fetchUnreadCounts() + } + } + // MARK: - Actions @IBAction func delete(_ sender: AnyObject?) { diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 1aa349a86..3a2ca3ea9 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -147,6 +147,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner { NotificationCenter.default.addObserver(self, selector: #selector(accountStateDidChange(_:)), name: .AccountStateDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange(_:)), name: .AccountsDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(calendarDayChanged(_:)), name: .NSCalendarDayChanged, object: nil) didRegisterForNotifications = true } @@ -511,6 +512,14 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner { self.fontSize = AppDefaults.timelineFontSize self.sortDirection = AppDefaults.timelineSortDirection } + + @objc func calendarDayChanged(_ note: Notification) { + if representedObjectsContainsTodayFeed() { + DispatchQueue.main.async { [weak self] in + self?.fetchArticles() + } + } + } // MARK: - Reloading Data @@ -966,6 +975,10 @@ private extension TimelineViewController { return representedObjects?.contains(where: { $0 is PseudoFeed}) ?? false } + func representedObjectsContainsTodayFeed() -> Bool { + return representedObjects?.contains(where: { $0 === SmartFeedsController.shared.todayFeed }) ?? false + } + func representedObjectsContainsAnyFeed(_ feeds: Set) -> Bool { // Return true if there’s a match or if a folder contains (recursively) one of feeds