summaryrefslogtreecommitdiff
path: root/client/channel_window.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/channel_window.go')
-rw-r--r--client/channel_window.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/client/channel_window.go b/client/channel_window.go
index 43ce83f..b4c9b9f 100644
--- a/client/channel_window.go
+++ b/client/channel_window.go
@@ -19,6 +19,7 @@ type channelWindow struct {
input tui.TextInput
watchedUsers map[string]bool
loadingHistory bool
+ endOfHistory bool
}
type channelMsg struct {
@@ -34,6 +35,7 @@ func (cl channelLocation) CreateWindow() window.Window {
location: cl, watchedUsers: make(map[string]bool),
}
globalApp.cache.Watch(cl.id)
+ cw.loadMoreHistory()
return cw
}
@@ -73,6 +75,9 @@ func (cw *channelWindow) Kill() {
}
func (cw *channelWindow) Buffer() *buffer.Buffer {
+ if cw.buf.AtTop() {
+ cw.loadMoreHistory()
+ }
return &cw.buf
}
@@ -107,6 +112,37 @@ func (cw *channelWindow) leaveChannel() {
globalApp.windowCache.Evict(cw.location)
}
+func (cw *channelWindow) loadMoreHistory() {
+ if cw.loadingHistory || cw.endOfHistory {
+ return
+ }
+ cw.loadingHistory = true
+
+ rq := proto.Object {Fields: make(map[string]string)}
+ top := cw.buf.Top()
+ if top != nil {
+ rq.Kind = "before"
+ rq.Fields[""] = top.Msg().(channelMsg).Object.Id
+ } else {
+ rq.Kind = "latest"
+ }
+ cb := func(response proto.Command) {
+ cw.loadingHistory = false
+ switch response.Kind {
+ case "history":
+ if len(response.Args) == 0 {
+ cw.endOfHistory = true
+ }
+ for i := len(response.Args) - 1; i >= 0; i-- {
+ cw.buf.AddTop(channelMsg {response.Args[i], cw})
+ }
+ case "fail":
+ cw.endOfHistory = true
+ }
+ }
+ globalApp.Request(proto.NewCmd("history", cw.location.id, rq), cb)
+}
+
type userListMsg struct {
index int
channelName string
@@ -177,7 +213,7 @@ func (cw *channelWindow) ShowStatusLine() {
}
tui.Text(ch.Fields[""], nil)
if cw.loadingHistory {
- tui.Text("...", nil)
+ tui.Text(" ...", nil)
}
}