~taiite/senpai

dc01205670a6e5dd5eee54b3e3fd07534926f984 — Hubert Hirtz a month ago 328a23e
Use messageBounds for infinite scroll CHATHISTORY requests
3 files changed, 7 insertions(+), 18 deletions(-)

M app.go
M ui/buffers.go
M ui/ui.go
M app.go => app.go +7 -5
@@ 51,10 51,13 @@ func (b *bound) Compare(line *ui.Line) int {

// Update updates the bounds to include the given line.
func (b *bound) Update(line *ui.Line) {
	if line.At.Before(b.first) {
	if line.At.IsZero() {
		return
	}
	if b.first.IsZero() || line.At.Before(b.first) {
		b.first = line.At
		b.firstMessage = line.Body.String()
	} else if line.At.After(b.last) {
	} else if b.last.IsZero() || line.At.After(b.last) {
		b.last = line.At
		b.lastMessage = line.Body.String()
	}


@@ 340,7 343,6 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
			// TODO scroll chan list
		} else if x > w-app.cfg.MemberColWidth {
			app.win.ScrollMemberUpBy(4)
			app.requestHistory()
		} else {
			app.win.ScrollUpBy(4)
			app.requestHistory()


@@ 480,8 482,8 @@ func (app *App) requestHistory() {
	buffer := app.win.CurrentBuffer()
	if app.win.IsAtTop() && buffer != Home {
		t := time.Now()
		if oldest := app.win.CurrentBufferOldestTime(); oldest != nil {
			t = *oldest
		if bound, ok := app.messageBounds[buffer]; ok {
			t = bound.first
		}
		app.s.NewHistoryRequest(buffer).
			WithLimit(100).

M ui/buffers.go => ui/buffers.go +0 -8
@@ 319,14 319,6 @@ func (bs *BufferList) Current() (title string) {
	return bs.list[bs.current].title
}

func (bs *BufferList) CurrentOldestTime() (t *time.Time) {
	ls := bs.list[bs.current].lines
	if 0 < len(ls) {
		t = &ls[0].At
	}
	return t
}

func (bs *BufferList) ScrollUp(n int) {
	b := &bs.list[bs.current]
	if b.isAtTop {

M ui/ui.go => ui/ui.go +0 -5
@@ 3,7 3,6 @@ package ui
import (
	"strings"
	"sync/atomic"
	"time"

	"git.sr.ht/~taiite/senpai/irc"



@@ 87,10 86,6 @@ func (ui *UI) CurrentBuffer() string {
	return ui.bs.Current()
}

func (ui *UI) CurrentBufferOldestTime() (t *time.Time) {
	return ui.bs.CurrentOldestTime()
}

func (ui *UI) NextBuffer() {
	ui.bs.Next()
	ui.memberOffset = 0