msglist: update message counter upon filter change

Update message counter in msglist when the filter is changed (either set or
cleared in the msgstore).

When we apply a filter, we change the number of uids in the message
store. This can unintentionally trigger the storeUpdate() function of
the msglist which checks the number of uids for new messages and
advances the pointer by the difference in the number of messages. This
can be avoided when we update the message counter upon changing the
filter.

Fixes: https://todo.sr.ht/~rjarry/aerc/23
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-03-20 09:47:52 +01:00 committed by Robin Jarry
parent 7d2b0f579d
commit 9f4da4de0c
2 changed files with 17 additions and 0 deletions

View file

@ -43,6 +43,7 @@ type MessageStore struct {
// Map of uids we've asked the worker to fetch // Map of uids we've asked the worker to fetch
onUpdate func(store *MessageStore) // TODO: multiple onUpdate handlers onUpdate func(store *MessageStore) // TODO: multiple onUpdate handlers
onFilterChange func(store *MessageStore)
onUpdateDirs func() onUpdateDirs func()
pendingBodies map[uint32]interface{} pendingBodies map[uint32]interface{}
pendingHeaders map[uint32]interface{} pendingHeaders map[uint32]interface{}
@ -323,6 +324,10 @@ func (store *MessageStore) OnUpdate(fn func(store *MessageStore)) {
store.onUpdate = fn store.onUpdate = fn
} }
func (store *MessageStore) OnFilterChange(fn func(store *MessageStore)) {
store.onFilterChange = fn
}
func (store *MessageStore) OnUpdateDirs(fn func()) { func (store *MessageStore) OnUpdateDirs(fn func()) {
store.onUpdateDirs = fn store.onUpdateDirs = fn
} }
@ -655,6 +660,9 @@ func (store *MessageStore) ApplyFilter(results []uint32) {
store.results = nil store.results = nil
store.filtered = results store.filtered = results
store.filter = true store.filter = true
if store.onFilterChange != nil {
store.onFilterChange(store)
}
store.update() store.update()
// any marking is now invalid // any marking is now invalid
// TODO: could save that probably // TODO: could save that probably
@ -668,6 +676,9 @@ func (store *MessageStore) ApplyClear() {
if store.BuildThreads() { if store.BuildThreads() {
store.runThreadBuilder() store.runThreadBuilder()
} }
if store.onFilterChange != nil {
store.onFilterChange(store)
}
} }
func (store *MessageStore) nextPrevResult(delta int) { func (store *MessageStore) nextPrevResult(delta int) {

View file

@ -367,6 +367,12 @@ func (ml *MessageList) SetStore(store *lib.MessageStore) {
ml.spinner.Stop() ml.spinner.Stop()
ml.nmsgs = len(store.Uids()) ml.nmsgs = len(store.Uids())
store.OnUpdate(ml.storeUpdate) store.OnUpdate(ml.storeUpdate)
store.OnFilterChange(func(store *lib.MessageStore) {
if ml.Store() != store {
return
}
ml.nmsgs = len(store.Uids())
})
} else { } else {
ml.spinner.Start() ml.spinner.Start()
} }