commit 4b426b9

delthas  ·  2026-05-14 12:02:37 +0000 UTC
parent f7fd540
Support draft/chathistory-end tag for end-of-history detection
3 files changed,  +14, -9
M app.go
M app.go
+11, -8
 1@@ -1850,14 +1850,17 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 2 		if !boundsNew.IsZero() {
 3 			app.messageBounds[bk] = boundsNew
 4 		}
 5-		if len(ev.Messages) < 10 {
 6-			// We're getting a non-full page: mark as complete to avoid indefinitely fetching the history.
 7-			// This should ideally be equal to the CHATHISTORY LIMIT, but it can be non advertised, or
 8-			// a full page could sometimes be less than a limit (because it could be filtered).
 9-			// It is also not zero, because bounds are inclusive, and not one, because we truncate based on
10-			// the second of the message (because some bouncers have a second-level resolution).
11-			// Be safe and pick 10 messages: less messages means that this was not a full page and we are done
12-			// with fetching the backlog.
13+		if len(ev.Messages) < 10 || ev.End {
14+			// We're getting a non-full page, or the server told us via the draft/chathistory-end tag
15+			// that this is the end of available history: mark as complete to avoid indefinitely
16+			// fetching the history.
17+			// The < 10 heuristic remains for servers that don't yet emit the tag. It should ideally
18+			// be equal to the CHATHISTORY LIMIT, but it can be non advertised, or a full page could
19+			// sometimes be less than a limit (because it could be filtered). It is also not zero,
20+			// because bounds are inclusive, and not one, because we truncate based on the second of
21+			// the message (because some bouncers have a second-level resolution). Be safe and pick
22+			// 10 messages: less messages means that this was not a full page and we are done with
23+			// fetching the backlog.
24 			b := app.messageBounds[bk]
25 			b.complete = true
26 			app.messageBounds[bk] = b
+1, -0
1@@ -104,6 +104,7 @@ type ListEvent []ListItem
2 type HistoryEvent struct {
3 	Target   string
4 	Messages []Event
5+	End      bool
6 }
7 
8 type HistoryTargetsEvent struct {
+2, -1
 1@@ -1460,7 +1460,8 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er
 2 					return nil, err
 3 				}
 4 
 5-				s.chBatches[id] = HistoryEvent{Target: target}
 6+				_, end := msg.Tags["draft/chathistory-end"]
 7+				s.chBatches[id] = HistoryEvent{Target: target, End: end}
 8 			case "draft/chathistory-targets":
 9 				s.targetsBatchID = id
10 				s.targetsBatch = HistoryTargetsEvent{Targets: make(map[string]time.Time)}