From c13df799763c6b584cf4963e125361bb16c0e07d Mon Sep 17 00:00:00 2001 From: inwit Date: Thu, 9 Nov 2023 21:35:04 +0100 Subject: 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 Acked-by: Robin Jarry --- app/msglist.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'app') 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) } -- cgit