summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--worker/notmuch/lib/database.go17
-rw-r--r--worker/notmuch/worker.go12
2 files changed, 29 insertions, 0 deletions
diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go
index f4fd588..0706bbc 100644
--- a/worker/notmuch/lib/database.go
+++ b/worker/notmuch/lib/database.go
@@ -55,6 +55,23 @@ func (db *DB) connectRO() error {
 	return nil
 }
 
+// ListTags lists all known tags
+func (db *DB) ListTags() ([]string, error) {
+	if db.ro == nil {
+		return nil, fmt.Errorf("not connected to the notmuch db")
+	}
+	tags, err := db.ro.Tags()
+	if err != nil {
+		return nil, err
+	}
+	var result []string
+	var tag *notmuch.Tag
+	for tags.Next(&tag) {
+		result = append(result, tag.Value)
+	}
+	return result, nil
+}
+
 //getQuery returns a query based on the provided query string.
 //It also configures the query as specified on the worker
 func (db *DB) newQuery(query string) (*notmuch.Query, error) {
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index ef4d4bf..96ec0cb 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -153,6 +153,7 @@ func (w *worker) handleConnect(msg *types.Connect) error {
 		return err
 	}
 	w.done(msg)
+	w.emitLabelList()
 	return nil
 }
 
@@ -383,6 +384,8 @@ func (w *worker) handleModifyLabels(msg *types.ModifyLabels) error {
 	if err != nil {
 		return err
 	}
+	// and update the list of possible tags
+	w.emitLabelList()
 	w.done(msg)
 	return nil
 }
@@ -460,6 +463,15 @@ func (w *worker) emitMessageInfo(m *Message,
 	return nil
 }
 
+func (w *worker) emitLabelList() {
+	tags, err := w.db.ListTags()
+	if err != nil {
+		w.w.Logger.Printf("could not load tags: %v", err)
+		return
+	}
+	w.w.PostMessage(&types.LabelList{Labels: tags}, nil)
+}
+
 func (w *worker) sort(uids []uint32,
 	criteria []*types.SortCriterion) ([]uint32, error) {
 	if len(criteria) == 0 {
78 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254