From e650cffde7351524c52e0af8dc05b77f5c43125f Mon Sep 17 00:00:00 2001 From: James Magahern Date: Thu, 25 Sep 2025 00:20:19 -0700 Subject: [PATCH] osx: mark as read when hovering over window --- osx/kordophone2/ConversationView.swift | 5 +++++ .../Transcript/TranscriptView.swift | 20 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/osx/kordophone2/ConversationView.swift b/osx/kordophone2/ConversationView.swift index 5a8887d..47328cb 100644 --- a/osx/kordophone2/ConversationView.swift +++ b/osx/kordophone2/ConversationView.swift @@ -23,5 +23,10 @@ struct ConversationView: View entryModel.handleDroppedProviders(providers) return true } + + .onHover { isHovering in + guard isHovering else { return } + transcriptModel.setNeedsMarkAsRead() + } } } diff --git a/osx/kordophone2/Transcript/TranscriptView.swift b/osx/kordophone2/Transcript/TranscriptView.swift index 8514e08..27db24c 100644 --- a/osx/kordophone2/Transcript/TranscriptView.swift +++ b/osx/kordophone2/Transcript/TranscriptView.swift @@ -126,11 +126,14 @@ struct TranscriptView: View { var displayItems: [DisplayItem] = [] var displayedConversation: Display.Conversation? = nil - + internal var needsReload: NeedsReload = .no internal var messages: [Display.Message] internal let client = XPCClient() + private var needsMarkAsRead: Bool = false + private var lastMarkAsRead: Date = .now + init(messages: [Display.Message] = []) { self.messages = messages rebuildDisplayItems() @@ -147,7 +150,20 @@ struct TranscriptView: View await reloadIfNeeded() } } - + + func setNeedsMarkAsRead() { + guard needsMarkAsRead == false else { return } + guard Date.now.timeIntervalSince(lastMarkAsRead) > 5.0 else { return } + + needsMarkAsRead = true + Task { @MainActor [weak self] in + guard let self else { return } + await markAsRead() + needsMarkAsRead = false + lastMarkAsRead = .now + } + } + func attachmentDownloaded(id: String) { // TODO: should be smarter here setNeedsReload(animated: false)