Advance message list cursor when messages arrive
This commit is contained in:
parent
588a6c785b
commit
13032734cd
1 changed files with 13 additions and 0 deletions
|
@ -18,6 +18,7 @@ type MessageList struct {
|
||||||
height int
|
height int
|
||||||
scroll int
|
scroll int
|
||||||
selected int
|
selected int
|
||||||
|
nmsgs int
|
||||||
spinner *Spinner
|
spinner *Spinner
|
||||||
store *lib.MessageStore
|
store *lib.MessageStore
|
||||||
}
|
}
|
||||||
|
@ -108,9 +109,20 @@ func (ml *MessageList) storeUpdate(store *lib.MessageStore) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(store.Uids) > 0 {
|
if len(store.Uids) > 0 {
|
||||||
|
// Prevent selecting beyond the last message
|
||||||
for ml.selected >= len(store.Uids) {
|
for ml.selected >= len(store.Uids) {
|
||||||
ml.Prev()
|
ml.Prev()
|
||||||
}
|
}
|
||||||
|
// When new messages come in, advance the cursor accordingly
|
||||||
|
// Note that this assumes new messages are appended to the top, which
|
||||||
|
// isn't necessarily true once we implement SORT... ideally we'd look
|
||||||
|
// for the previously selected UID.
|
||||||
|
if len(store.Uids) > ml.nmsgs && ml.nmsgs != 0 {
|
||||||
|
for i := 0; i < len(store.Uids)-ml.nmsgs; i++ {
|
||||||
|
ml.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ml.nmsgs = len(store.Uids)
|
||||||
}
|
}
|
||||||
|
|
||||||
ml.Invalidate()
|
ml.Invalidate()
|
||||||
|
@ -124,6 +136,7 @@ func (ml *MessageList) SetStore(store *lib.MessageStore) {
|
||||||
ml.store = store
|
ml.store = store
|
||||||
if store != nil {
|
if store != nil {
|
||||||
ml.spinner.Stop()
|
ml.spinner.Stop()
|
||||||
|
ml.nmsgs = len(store.Uids)
|
||||||
store.OnUpdate(ml.storeUpdate)
|
store.OnUpdate(ml.storeUpdate)
|
||||||
} else {
|
} else {
|
||||||
ml.spinner.Start()
|
ml.spinner.Start()
|
||||||
|
|
Loading…
Reference in a new issue