diff options
author | Robin Jarry <robin@jarry.cc> | 2023-07-17 14:09:16 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-08-04 23:16:29 +0200 |
commit | 24eab0f5ef6324b00717997f671cf1d13317bd5c (patch) | |
tree | e5a5a373599a8b6ff8720d527778452aa258be12 | |
parent | f27b2d6150968bc03bfd8ba51b6048def6f4f57f (diff) | |
download | aerc-24eab0f5ef6324b00717997f671cf1d13317bd5c.tar.gz |
msglist: fetch headers even when not focused
Do not rely on MessageList.Draw only to fetch missing headers. In Draw,
report the current scroll offset and length to the message store and use
them to determine if a new message UID should be candidate for fetching
headers.
This allows the mail-received hook to work even when the message list is
not focused.
Fixes: https://todo.sr.ht/~rjarry/aerc/147
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Tristan Partin <tristan@partin.io>
-rw-r--r-- | lib/msgstore.go | 35 | ||||
-rw-r--r-- | widgets/msglist.go | 2 |
2 files changed, 30 insertions, 7 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go index 7c6f91c5..a29ff139 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -29,6 +29,10 @@ type MessageStore struct { uids []uint32 threads []*types.Thread + // Visible UIDs + scrollOffset int + scrollLen int + selectedUid uint32 bodyCallbacks map[uint32][]func(*types.FullMessage) @@ -93,6 +97,8 @@ func NewMessageStore(worker *types.Worker, Messages: make(map[uint32]*models.MessageInfo), selectedUid: MagicUid, + // default window height until account is drawn once + scrollLen: 25, bodyCallbacks: make(map[uint32][]func(*types.FullMessage)), @@ -126,6 +132,11 @@ func (store *MessageStore) SetContext(ctx context.Context) { store.ctx = ctx } +func (store *MessageStore) UpdateScroll(offset, length int) { + store.scrollOffset = offset + store.scrollLen = length +} + func (store *MessageStore) FetchHeaders(uids []uint32, cb func(types.WorkerMessage), ) { @@ -220,21 +231,26 @@ func merge(to *models.MessageInfo, from *models.MessageInfo) { } func (store *MessageStore) Update(msg types.WorkerMessage) { + var newUids []uint32 update := false updateThreads := false - directoryChange := false + start := store.scrollOffset + end := store.scrollOffset + store.scrollLen + switch msg := msg.(type) { case *types.OpenDirectory: store.Sort(store.sortCriteria, nil) update = true case *types.DirectoryContents: newMap := make(map[uint32]*models.MessageInfo, len(msg.Uids)) - for _, uid := range msg.Uids { + for i, uid := range msg.Uids { if msg, ok := store.Messages[uid]; ok { newMap[uid] = msg } else { newMap[uid] = nil - directoryChange = true + if i >= start && i < end { + newUids = append(newUids, uid) + } } } store.Messages = newMap @@ -251,12 +267,14 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { store.threads = msg.Threads newMap := make(map[uint32]*models.MessageInfo, len(store.uids)) - for _, uid := range store.uids { + for i, uid := range store.uids { if msg, ok := store.Messages[uid]; ok { newMap[uid] = msg } else { newMap[uid] = nil - directoryChange = true + if i >= start && i < end { + newUids = append(newUids, uid) + } } } @@ -348,8 +366,11 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { store.update(updateThreads) } - if directoryChange && store.triggerDirectoryChange != nil { - store.triggerDirectoryChange() + if len(newUids) > 0 { + store.FetchHeaders(newUids, nil) + if store.triggerDirectoryChange != nil { + store.triggerDirectoryChange() + } } } diff --git a/widgets/msglist.go b/widgets/msglist.go index 8263b945..a334d0d4 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -81,6 +81,8 @@ func (ml *MessageList) Draw(ctx *ui.Context) { } } + store.UpdateScroll(ml.Scroll(), ml.height) + textWidth := ctx.Width() if ml.NeedScrollbar() { textWidth -= 1 |