From 8ced001d82b59f353c33ad34ca0c79313eef41af Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Sun, 16 Apr 2023 09:53:40 -0500 Subject: listDirectories: refactor listdirectories handling ListDirectories is called when connecting, reconnecting, and creation/deletion of a directory. The code is not in the same style as other areas of aerc. Refactor to match coding style of the rest of aerc by creating an Update function which handles necessary updates in the dirlist. This style does not use a callback, making it clearer what is happening in the message flow, and operates similar to how the msgstore receives updates. Use a map in the dirstore to reduce duplicate storage of directory names. Directly add or remove directories from the map when created / deleted to prevent a new ListDirectories message, and a flash of the UI. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- lib/dirstore.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/dirstore.go') diff --git a/lib/dirstore.go b/lib/dirstore.go index bb58a9dc..cc06d579 100644 --- a/lib/dirstore.go +++ b/lib/dirstore.go @@ -1,7 +1,6 @@ package lib type DirStore struct { - dirs []string msgStores map[string]*MessageStore } @@ -10,13 +9,12 @@ func NewDirStore() *DirStore { return &DirStore{msgStores: msgStores} } -func (store *DirStore) Update(dirs []string) { - store.dirs = make([]string, len(dirs)) - copy(store.dirs, dirs) -} - func (store *DirStore) List() []string { - return store.dirs + dirs := []string{} + for dir := range store.msgStores { + dirs = append(dirs, dir) + } + return dirs } func (store *DirStore) MessageStore(dirname string) (*MessageStore, bool) { @@ -27,3 +25,7 @@ func (store *DirStore) MessageStore(dirname string) (*MessageStore, bool) { func (store *DirStore) SetMessageStore(name string, msgStore *MessageStore) { store.msgStores[name] = msgStore } + +func (store *DirStore) Remove(name string) { + delete(store.msgStores, name) +} -- cgit