commit dc01205
Hubert Hirtz
·
2021-09-03 09:22:04 +0000 UTC
parent 328a23e
Use messageBounds for infinite scroll CHATHISTORY requests
3 files changed,
+7,
-18
M
app.go
+7,
-5
1@@ -51,10 +51,13 @@ func (b *bound) Compare(line *ui.Line) int {
2
3 // Update updates the bounds to include the given line.
4 func (b *bound) Update(line *ui.Line) {
5- if line.At.Before(b.first) {
6+ if line.At.IsZero() {
7+ return
8+ }
9+ if b.first.IsZero() || line.At.Before(b.first) {
10 b.first = line.At
11 b.firstMessage = line.Body.String()
12- } else if line.At.After(b.last) {
13+ } else if b.last.IsZero() || line.At.After(b.last) {
14 b.last = line.At
15 b.lastMessage = line.Body.String()
16 }
17@@ -340,7 +343,6 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
18 // TODO scroll chan list
19 } else if x > w-app.cfg.MemberColWidth {
20 app.win.ScrollMemberUpBy(4)
21- app.requestHistory()
22 } else {
23 app.win.ScrollUpBy(4)
24 app.requestHistory()
25@@ -480,8 +482,8 @@ func (app *App) requestHistory() {
26 buffer := app.win.CurrentBuffer()
27 if app.win.IsAtTop() && buffer != Home {
28 t := time.Now()
29- if oldest := app.win.CurrentBufferOldestTime(); oldest != nil {
30- t = *oldest
31+ if bound, ok := app.messageBounds[buffer]; ok {
32+ t = bound.first
33 }
34 app.s.NewHistoryRequest(buffer).
35 WithLimit(100).
+0,
-8
1@@ -319,14 +319,6 @@ func (bs *BufferList) Current() (title string) {
2 return bs.list[bs.current].title
3 }
4
5-func (bs *BufferList) CurrentOldestTime() (t *time.Time) {
6- ls := bs.list[bs.current].lines
7- if 0 < len(ls) {
8- t = &ls[0].At
9- }
10- return t
11-}
12-
13 func (bs *BufferList) ScrollUp(n int) {
14 b := &bs.list[bs.current]
15 if b.isAtTop {
M
ui/ui.go
+0,
-5
1@@ -3,7 +3,6 @@ package ui
2 import (
3 "strings"
4 "sync/atomic"
5- "time"
6
7 "git.sr.ht/~taiite/senpai/irc"
8
9@@ -87,10 +86,6 @@ func (ui *UI) CurrentBuffer() string {
10 return ui.bs.Current()
11 }
12
13-func (ui *UI) CurrentBufferOldestTime() (t *time.Time) {
14- return ui.bs.CurrentOldestTime()
15-}
16-
17 func (ui *UI) NextBuffer() {
18 ui.bs.Next()
19 ui.memberOffset = 0