summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-04-16 09:53:42 -0500
committerRobin Jarry <robin@jarry.cc>2023-04-22 22:40:12 +0200
commit2438d3b74ff9faf598e67f4b6da9324aa98b8b86 (patch)
tree6eadb0bbe3b4ae4cfc4a9ae2ae6fb2773cb4da23
parent2ed7a741ff9eca1dd3fe9e94cdcfe4f365b74ff2 (diff)
downloadaerc-2438d3b74ff9faf598e67f4b6da9324aa98b8b86.tar.gz
aerc-2438d3b74ff9faf598e67f4b6da9324aa98b8b86.zip
dirstore: store directory model in dirstore
Use the dirstore to store models.Directory data structures. This will be used in subsequent commits for accessing directory data. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--lib/dirstore.go15
-rw-r--r--widgets/account.go2
-rw-r--r--widgets/dirlist.go6
3 files changed, 15 insertions, 8 deletions
diff --git a/lib/dirstore.go b/lib/dirstore.go
index cc06d579..76833622 100644
--- a/lib/dirstore.go
+++ b/lib/dirstore.go
@@ -1,12 +1,17 @@
package lib
+import "git.sr.ht/~rjarry/aerc/models"
+
type DirStore struct {
+ dirs map[string]*models.Directory
msgStores map[string]*MessageStore
}
func NewDirStore() *DirStore {
- msgStores := make(map[string]*MessageStore)
- return &DirStore{msgStores: msgStores}
+ return &DirStore{
+ dirs: make(map[string]*models.Directory),
+ msgStores: make(map[string]*MessageStore),
+ }
}
func (store *DirStore) List() []string {
@@ -22,10 +27,12 @@ func (store *DirStore) MessageStore(dirname string) (*MessageStore, bool) {
return msgStore, ok
}
-func (store *DirStore) SetMessageStore(name string, msgStore *MessageStore) {
- store.msgStores[name] = msgStore
+func (store *DirStore) SetMessageStore(dir *models.Directory, msgStore *MessageStore) {
+ store.dirs[dir.Name] = dir
+ store.msgStores[dir.Name] = msgStore
}
func (store *DirStore) Remove(name string) {
+ delete(store.dirs, name)
delete(store.msgStores, name)
}
diff --git a/widgets/account.go b/widgets/account.go
index ad9d200a..6449aeba 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -308,7 +308,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
acct.updateSplitView,
)
store.SetMarker(marker.New(store))
- acct.dirlist.SetMsgStore(msg.Dir.Name, store)
+ acct.dirlist.SetMsgStore(msg.Dir, store)
case *types.DirectoryInfo:
if store, ok := acct.dirlist.MsgStore(msg.Info.Name); ok {
store.Update(msg)
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index a548b7b7..85cf4112 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -39,7 +39,7 @@ type DirectoryLister interface {
SelectedMsgStore() (*lib.MessageStore, bool)
MsgStore(string) (*lib.MessageStore, bool)
- SetMsgStore(string, *lib.MessageStore)
+ SetMsgStore(*models.Directory, *lib.MessageStore)
FilterDirs([]string, []string, bool) []string
GetRUECount(string) (int, int, int)
@@ -478,8 +478,8 @@ func (dirlist *DirectoryList) MsgStore(name string) (*lib.MessageStore, bool) {
return dirlist.store.MessageStore(name)
}
-func (dirlist *DirectoryList) SetMsgStore(name string, msgStore *lib.MessageStore) {
- dirlist.store.SetMessageStore(name, msgStore)
+func (dirlist *DirectoryList) SetMsgStore(dir *models.Directory, msgStore *lib.MessageStore) {
+ dirlist.store.SetMessageStore(dir, msgStore)
msgStore.OnUpdateDirs(func() {
dirlist.Invalidate()
})