1
0
Fork 0
mirror of https://git.sr.ht/~rjarry/aerc synced 2025-07-02 05:00:21 +02:00
aerc/lib/dirstore.go
Koni Marti 345907914f dirstore: list the folders in arrival order
List the folders in arrival order when dirstore.List() is called instead
of returning it in an arbitrary order.

If enable-folders-sort=false and dirlist-tree=false, the directory list
will arbitrarly reshuffle when changing directories because the
dirlist.dirs are generated from keys in a map in the dirstore.

Fixes: https://todo.sr.ht/~rjarry/aerc/178
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2023-05-28 18:21:26 +02:00

51 lines
1.1 KiB
Go

package lib
import (
"git.sr.ht/~rjarry/aerc/lib/sort"
"git.sr.ht/~rjarry/aerc/models"
)
type DirStore struct {
dirs map[string]*models.Directory
msgStores map[string]*MessageStore
order []string
}
func NewDirStore() *DirStore {
return &DirStore{
dirs: make(map[string]*models.Directory),
msgStores: make(map[string]*MessageStore),
}
}
func (store *DirStore) List() []string {
dirs := []string{}
for dir := range store.msgStores {
dirs = append(dirs, dir)
}
sort.SortStringBy(dirs, store.order)
return dirs
}
func (store *DirStore) MessageStore(dirname string) (*MessageStore, bool) {
msgStore, ok := store.msgStores[dirname]
return msgStore, ok
}
func (store *DirStore) SetMessageStore(dir *models.Directory, msgStore *MessageStore) {
s := dir.Name
if _, ok := store.dirs[s]; !ok {
store.order = append(store.order, s)
}
store.dirs[dir.Name] = dir
store.msgStores[dir.Name] = msgStore
}
func (store *DirStore) Remove(name string) {
delete(store.dirs, name)
delete(store.msgStores, name)
}
func (store *DirStore) Directory(name string) *models.Directory {
return store.dirs[name]
}