aboutsummaryrefslogtreecommitdiffstats
path: root/worker/notmuch/eventhandlers.go
blob: ab18046771f8080a970916a503b9acb6b1d6c2e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//go:build notmuch
// +build notmuch

package notmuch

import (
	"fmt"
	"strconv"

	"git.sr.ht/~rjarry/aerc/logging"
)

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))
			info, err := w.buildDirInfo(name, query, true)
			if err != nil {
				logging.Errorf("could not gather DirectoryInfo: %v", err)
				continue
			}
			w.w.PostMessage(info, nil)
		}
	}

	for name, query := range w.nameQueryMap {
		info, err := w.buildDirInfo(name, query, true)
		if err != nil {
			logging.Errorf("could not gather DirectoryInfo: %v", err)
			continue
		}
		w.w.PostMessage(info, nil)
	}
	return nil
}