From e4a2fe26415eba5cf7920c08acd0313b1c75d1f4 Mon Sep 17 00:00:00 2001 From: delthas Date: Tue, 18 Oct 2022 17:27:20 +0200 Subject: Clear highlights from MARKREAD when only NotifyNone lines are left Previously, we did not clear buffers highlight statuses on MARKREAD if there was any unread line after it. This meant that if we received a plain message, than a join message, and some other device sent us a read marker for the plain message, we would still highlight the buffer. But we should not: a join message should not highlight the buffer. This is a recurrent use case because some clients do not display join mesasges and therefore do not send read markers for it. This updates the logic to actually store the notify level (in the line) and uses it to reset the highlight status when only NotifyNone messages (or no messages) are left. --- ui/buffers.go | 22 ++++++++++++++-------- ui/ui.go | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'ui') diff --git a/ui/buffers.go b/ui/buffers.go index 0e398de..b11e734 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -33,6 +33,7 @@ type Line struct { Head string Body StyledString HeadColor tcell.Color + Notify NotifyType Highlight bool Readable bool Mergeable bool @@ -366,7 +367,7 @@ func (bs *BufferList) mergeLine(former *Line, addition Line) (keepLine bool) { return true } -func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line) { +func (bs *BufferList) AddLine(netID, title string, line Line) { _, b := bs.at(netID, title) if b == nil { return @@ -394,10 +395,10 @@ func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line) } } - if notify != NotifyNone && b != current { + if line.Notify != NotifyNone && b != current { b.unread = true } - if notify == NotifyHighlight && b != current { + if line.Notify == NotifyHighlight && b != current { b.highlights++ } } @@ -443,16 +444,21 @@ func (bs *BufferList) SetRead(netID, title string, timestamp time.Time) { if b == nil { return } + clearRead := true for i := len(b.lines) - 1; i >= 0; i-- { line := &b.lines[i] - if line.Readable { - if !line.At.After(timestamp) { - b.highlights = 0 - b.unread = false - } + if !line.At.After(timestamp) { + break + } + if line.Readable && line.Notify != NotifyNone { + clearRead = false break } } + if clearRead { + b.highlights = 0 + b.unread = false + } if b.read.Before(timestamp) { b.read = timestamp } diff --git a/ui/ui.go b/ui/ui.go index 1a0da91..859f32a 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -270,8 +270,8 @@ func (ui *UI) RemoveNetworkBuffers(netID string) { ui.memberOffset = 0 } -func (ui *UI) AddLine(netID, buffer string, notify NotifyType, line Line) { - ui.bs.AddLine(netID, buffer, notify, line) +func (ui *UI) AddLine(netID, buffer string, line Line) { + ui.bs.AddLine(netID, buffer, line) } func (ui *UI) AddLines(netID, buffer string, before, after []Line) { -- cgit v1.2.3