aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/dirlist.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-04-16 09:53:44 -0500
committerRobin Jarry <robin@jarry.cc>2023-04-22 22:40:12 +0200
commit5b0a98b8c936532fa5444b1cabf53d7c929d19c1 (patch)
treeb04415f6120d944cd74c45464a771d064cdd4305 /widgets/dirlist.go
parentf13fbe7a27756c63d85f40c15320664d634f59e2 (diff)
downloadaerc-5b0a98b8c936532fa5444b1cabf53d7c929d19c1.tar.gz
directory: use directory to store rue counts
Store the Directory RUE counts on the Directory data model. Use DirectoryInfo messages to update the Directory model. Access Directories via the dirlist instead of via the msgstore. Remove unused fields on DirectoryInfo, all backends now give accurate counts. Move refetch logic into dirlist Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry<robin@jarry.cc>
Diffstat (limited to 'widgets/dirlist.go')
-rw-r--r--widgets/dirlist.go49
1 files changed, 27 insertions, 22 deletions
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index 85cf4112..ee2acb1b 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -39,6 +39,8 @@ type DirectoryLister interface {
SelectedMsgStore() (*lib.MessageStore, bool)
MsgStore(string) (*lib.MessageStore, bool)
+ SelectedDirectory() *models.Directory
+ Directory(string) *models.Directory
SetMsgStore(*models.Directory, *lib.MessageStore)
FilterDirs([]string, []string, bool) []string
@@ -112,6 +114,20 @@ func (dirlist *DirectoryList) Update(msg types.WorkerMessage) {
dirlist.filterDirsByFoldersConfig()
dirlist.sortDirsByFoldersSortConfig()
}
+ case *types.DirectoryInfo:
+ dir := dirlist.Directory(msg.Info.Name)
+ if dir == nil {
+ return
+ }
+ dir.Exists = msg.Info.Exists
+ dir.Recent = msg.Info.Recent
+ dir.Unseen = msg.Info.Unseen
+ if msg.Refetch {
+ store, ok := dirlist.SelectedMsgStore()
+ if ok {
+ store.Sort(store.GetCurrentSortCriteria(), nil)
+ }
+ }
default:
return
}
@@ -183,15 +199,11 @@ func (dirlist *DirectoryList) Invalidate() {
// Returns the Recent, Unread, and Exist counts for the named directory
func (dirlist *DirectoryList) GetRUECount(name string) (int, int, int) {
- msgStore, ok := dirlist.MsgStore(name)
- if !ok {
+ dir := dirlist.Directory(name)
+ if dir == nil {
return 0, 0, 0
}
- if !msgStore.DirInfo.AccurateCounts {
- msgStore.DirInfo.Recent, msgStore.DirInfo.Unseen = countRUE(msgStore)
- }
- di := msgStore.DirInfo
- return di.Recent, di.Unseen, di.Exists
+ return dir.Recent, dir.Unseen, dir.Exists
}
func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
@@ -478,6 +490,14 @@ func (dirlist *DirectoryList) MsgStore(name string) (*lib.MessageStore, bool) {
return dirlist.store.MessageStore(name)
}
+func (dirlist *DirectoryList) SelectedDirectory() *models.Directory {
+ return dirlist.store.Directory(dirlist.selected)
+}
+
+func (dirlist *DirectoryList) Directory(name string) *models.Directory {
+ return dirlist.store.Directory(name)
+}
+
func (dirlist *DirectoryList) SetMsgStore(dir *models.Directory, msgStore *lib.MessageStore) {
dirlist.store.SetMessageStore(dir, msgStore)
msgStore.OnUpdateDirs(func() {
@@ -493,18 +513,3 @@ func findString(slice []string, str string) int {
}
return -1
}
-
-func countRUE(msgStore *lib.MessageStore) (recent, unread int) {
- for _, msg := range msgStore.Messages {
- if msg == nil {
- continue
- }
- if msg.Flags.Has(models.RecentFlag) {
- recent++
- }
- if !msg.Flags.Has(models.SeenFlag) {
- unread++
- }
- }
- return recent, unread
-}