commit ae62bb9
delthas
·
2025-03-11 23:19:16 +0000 UTC
parent 19a962c
Fix chat history fetch loop for targets containing uppercase chars We would previously flood the server with CHATHISTORY BEFORE on channels with mixed case.
1 files changed,
+16,
-12
M
app.go
M
app.go
+16,
-12
1@@ -1221,16 +1221,17 @@ func (app *App) maybeRequestHistory() {
2 return
3 }
4 netID, buffer := app.win.CurrentBuffer()
5- if app.messageBounds[boundKey{netID, buffer}].complete {
6- return
7- }
8 s := app.sessions[netID]
9 if s == nil {
10 return
11 }
12+ bk := boundKey{netID, s.Casemap(buffer)}
13+ if app.messageBounds[bk].complete {
14+ return
15+ }
16 _, h := app.win.Size()
17 if l := app.win.LinesAboveOffset(); l < h*2 && buffer != "" {
18- if bound, ok := app.messageBounds[boundKey{netID, buffer}]; ok {
19+ if bound, ok := app.messageBounds[bk]; ok {
20 s.NewHistoryRequest(buffer).
21 WithLimit(200).
22 Before(bound.first)
23@@ -1393,7 +1394,8 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
24 if !ev.Read.IsZero() {
25 app.win.SetRead(netID, ev.Channel, ev.Read)
26 }
27- bounds, ok := app.messageBounds[boundKey{netID, ev.Channel}]
28+ bk := boundKey{netID, s.Casemap(ev.Channel)}
29+ bounds, ok := app.messageBounds[bk]
30 if added || !ok {
31 if t, ok := msg.Time(); ok {
32 s.NewHistoryRequest(ev.Channel).
33@@ -1434,7 +1436,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
34 app.win.AddLine(netID, ev.Channel, line)
35 case irc.SelfPartEvent:
36 app.win.RemoveBuffer(netID, ev.Channel)
37- delete(app.messageBounds, boundKey{netID, ev.Channel})
38+ delete(app.messageBounds, boundKey{netID, s.Casemap(ev.Channel)})
39 case irc.UserPartEvent:
40 if !app.cfg.StatusEnabled {
41 break
42@@ -1519,9 +1521,10 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
43 app.lastQuery = msg.Prefix.Name
44 app.lastQueryNet = netID
45 }
46- bounds := app.messageBounds[boundKey{netID, buffer}]
47+ bk := boundKey{netID, s.Casemap(buffer)}
48+ bounds := app.messageBounds[bk]
49 bounds.Update(&line)
50- app.messageBounds[boundKey{netID, buffer}] = bounds
51+ app.messageBounds[bk] = bounds
52 case irc.HistoryTargetsEvent:
53 type target struct {
54 name string
55@@ -1555,7 +1558,8 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
56 case irc.HistoryEvent:
57 var linesBefore []ui.Line
58 var linesAfter []ui.Line
59- bounds, hasBounds := app.messageBounds[boundKey{netID, ev.Target}]
60+ bk := boundKey{netID, s.Casemap(ev.Target)}
61+ bounds, hasBounds := app.messageBounds[bk]
62 boundsNew := bounds
63 for _, m := range ev.Messages {
64 var line ui.Line
65@@ -1586,7 +1590,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
66 app.win.AddLines(netID, ev.Target, linesBefore, linesAfter)
67
68 if !boundsNew.IsZero() {
69- app.messageBounds[boundKey{netID, ev.Target}] = boundsNew
70+ app.messageBounds[bk] = boundsNew
71 }
72 if len(ev.Messages) < 10 {
73 // We're getting a non-full page: mark as complete to avoid indefinitely fetching the history.
74@@ -1596,9 +1600,9 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
75 // the second of the message (because some bouncers have a second-level resolution).
76 // Be safe and pick 10 messages: less messages means that this was not a full page and we are done
77 // with fetching the backlog.
78- b := app.messageBounds[boundKey{netID, ev.Target}]
79+ b := app.messageBounds[bk]
80 b.complete = true
81- app.messageBounds[boundKey{netID, ev.Target}] = b
82+ app.messageBounds[bk] = b
83 }
84 case irc.SearchEvent:
85 app.win.OpenOverlay("Press Escape to close the search results")