aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-04-16 09:53:38 -0500
committerRobin Jarry <robin@jarry.cc>2023-04-22 22:40:12 +0200
commit87765f93de9b5c123be5beee45b62425c71c2005 (patch)
tree0c9401dc48b48d4592900109d592befc5c624f21 /worker
parent82de08a8a3f55c438d8808e3c759e3d99261c4b8 (diff)
downloadaerc-87765f93de9b5c123be5beee45b62425c71c2005.tar.gz
capabilities: report capabilities from backend
Use the Backend interface to report Backend capabilities. Previously, these were reported via a DirectoryInfo message, however they have nothing to do with a directory and should be reported directly by the backend. Add Capabilities method to Backend interface, satisfy this in each backend, and use it on the UI side. Remove Caps field from DirectoryInfo Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry<robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/checkmail.go1
-rw-r--r--worker/imap/list.go1
-rw-r--r--worker/imap/worker.go4
-rw-r--r--worker/maildir/worker.go29
-rw-r--r--worker/mbox/models.go4
-rw-r--r--worker/mbox/worker.go10
-rw-r--r--worker/notmuch/worker.go14
-rw-r--r--worker/types/worker.go1
8 files changed, 46 insertions, 18 deletions
diff --git a/worker/imap/checkmail.go b/worker/imap/checkmail.go
index 9c1f14c1..05441a3c 100644
--- a/worker/imap/checkmail.go
+++ b/worker/imap/checkmail.go
@@ -66,7 +66,6 @@ func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) {
Exists: int(status.Messages),
Recent: int(status.Recent),
Unseen: int(status.Unseen),
- Caps: w.caps,
},
Refetch: refetch,
}, nil)
diff --git a/worker/imap/list.go b/worker/imap/list.go
index c7f1ed58..b1bc65a1 100644
--- a/worker/imap/list.go
+++ b/worker/imap/list.go
@@ -65,7 +65,6 @@ func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) {
Exists: int(status.Messages),
Recent: int(status.Recent),
Unseen: int(status.Unseen),
- Caps: imapw.caps,
},
}, nil)
}
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
index 8673c0ff..1f61f458 100644
--- a/worker/imap/worker.go
+++ b/worker/imap/worker.go
@@ -307,3 +307,7 @@ func (w *IMAPWorker) Run() {
}
}
}
+
+func (w *IMAPWorker) Capabilities() *models.Capabilities {
+ return w.caps
+}
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index dc794a10..d8b3e816 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -43,6 +43,7 @@ type Worker struct {
watcher types.FSWatcher
currentSortCriteria []*types.SortCriterion
maildirpp bool // whether to use Maildir++ directory layout
+ capabilities *models.Capabilities
}
// NewWorker creates a new maildir worker with the provided worker.
@@ -51,7 +52,14 @@ func NewWorker(worker *types.Worker) (types.Backend, error) {
if err != nil {
return nil, fmt.Errorf("could not create file system watcher: %w", err)
}
- return &Worker{worker: worker, watcher: watch}, nil
+ return &Worker{
+ capabilities: &models.Capabilities{
+ Sort: true,
+ Thread: true,
+ },
+ worker: worker,
+ watcher: watch,
+ }, nil
}
// NewMaildirppWorker creates a new Maildir++ worker with the provided worker.
@@ -60,7 +68,15 @@ func NewMaildirppWorker(worker *types.Worker) (types.Backend, error) {
if err != nil {
return nil, fmt.Errorf("could not create file system watcher: %w", err)
}
- return &Worker{worker: worker, watcher: watch, maildirpp: true}, nil
+ return &Worker{
+ capabilities: &models.Capabilities{
+ Sort: true,
+ Thread: true,
+ },
+ worker: worker,
+ watcher: watch,
+ maildirpp: true,
+ }, nil
}
// Run starts the worker's message handling loop.
@@ -75,6 +91,10 @@ func (w *Worker) Run() {
}
}
+func (w *Worker) Capabilities() *models.Capabilities {
+ return w.capabilities
+}
+
func (w *Worker) handleAction(action types.WorkerMessage) {
msg := w.worker.ProcessAction(action)
switch msg := msg.(type) {
@@ -177,11 +197,6 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo {
Unseen: 0,
AccurateCounts: false,
-
- Caps: &models.Capabilities{
- Sort: true,
- Thread: true,
- },
}
dir := w.c.Store.Dir(name)
diff --git a/worker/mbox/models.go b/worker/mbox/models.go
index 3af93a84..1546f01a 100644
--- a/worker/mbox/models.go
+++ b/worker/mbox/models.go
@@ -49,10 +49,6 @@ func (md *mailboxContainer) DirectoryInfo(file string) *models.DirectoryInfo {
Recent: 0,
Unseen: 0,
AccurateCounts: false,
- Caps: &models.Capabilities{
- Sort: true,
- Thread: false,
- },
}
}
diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go
index c2cf9ecb..3063640a 100644
--- a/worker/mbox/worker.go
+++ b/worker/mbox/worker.go
@@ -28,11 +28,17 @@ type mboxWorker struct {
name string
folder *container
worker *types.Worker
+
+ capabilities *models.Capabilities
}
func NewWorker(worker *types.Worker) (types.Backend, error) {
return &mboxWorker{
worker: worker,
+ capabilities: &models.Capabilities{
+ Sort: true,
+ Thread: false,
+ },
}, nil
}
@@ -373,6 +379,10 @@ func (w *mboxWorker) Run() {
}
}
+func (w *mboxWorker) Capabilities() *models.Capabilities {
+ return w.capabilities
+}
+
func filterUids(folder *container, uids []uint32, args []string) ([]uint32, error) {
criteria, err := lib.GetSearchCriteria(args)
if err != nil {
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index 49e598bf..81f38d1c 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -48,6 +48,7 @@ type worker struct {
currentSortCriteria []*types.SortCriterion
watcher types.FSWatcher
watcherDebounce *time.Timer
+ capabilities *models.Capabilities
}
// NewWorker creates a new notmuch worker with the provided worker.
@@ -61,6 +62,10 @@ func NewWorker(w *types.Worker) (types.Backend, error) {
w: w,
nmEvents: events,
watcher: watcher,
+ capabilities: &models.Capabilities{
+ Sort: true,
+ Thread: true,
+ },
}, nil
}
@@ -100,6 +105,10 @@ func (w *worker) Run() {
}
}
+func (w *worker) Capabilities() *models.Capabilities {
+ return w.capabilities
+}
+
func (w *worker) done(msg types.WorkerMessage) {
w.w.PostMessage(&types.Done{Message: types.RespondTo(msg)}, nil)
}
@@ -276,11 +285,6 @@ func (w *worker) getDirectoryInfo(name string, query string) *models.DirectoryIn
// total unread
Unseen: 0,
AccurateCounts: true,
-
- Caps: &models.Capabilities{
- Sort: true,
- Thread: true,
- },
}
count, err := w.db.QueryCountMessages(query)
diff --git a/worker/types/worker.go b/worker/types/worker.go
index 4b2937c6..55e00faf 100644
--- a/worker/types/worker.go
+++ b/worker/types/worker.go
@@ -14,6 +14,7 @@ var lastId int64 = 1 // access via atomic
type Backend interface {
Run()
+ Capabilities() *models.Capabilities
}
type Worker struct {