about summary refs log tree commit diff stats
path: root/commands/account/search.go
diff options
context:
space:
mode:
authorKevin Kuehler <keur@ocf.berkeley.edu>2019-07-17 00:35:50 -0700
committerDrew DeVault <sir@cmpwn.com>2019-07-19 11:30:32 -0400
commitf81e4bd41c3ba9427390eadfc5133ed8daada6ab (patch)
tree1c815a23a33005dbd51bc0c4c1c1e1234fe696a5 /commands/account/search.go
parent8b2abcb02a191ad77c971fd4679c7d177ce2f827 (diff)
downloadaerc-f81e4bd41c3ba9427390eadfc5133ed8daada6ab.tar.gz
Implement :filter, :clear
Signed-off-by: Kevin Kuehler <keur@ocf.berkeley.edu>
Diffstat (limited to 'commands/account/search.go')
-rw-r--r--commands/account/search.go30
1 files changed, 21 insertions, 9 deletions
diff --git a/commands/account/search.go b/commands/account/search.go
index 0687c5b..da7ab03 100644
--- a/commands/account/search.go
+++ b/commands/account/search.go
@@ -16,7 +16,7 @@ func init() {
 }
 
 func (_ SearchFilter) Aliases() []string {
-	return []string{"search"}
+	return []string{"search", "filter"}
 }
 
 func (_ SearchFilter) Complete(aerc *widgets.Aerc, args []string) []string {
@@ -54,13 +54,25 @@ func (_ SearchFilter) Execute(aerc *widgets.Aerc, args []string) error {
 	if store == nil {
 		return errors.New("Cannot perform action. Messages still loading")
 	}
-	aerc.SetStatus("Searching...")
-	store.Search(criteria, func(uids []uint32) {
-		aerc.SetStatus("Search complete.")
-		acct.Logger().Printf("Search results: %v", uids)
-		store.ApplySearch(uids)
-		// TODO: Remove when stores have multiple OnUpdate handlers
-		acct.Messages().Scroll()
-	})
+
+	var cb func([]uint32)
+	if args[0] == "filter" {
+		aerc.SetStatus("Filtering...")
+		cb = func(uids []uint32) {
+			aerc.SetStatus("Filter complete.")
+			acct.Logger().Printf("Filter results: %v", uids)
+			store.ApplyFilter(uids)
+		}
+	} else {
+		aerc.SetStatus("Searching...")
+		cb = func(uids []uint32) {
+			aerc.SetStatus("Search complete.")
+			acct.Logger().Printf("Search results: %v", uids)
+			store.ApplySearch(uids)
+			// TODO: Remove when stores have multiple OnUpdate handlers
+			acct.Messages().Scroll()
+		}
+	}
+	store.Search(criteria, cb)
 	return nil
 }