aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorinwit <inwit@sindominio.net>2023-11-09 21:35:04 +0100
committerRobin Jarry <robin@jarry.cc>2023-11-12 12:53:11 +0100
commitc13df799763c6b584cf4963e125361bb16c0e07d (patch)
tree31262c5de8a47ff7b4d1ca9be75924d80c95173d /app
parent063187340ce257a633cc5e6b503112db306be2e6 (diff)
downloadaerc-c13df799763c6b584cf4963e125361bb16c0e07d.tar.gz
threads: add .ThreadUnread to template data
When a thread is folded, it can be useful to know how many unseen messages lie below the root. For example, one might want to show that count in the message list: column-folded = {{if .ThreadFolded \ }}{{if ne .ThreadUnread 0 \ }}{{.ThreadUnread | printf "%s/"}}{{ \ end}}{{ .ThreadCount | printf "%s"}}{{end}} Add `.ThreadUnread` to the template functions. Changelog-added: `.ThreadUnread` is now available in templates. Signed-off-by: inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'app')
-rw-r--r--app/msglist.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/app/msglist.go b/app/msglist.go
index 146d032d..40253ed6 100644
--- a/app/msglist.go
+++ b/app/msglist.go
@@ -403,6 +403,20 @@ func countThreads(thread *types.Thread) (ctr int) {
return
}
+func unreadInThread(thread *types.Thread, store *lib.MessageStore) (ctr int) {
+ if thread == nil {
+ return
+ }
+ _ = thread.Walk(func(t *types.Thread, _ int, _ error) error {
+ msg := store.Messages[t.Uid]
+ if msg != nil && !msg.Flags.Has(models.SeenFlag) {
+ ctr++
+ }
+ return nil
+ })
+ return
+}
+
func threadPrefix(t *types.Thread, reverse bool, point bool) string {
var arrow string
if t.Parent != nil {
@@ -476,7 +490,7 @@ func newThreadView(store *lib.MessageStore) *threadView {
}
func (t *threadView) Update(data state.DataSetter, uid uint32) {
- prefix, same, count, folded, context := "", false, 0, false, false
+ prefix, same, count, unread, folded, context := "", false, 0, 0, false, false
thread, err := t.store.Thread(uid)
if thread != nil && err == nil {
prefix = threadPrefix(thread, t.reverse, true)
@@ -485,8 +499,9 @@ func (t *threadView) Update(data state.DataSetter, uid uint32) {
t.prev = thread
t.prevSubj = subject
count = countThreads(thread)
+ unread = unreadInThread(thread, t.store)
folded = thread.FirstChild != nil && thread.FirstChild.Hidden != 0
context = thread.Context
}
- data.SetThreading(prefix, same, count, folded, context)
+ data.SetThreading(prefix, same, count, unread, folded, context)
}