about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--models/models.go3
-rw-r--r--widgets/dirlist.go61
2 files changed, 39 insertions, 25 deletions
diff --git a/models/models.go b/models/models.go
index 8d254a1..7654cf0 100644
--- a/models/models.go
+++ b/models/models.go
@@ -50,6 +50,9 @@ type DirectoryInfo struct {
 
 	// The number of unread messages
 	Unseen int
+
+	// set to true if the value counts are accurate
+	AccurateCounts bool
 }
 
 // A MessageInfo holds information about the structure of a message
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index e8a9309..81a97cc 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
+}