aerc/commands/account/search.go
Tim Culverhouse c2f4404fca threading: enable filtering of server-side threads
This patch enables the filtering of a threaded view which uses
server-built threads. Filtering is done server-side, in order to
preserve the use of server-built threads.

In adding this feature, the filtering of notmuch folders was brought up
to feature parity with the other workers. The filters function the same
(ie: they can be stacked). The notmuch filters, however, still use
notmuch syntax for the filtering.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-10 21:15:12 +02:00

61 lines
1.5 KiB
Go

package account
import (
"errors"
"strings"
"git.sr.ht/~rjarry/aerc/lib/statusline"
"git.sr.ht/~rjarry/aerc/widgets"
"git.sr.ht/~rjarry/aerc/worker/types"
)
type SearchFilter struct{}
func init() {
register(SearchFilter{})
}
func (SearchFilter) Aliases() []string {
return []string{"search", "filter"}
}
func (SearchFilter) Complete(aerc *widgets.Aerc, args []string) []string {
return nil
}
func (SearchFilter) Execute(aerc *widgets.Aerc, args []string) error {
acct := aerc.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
store := acct.Store()
if store == nil {
return errors.New("Cannot perform action. Messages still loading")
}
if args[0] == "filter" {
if len(args[1:]) == 0 {
return Clear{}.Execute(aerc, []string{"clear"})
}
acct.SetStatus(statusline.FilterActivity("Filtering..."), statusline.Search(""))
store.SetFilter(args[1:])
cb := func(msg types.WorkerMessage) {
if _, ok := msg.(*types.Done); ok {
acct.SetStatus(statusline.FilterResult(strings.Join(args, " ")))
acct.Logger().Printf("Filter results: %v", store.Uids())
}
}
store.Sort(nil, cb)
} else {
acct.SetStatus(statusline.Search("Searching..."))
cb := func(uids []uint32) {
acct.SetStatus(statusline.Search(strings.Join(args, " ")))
acct.Logger().Printf("Search results: %v", uids)
store.ApplySearch(uids)
// TODO: Remove when stores have multiple OnUpdate handlers
acct.Messages().Invalidate()
}
store.Search(args, cb)
}
return nil
}