From 5eac9a9080fe2ff6e0e535feaf090424d7295f85 Mon Sep 17 00:00:00 2001 From: Sean Coates Date: Sun, 31 May 2026 23:09:51 -0400 Subject: [PATCH] only mark room read when app is active --- Mactrix/Views/ChatView/ChatView.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Mactrix/Views/ChatView/ChatView.swift b/Mactrix/Views/ChatView/ChatView.swift index 084c1fe..6cfd77d 100644 --- a/Mactrix/Views/ChatView/ChatView.swift +++ b/Mactrix/Views/ChatView/ChatView.swift @@ -22,8 +22,14 @@ struct TimelineGroupView: View { } } +private struct TimelineReadKey: Equatable { + let count: Int + let active: Bool +} + struct ChatJoinedRoom: View { @Environment(AppState.self) private var appState + @Environment(\.appearsActive) private var appearsActive @Bindable var timeline: LiveTimeline var room: LiveRoom { @@ -57,10 +63,10 @@ struct ChatJoinedRoom: View { Logger.viewCycle.error("failed to mark room as recently visited: \(error)") } } - .task(id: timeline.timelineItems.count, priority: .background) { + .task(id: TimelineReadKey(count: timeline.timelineItems.count, active: appearsActive), priority: .background) { + guard appearsActive else { return } do { try await Task.sleep(for: .seconds(1)) - Logger.viewCycle.debug("Mark room as read") try await timeline.timeline?.markAsRead(receiptType: .read) } catch is CancellationError {