aerc/worker/notmuch/eventhandlers.go
Julian Pidancet c31a5fc33d notmuch: simplify DirectoryInfo emitting logic
Refactor the code emitting DirectoryInfo messages. Reduce function
call indirections by retiring gatherDirectoryInfo(), buildDirInfo() and
emitDirectoryInfo(), and replacing them with getDirectoryInfo()
(aligning the code with what is done in the maildir worker by the same
occasion).

Also merge queryFromName(), which no longer needs to be called from
different places, in handleOpenDirectory().

Signed-off-by: Julian Pidancet <julian.pidancet@oracle.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
2022-10-27 21:45:31 +02:00

47 lines
947 B
Go

//go:build notmuch
// +build notmuch
package notmuch
import (
"fmt"
"strconv"
"git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/worker/types"
)
func (w *worker) handleNotmuchEvent(et eventType) error {
switch ev := et.(type) {
case *updateDirCounts:
return w.handleUpdateDirCounts(ev)
default:
return errUnsupported
}
}
func (w *worker) handleUpdateDirCounts(ev eventType) error {
if w.store != nil {
folders, err := w.store.FolderMap()
if err != nil {
logging.Errorf("failed listing directories: %v", err)
return err
}
for name := range folders {
query := fmt.Sprintf("folder:%s", strconv.Quote(name))
w.w.PostMessage(&types.DirectoryInfo{
Info: w.getDirectoryInfo(name, query),
SkipSort: true,
}, nil)
}
}
for name, query := range w.nameQueryMap {
w.w.PostMessage(&types.DirectoryInfo{
Info: w.getDirectoryInfo(name, query),
SkipSort: true,
}, nil)
}
return nil
}