aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-02-15 14:14:43 +0100
committerDrew DeVault <sir@cmpwn.com>2020-02-16 10:41:16 -0500
commit66b68f35b3f3f3b97ec9951397fd75afeb0d0995 (patch)
tree126a15cbae36f3e4794668b80b26e85c42f02631 /widgets
parentbd4df530095ee343778a59120a9e641c01010b0f (diff)
downloadaerc-66b68f35b3f3f3b97ec9951397fd75afeb0d0995.tar.gz
dirlist: actually honor the DirInfo
Currently the dirlist ignores the counts provided by the dirInfo. However some of the workers can actually provide accurate counts much quicker than if we count the flags. Eventually we will also want to enable displaying counts for background folders, where the brute force counting won't work as none of the headers are fetched yet. This commit models it in an opt-in manner, if the flag isn't set then we still count the messages manually.
Diffstat (limited to 'widgets')
-rw-r--r--widgets/dirlist.go61
1 files changed, 36 insertions, 25 deletions
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index e8a93091..81a97cc5 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -171,32 +171,17 @@ func (dirlist *DirectoryList) getDirString(name string, width int, recentUnseen
}
func (dirlist *DirectoryList) getRUEString(name string) string {
- totalUnseen := 0
- totalRecent := 0
- totalExists := 0
- if msgStore, ok := dirlist.MsgStore(name); ok {
- for _, msg := range msgStore.Messages {
- if msg == nil {
- continue
- }
- seen := false
- recent := false
- for _, flag := range msg.Flags {
- if flag == models.SeenFlag {
- seen = true
- } else if flag == models.RecentFlag {
- recent = true
- }
- }
- if !seen {
- if recent {
- totalRecent++
- } else {
- totalUnseen++
- }
- }
- }
+ msgStore, ok := dirlist.MsgStore(name)
+ if !ok {
+ return ""
+ }
+ var totalRecent, totalUnseen, totalExists int
+ if msgStore.DirInfo.AccurateCounts {
+ totalRecent = msgStore.DirInfo.Recent
+ totalUnseen = msgStore.DirInfo.Unseen
totalExists = msgStore.DirInfo.Exists
+ } else {
+ totalRecent, totalUnseen, totalExists = countRUE(msgStore)
}
rueString := ""
if totalRecent > 0 {
@@ -395,3 +380,29 @@ func (dirlist *DirectoryList) getSortCriteria() []*types.SortCriterion {
}
return criteria
}
+
+func countRUE(msgStore *lib.MessageStore) (recent, unread, exist int) {
+ for _, msg := range msgStore.Messages {
+ if msg == nil {
+ continue
+ }
+ seen := false
+ isrecent := false
+ for _, flag := range msg.Flags {
+ if flag == models.SeenFlag {
+ seen = true
+ } else if flag == models.RecentFlag {
+ isrecent = true
+ }
+ }
+ if !seen {
+ if isrecent {
+ recent++
+ } else {
+ unread++
+ }
+ }
+ exist++
+ }
+ return recent, unread, exist
+}