notmuch: align dirInfo logic to the maildir worker

This commit is contained in:
Reto Brunner 2020-02-29 14:40:51 +01:00 committed by Drew DeVault
parent 841655a98e
commit fb2df7e169
1 changed files with 13 additions and 10 deletions

View File

@ -33,6 +33,7 @@ type worker struct {
w *types.Worker w *types.Worker
nmEvents chan eventType nmEvents chan eventType
query string query string
currentQueryName string
uidStore *uidstore.Store uidStore *uidstore.Store
nameQueryMap map[string]string nameQueryMap map[string]string
db *notmuch.DB db *notmuch.DB
@ -118,8 +119,6 @@ func (w *worker) handleMessage(msg types.WorkerMessage) error {
return w.handleSearchDirectory(msg) return w.handleSearchDirectory(msg)
case *types.ModifyLabels: case *types.ModifyLabels:
return w.handleModifyLabels(msg) return w.handleModifyLabels(msg)
case *types.DirectoryInfoUpdateRequest:
return w.handleDirInfoUpdateRequest(msg)
// not implemented, they are generally not used // not implemented, they are generally not used
// in a notmuch based workflow // in a notmuch based workflow
@ -217,14 +216,12 @@ func (w *worker) gatherDirectoryInfo(name string, query string) (
return info, nil return info, nil
} }
func (w *worker) handleDirInfoUpdateRequest( func (w *worker) emitDirectoryInfo(name string) error {
msg *types.DirectoryInfoUpdateRequest) error { query := w.queryFromName(name)
query := w.queryFromName(msg.Name) info, err := w.gatherDirectoryInfo(name, query)
info, err := w.gatherDirectoryInfo(msg.Name, query)
if err != nil { if err != nil {
return err return err
} }
info.Message = types.RespondTo(msg)
w.w.PostMessage(info, nil) w.w.PostMessage(info, nil)
return nil return nil
} }
@ -244,6 +241,7 @@ func (w *worker) handleOpenDirectory(msg *types.OpenDirectory) error {
w.w.Logger.Printf("opening %s", msg.Directory) w.w.Logger.Printf("opening %s", msg.Directory)
// try the friendly name first, if that fails assume it's a query // try the friendly name first, if that fails assume it's a query
w.query = w.queryFromName(msg.Directory) w.query = w.queryFromName(msg.Directory)
w.currentQueryName = msg.Directory
info, err := w.gatherDirectoryInfo(msg.Directory, w.query) info, err := w.gatherDirectoryInfo(msg.Directory, w.query)
if err != nil { if err != nil {
return err return err
@ -343,11 +341,13 @@ func (w *worker) handleFetchMessageBodyPart(
} }
// send updated flags to ui // send updated flags to ui
err = w.emitMessageInfo(m, msg) if err = w.emitMessageInfo(m, msg); err != nil {
if err != nil {
w.w.Logger.Printf(err.Error()) w.w.Logger.Printf(err.Error())
w.err(msg, err)
} }
if err = w.emitDirectoryInfo(w.currentQueryName); err != nil {
w.w.Logger.Printf(err.Error())
}
w.done(msg) w.done(msg)
return nil return nil
} }
@ -396,6 +396,9 @@ func (w *worker) handleReadMessages(msg *types.ReadMessages) error {
continue continue
} }
} }
if err := w.emitDirectoryInfo(w.currentQueryName); err != nil {
w.w.Logger.Printf(err.Error())
}
w.done(msg) w.done(msg)
return nil return nil
} }