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)