2021-12-11 23:20:53 +01:00
|
|
|
//go:build notmuch
|
|
|
|
// +build notmuch
|
2020-02-26 20:36:18 +01:00
|
|
|
|
2020-02-15 14:14:46 +01:00
|
|
|
package notmuch
|
|
|
|
|
2022-10-26 22:29:04 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"git.sr.ht/~rjarry/aerc/logging"
|
|
|
|
)
|
2022-07-19 22:31:51 +02:00
|
|
|
|
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 {
|
2022-10-26 22:29:04 +02:00
|
|
|
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))
|
|
|
|
info, err := w.buildDirInfo(name, query, true)
|
|
|
|
if err != nil {
|
|
|
|
logging.Errorf("could not gather DirectoryInfo: %v", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
w.w.PostMessage(info, nil)
|
|
|
|
}
|
|
|
|
|
2020-02-15 14:14:47 +01:00
|
|
|
for name, query := range w.nameQueryMap {
|
2022-07-30 17:36:56 +02:00
|
|
|
info, err := w.buildDirInfo(name, query, true)
|
2020-02-15 14:14:47 +01:00
|
|
|
if err != nil {
|
2022-07-19 22:31:51 +02:00
|
|
|
logging.Errorf("could not gather DirectoryInfo: %v", err)
|
2020-02-15 14:14:47 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
w.w.PostMessage(info, nil)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|