aboutsummaryrefslogtreecommitdiffstats
path: root/worker/notmuch/eventhandlers.go
blob: a6ab76683d517c28576b4c9523ac9e33833a3309 (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
//go:build notmuch
// +build notmuch

package notmuch

import (
	"fmt"
	"path/filepath"
	"strconv"

	"git.sr.ht/~rjarry/aerc/worker/types"
)

func (w *worker) handleNotmuchEvent(et eventType) error {
	switch et.(type) {
	case *updateDirCounts:
		return w.handleUpdateDirCounts()
	default:
		return errUnsupported
	}
}

func (w *worker) handleUpdateDirCounts() error {
	if w.store != nil {
		folders, err := w.store.FolderMap()
		if err != nil {
			w.w.Errorf("failed listing directories: %v", err)
			return err
		}
		for name := range folders {
			folder := filepath.Join(w.maildirAccountPath, name)
			query := fmt.Sprintf("folder:%s", strconv.Quote(folder))
			w.w.PostMessage(&types.DirectoryInfo{
				Info: w.getDirectoryInfo(name, query),
			}, nil)
		}
	}

	for name, query := range w.nameQueryMap {
		w.w.PostMessage(&types.DirectoryInfo{
			Info: w.getDirectoryInfo(name, query),
		}, nil)
	}
	return nil
}