aerc/worker/notmuch/eventhandlers.go

47 lines
947 B
Go
Raw Normal View History

//go:build notmuch
// +build notmuch
2020-02-26 20:36:18 +01:00
2020-02-15 14:14:46 +01:00
package notmuch
import (
"fmt"
"strconv"
"git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/worker/types"
)
2020-02-15 14:14:46 +01:00
func (w *worker) handleNotmuchEvent(et eventType) error {
switch ev := et.(type) {
2020-02-15 14:14:47 +01:00
case *updateDirCounts:
return w.handleUpdateDirCounts(ev)
2020-02-15 14:14:46 +01:00
default:
return errUnsupported
}
}
2020-02-15 14:14:47 +01:00
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)
}
}
2020-02-15 14:14:47 +01:00
for name, query := range w.nameQueryMap {
w.w.PostMessage(&types.DirectoryInfo{
Info: w.getDirectoryInfo(name, query),
SkipSort: true,
}, nil)
2020-02-15 14:14:47 +01:00
}
return nil
}