diff options
-rw-r--r-- | lib/msgstore.go | 8 | ||||
-rw-r--r-- | widgets/account.go | 2 | ||||
-rw-r--r-- | widgets/dirlist.go | 17 |
3 files changed, 18 insertions, 9 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go index 7209316e..e6ddf72f 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -31,8 +31,6 @@ 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() @@ -46,7 +44,6 @@ type MessageStore struct { func NewMessageStore(worker *types.Worker, dirInfo *models.DirectoryInfo, - defaultSortCriteria []*types.SortCriterion, triggerNewEmail func(*models.MessageInfo), triggerDirectoryChange func()) *MessageStore { @@ -60,8 +57,6 @@ 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, @@ -176,9 +171,6 @@ func (store *MessageStore) Update(msg types.WorkerMessage) { switch msg := msg.(type) { case *types.DirectoryInfo: store.DirInfo = *msg.Info - store.worker.PostAction(&types.FetchDirectoryContents{ - SortCriteria: store.defaultSortCriteria, - }, nil) update = true case *types.DirectoryContents: newMap := make(map[uint32]*models.MessageInfo) diff --git a/widgets/account.go b/widgets/account.go index f8b6581f..a83624fe 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -242,7 +242,6 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { store.Update(msg) } else { store = lib.NewMessageStore(acct.worker, msg.Info, - acct.getSortCriteria(), func(msg *models.MessageInfo) { acct.conf.Triggers.ExecNewEmail(acct.acct, acct.conf, msg) @@ -257,6 +256,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { acct.msglist.SetStore(store) }) } + acct.dirlist.Invalidate() case *types.DirectoryContents: if store, ok := acct.dirlist.SelectedMsgStore(); ok { store.Update(msg) diff --git a/widgets/dirlist.go b/widgets/dirlist.go index 9267a3cb..e8a93091 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -11,6 +11,7 @@ import ( "git.sr.ht/~sircmpwn/aerc/config" "git.sr.ht/~sircmpwn/aerc/lib" + libsort "git.sr.ht/~sircmpwn/aerc/lib/sort" "git.sr.ht/~sircmpwn/aerc/lib/ui" "git.sr.ht/~sircmpwn/aerc/models" "git.sr.ht/~sircmpwn/aerc/worker/types" @@ -104,6 +105,10 @@ func (dirlist *DirectoryList) Select(name string) { } sort.Strings(dirlist.dirs) dirlist.sortDirsByFoldersSortConfig() + // once opened, we need to enumerate the contents + dirlist.worker.PostAction(&types.FetchDirectoryContents{ + SortCriteria: dirlist.getSortCriteria(), + }, nil) } dirlist.Invalidate() }) @@ -378,3 +383,15 @@ func findString(slice []string, str string) int { } return -1 } + +func (dirlist *DirectoryList) getSortCriteria() []*types.SortCriterion { + if len(dirlist.UiConfig().Sort) == 0 { + return nil + } + criteria, err := libsort.GetSortCriteria(dirlist.UiConfig().Sort) + if err != nil { + dirlist.logger.Printf("getSortCriteria failed: %v", err) + return nil + } + return criteria +} |