commit c86a2fa

delthas  ·  2022-04-15 12:55:18 +0000 UTC
parent 7a86dff
Only send READ for messages received from a channel

i.e. don't enter an infinite loop when printing disconnection errors :-)
2 files changed,  +20, -4
M app.go
M app.go
+9, -0
 1@@ -705,6 +705,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 2 			HeadColor: tcell.ColorGray,
 3 			Body:      body.StyledString(),
 4 			Highlight: true,
 5+			Readable:  true,
 6 		})
 7 	case irc.UserNickEvent:
 8 		line := app.formatEvent(ev)
 9@@ -782,6 +783,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
10 			HeadColor: tcell.ColorGray,
11 			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)),
12 			Highlight: notify == ui.NotifyHighlight,
13+			Readable:  true,
14 		})
15 	case irc.MessageEvent:
16 		buffer, line, notification := app.formatMessage(s, ev)
17@@ -1044,6 +1046,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
18 			Body:      body.StyledString(),
19 			Mergeable: true,
20 			Data:      []irc.Event{ev},
21+			Readable:  true,
22 		}
23 	case irc.UserJoinEvent:
24 		var body ui.StyledStringBuilder
25@@ -1059,6 +1062,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
26 			Body:      body.StyledString(),
27 			Mergeable: true,
28 			Data:      []irc.Event{ev},
29+			Readable:  true,
30 		}
31 	case irc.UserPartEvent:
32 		var body ui.StyledStringBuilder
33@@ -1074,6 +1078,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
34 			Body:      body.StyledString(),
35 			Mergeable: true,
36 			Data:      []irc.Event{ev},
37+			Readable:  true,
38 		}
39 	case irc.UserQuitEvent:
40 		var body ui.StyledStringBuilder
41@@ -1089,6 +1094,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
42 			Body:      body.StyledString(),
43 			Mergeable: true,
44 			Data:      []irc.Event{ev},
45+			Readable:  true,
46 		}
47 	case irc.TopicChangeEvent:
48 		topic := ui.IRCString(ev.Topic).String()
49@@ -1098,6 +1104,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
50 			Head:      "--",
51 			HeadColor: tcell.ColorGray,
52 			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)),
53+			Readable:  true,
54 		}
55 	case irc.ModeChangeEvent:
56 		body := fmt.Sprintf("[%s]", ev.Mode)
57@@ -1110,6 +1117,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
58 			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)),
59 			Mergeable: mergeable,
60 			Data:      []irc.Event{ev},
61+			Readable:  true,
62 		}
63 	default:
64 		return ui.Line{}
65@@ -1189,6 +1197,7 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
66 		HeadColor: headColor,
67 		Body:      body.StyledString(),
68 		Highlight: hlLine,
69+		Readable:  true,
70 	}
71 	return
72 }
+11, -4
 1@@ -34,6 +34,7 @@ type Line struct {
 2 	Body      StyledString
 3 	HeadColor tcell.Color
 4 	Highlight bool
 5+	Readable  bool
 6 	Mergeable bool
 7 	Data      interface{}
 8 
 9@@ -420,9 +421,15 @@ func (bs *BufferList) SetRead(netID, title string, timestamp time.Time) {
10 	if b == nil {
11 		return
12 	}
13-	if len(b.lines) > 0 && !b.lines[len(b.lines)-1].At.After(timestamp) {
14-		b.highlights = 0
15-		b.unread = false
16+	for i := len(b.lines) - 1; i >= 0; i-- {
17+		line := &b.lines[i]
18+		if line.Readable {
19+			if line.At.After(timestamp) {
20+				b.highlights = 0
21+				b.unread = false
22+			}
23+			break
24+		}
25 	}
26 	if b.read.Before(timestamp) {
27 		b.read = timestamp
28@@ -435,7 +442,7 @@ func (bs *BufferList) UpdateRead() (netID, title string, timestamp time.Time) {
29 	y := 0
30 	for i := len(b.lines) - 1; 0 <= i; i-- {
31 		line = &b.lines[i]
32-		if y >= b.scrollAmt {
33+		if y >= b.scrollAmt && line.Readable {
34 			break
35 		}
36 		y += len(line.NewLines(bs.tlInnerWidth)) + 1