diff options
author | delthas <delthas@dille.cc> | 2022-04-15 14:55:18 +0200 |
---|---|---|
committer | delthas <delthas@dille.cc> | 2022-04-15 14:55:18 +0200 |
commit | c86a2fae090aeb59620efb7996c4c6739601d63f (patch) | |
tree | a4ab3687a749ea6a077702d337b7b7601275da4f | |
parent | Implement SEARCH (diff) |
Only send READ for messages received from a channel
i.e. don't enter an infinite loop when printing disconnection errors :-)
-rw-r--r-- | app.go | 9 | ||||
-rw-r--r-- | ui/buffers.go | 15 |
2 files changed, 20 insertions, 4 deletions
@@ -705,6 +705,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) { HeadColor: tcell.ColorGray, Body: body.StyledString(), Highlight: true, + Readable: true, }) case irc.UserNickEvent: line := app.formatEvent(ev) @@ -782,6 +783,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) { HeadColor: tcell.ColorGray, Body: ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)), Highlight: notify == ui.NotifyHighlight, + Readable: true, }) case irc.MessageEvent: buffer, line, notification := app.formatMessage(s, ev) @@ -1044,6 +1046,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line { Body: body.StyledString(), Mergeable: true, Data: []irc.Event{ev}, + Readable: true, } case irc.UserJoinEvent: var body ui.StyledStringBuilder @@ -1059,6 +1062,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line { Body: body.StyledString(), Mergeable: true, Data: []irc.Event{ev}, + Readable: true, } case irc.UserPartEvent: var body ui.StyledStringBuilder @@ -1074,6 +1078,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line { Body: body.StyledString(), Mergeable: true, Data: []irc.Event{ev}, + Readable: true, } case irc.UserQuitEvent: var body ui.StyledStringBuilder @@ -1089,6 +1094,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line { Body: body.StyledString(), Mergeable: true, Data: []irc.Event{ev}, + Readable: true, } case irc.TopicChangeEvent: topic := ui.IRCString(ev.Topic).String() @@ -1098,6 +1104,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line { Head: "--", HeadColor: tcell.ColorGray, Body: ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)), + Readable: true, } case irc.ModeChangeEvent: body := fmt.Sprintf("[%s]", ev.Mode) @@ -1110,6 +1117,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line { Body: ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)), Mergeable: mergeable, Data: []irc.Event{ev}, + Readable: true, } default: return ui.Line{} @@ -1189,6 +1197,7 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin HeadColor: headColor, Body: body.StyledString(), Highlight: hlLine, + Readable: true, } return } diff --git a/ui/buffers.go b/ui/buffers.go index 5ed3414..69d1aa0 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -34,6 +34,7 @@ type Line struct { Body StyledString HeadColor tcell.Color Highlight bool + Readable bool Mergeable bool Data interface{} @@ -420,9 +421,15 @@ func (bs *BufferList) SetRead(netID, title string, timestamp time.Time) { if b == nil { return } - if len(b.lines) > 0 && !b.lines[len(b.lines)-1].At.After(timestamp) { - b.highlights = 0 - b.unread = false + 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 + } + break + } } if b.read.Before(timestamp) { b.read = timestamp @@ -435,7 +442,7 @@ func (bs *BufferList) UpdateRead() (netID, title string, timestamp time.Time) { y := 0 for i := len(b.lines) - 1; 0 <= i; i-- { line = &b.lines[i] - if y >= b.scrollAmt { + if y >= b.scrollAmt && line.Readable { break } y += len(line.NewLines(bs.tlInnerWidth)) + 1 |