From 8464b373851142b0becaaa10db34df3559b2b62e Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 17 Oct 2023 15:31:09 +0200 Subject: search: use a common api for all workers Define a SearchCriteria structure. Update the FetchDirectoryContents, FetchDirectoryThreaded and SearchDirectory worker messages to include this SearchCriteria structure instead of a []string slice. Parse the search arguments in a single place into a SearchCriteria structure and use it to search/filter via the message store. Update all workers to use that new API. Clarify the man page indicating that notmuch supports searching with aerc's syntax and also with notmuch specific syntax. getopt is no longer needed, remove it from go.mod. NB: to support more complex search filters in JMAP, we need to use an email.Filter interface. Since GOB does not support encoding/decoding interfaces, store the raw SearchCriteria and []SortCriterion values in the cached FolderContents. Translate them to JMAP API objects when sending an email.Query request to the server. Signed-off-by: Robin Jarry Reviewed-by: Koni Marti Tested-by: Moritz Poldrack Tested-by: Inwit --- lib/msgstore.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/msgstore.go b/lib/msgstore.go index ab48f331..c68c2ed8 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -42,7 +42,7 @@ type MessageStore struct { // Search/filter results results []uint32 resultIndex int - filter []string + filter *types.SearchCriteria sortCriteria []*types.SortCriterion sortDefault []*types.SortCriterion @@ -110,7 +110,6 @@ func NewMessageStore(worker *types.Worker, reverseThreadOrder: reverseThreadOrder, sortThreadSiblings: sortThreadSiblings, - filter: []string{"filter"}, sortCriteria: defaultSortCriteria, sortDefault: defaultSortCriteria, @@ -719,10 +718,10 @@ func (store *MessageStore) Prev() { store.NextPrev(-1) } -func (store *MessageStore) Search(args []string, cb func([]uint32)) { +func (store *MessageStore) Search(terms *types.SearchCriteria, cb func([]uint32)) { store.worker.PostAction(&types.SearchDirectory{ - Context: store.ctx, - Argv: args, + Context: store.ctx, + Criteria: terms, }, func(msg types.WorkerMessage) { if msg, ok := msg.(*types.SearchResults); ok { allowedUids := store.Uids() @@ -757,12 +756,12 @@ func (store *MessageStore) IsResult(uid uint32) bool { return false } -func (store *MessageStore) SetFilter(args []string) { - store.filter = append(store.filter, args...) +func (store *MessageStore) SetFilter(terms *types.SearchCriteria) { + store.filter = store.filter.Combine(terms) } func (store *MessageStore) ApplyClear() { - store.filter = []string{"filter"} + store.filter = nil store.results = nil if store.onFilterChange != nil { store.onFilterChange(store) @@ -839,16 +838,16 @@ func (store *MessageStore) Sort(criteria []*types.SortCriterion, cb func(types.W if store.threadedView && !store.buildThreads { store.worker.PostAction(&types.FetchDirectoryThreaded{ - Context: store.ctx, - SortCriteria: criteria, - FilterCriteria: store.filter, - ThreadContext: store.threadContext, + Context: store.ctx, + SortCriteria: criteria, + Filter: store.filter, + ThreadContext: store.threadContext, }, handle_return) } else { store.worker.PostAction(&types.FetchDirectoryContents{ - Context: store.ctx, - SortCriteria: criteria, - FilterCriteria: store.filter, + Context: store.ctx, + SortCriteria: criteria, + Filter: store.filter, }, handle_return) } } -- cgit