From 9a26df89d1288b82709e2f3de357d86ba8c9e1c5 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 21 Jun 2024 18:09:28 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20bug=20where=20sidebar=20unread=20count=20?= =?UTF-8?q?view=20would=20flicker=20as=20the=20timeline=20view=20controlle?= =?UTF-8?q?r=20unreadCount=20would=20be=20briefly=200=20when=20it=E2=80=99?= =?UTF-8?q?s=20updating=20its=20unread=20count.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mac/MainWindow/Sidebar/SidebarViewController.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index 81945f4f6..c2328d7da 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -815,14 +815,18 @@ private extension SidebarViewController { // then the unread count comes from the timeline. // This ensures that any transients in the timeline // are accounted for in the unread count. - if nodeShouldGetUnreadCountFromTimeline(node) { - return delegate?.unreadCount(for: node.representedObject) ?? 0 + + var count = 0 + if let unreadCountProvider = node.representedObject as? UnreadCountProvider { + count = unreadCountProvider.unreadCount } - if let unreadCountProvider = node.representedObject as? UnreadCountProvider { - return unreadCountProvider.unreadCount + if nodeShouldGetUnreadCountFromTimeline(node) { + let timelineUnreadCount = delegate?.unreadCount(for: node.representedObject) ?? 0 + return max(count, timelineUnreadCount) // timelineUnreadCount may include additional transients } - return 0 + + return count } func nodeShouldGetUnreadCountFromTimeline(_ node: Node) -> Bool {