diff options
author | Jeffas <dev@jeffas.io> | 2019-09-19 23:37:44 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-09-20 14:56:02 -0400 |
commit | 90d26da58a4af2d34328f5916adf3781222966c6 (patch) | |
tree | 58a60e0d42b183f94d12b35e19ed1b046d03d5cd /lib/msgstore.go | |
parent | 43435ba06cd0820a83f14630881981b338473cb8 (diff) | |
download | aerc-90d26da58a4af2d34328f5916adf3781222966c6.tar.gz |
Add sorting functionality
There is a command and config option. The criteria are a list of the sort criterion and each can be individually reversed. This only includes support for sorting in the maildir backend currently. The other backends are not supported in this patch.
Diffstat (limited to 'lib/msgstore.go')
-rw-r--r-- | lib/msgstore.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go index 1f18fbf..b0392ba 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -25,6 +25,8 @@ type MessageStore struct { resultIndex int filter bool + defaultSortCriteria []*types.SortCriterion + // Map of uids we've asked the worker to fetch onUpdate func(store *MessageStore) // TODO: multiple onUpdate handlers onUpdateDirs func() @@ -38,6 +40,7 @@ type MessageStore struct { func NewMessageStore(worker *types.Worker, dirInfo *models.DirectoryInfo, + defaultSortCriteria []*types.SortCriterion, triggerNewEmail func(*models.MessageInfo), triggerDirectoryChange func()) *MessageStore { @@ -49,6 +52,8 @@ func NewMessageStore(worker *types.Worker, bodyCallbacks: make(map[uint32][]func(io.Reader)), headerCallbacks: make(map[uint32][]func(*types.MessageInfo)), + defaultSortCriteria: defaultSortCriteria, + pendingBodies: make(map[uint32]interface{}), pendingHeaders: make(map[uint32]interface{}), worker: worker, @@ -151,7 +156,9 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { switch msg := msg.(type) { case *types.DirectoryInfo: store.DirInfo = *msg.Info - store.worker.PostAction(&types.FetchDirectoryContents{}, nil) + store.worker.PostAction(&types.FetchDirectoryContents{ + SortCriteria: store.defaultSortCriteria, + }, nil) update = true case *types.DirectoryContents: newMap := make(map[uint32]*models.MessageInfo) @@ -434,3 +441,11 @@ func (store *MessageStore) ModifyLabels(uids []uint32, add, remove []string, Remove: remove, }, cb) } + +func (store *MessageStore) Sort(criteria []*types.SortCriterion, cb func()) { + store.worker.PostAction(&types.FetchDirectoryContents{ + SortCriteria: criteria, + }, func(msg types.WorkerMessage) { + cb() + }) +} |