Debian Codegraph @

lib/dirstore.go

raw
1 package lib
2
3 import (
4 "git.sr.ht/~rjarry/aerc/lib/sort"
5 "git.sr.ht/~rjarry/aerc/models"
6 )
7
8 type DirStore struct {
9 dirs map[string]*models.Directory
10 msgStores map[string]*MessageStore
11 order []string
12 }
13
14 func NewDirStore() *DirStore {
15 return &DirStore{
16 dirs: make(map[string]*models.Directory),
17 msgStores: make(map[string]*MessageStore),
18 }
19 }
20
21 func (store *DirStore) List() []string {
22 dirs := []string{}
23 for dir := range store.msgStores {
24 dirs = append(dirs, dir)
25 }
26 sort.SortStringBy(dirs, store.order)
27 return dirs
28 }
29
30 func (store *DirStore) MessageStore(dirname string) (*MessageStore, bool) {
31 msgStore, ok := store.msgStores[dirname]
32 return msgStore, ok
33 }
34
35 func (store *DirStore) SetMessageStore(dir *models.Directory, msgStore *MessageStore) {
36 s := dir.Name
37 if _, ok := store.dirs[s]; !ok {
38 store.order = append(store.order, s)
39 }
40 store.dirs[dir.Name] = dir
41 store.msgStores[dir.Name] = msgStore
42 }
43
44 func (store *DirStore) Remove(name string) {
45 delete(store.dirs, name)
46 delete(store.msgStores, name)
47 }
48
49 func (store *DirStore) Directory(name string) *models.Directory {
50 return store.dirs[name]
51 }