From 7f66297c521fca8f9bc17280f0a96874598bde96 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Tue, 18 Jul 2023 10:29:52 +0200 Subject: threadbuilder: show siblings even when no parent found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Show all threading associations even when not all nodes are present. Indicate if a thread is incomplete, i.e. misses a direct parent node. Use the `msglist_thread_orphan.fg=red` styleobject in your stylesheet to indicate whether a messsage has a missing parent. Also use a different thread prefix ("┬─" instead of "├─") not to confuse them with regular threads that have a visible parent. Signed-off-by: Koni Marti Signed-off-by: Robin Jarry Tested-by: Matěj Cepl --- lib/state/templates.go | 18 ++++++++---------- lib/threadbuilder.go | 36 +++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/state/templates.go b/lib/state/templates.go index e5206cf0..868f9184 100644 --- a/lib/state/templates.go +++ b/lib/state/templates.go @@ -28,7 +28,7 @@ type DataSetter interface { SetHeaders(*mail.Header, *models.OriginalMail) SetInfo(*models.MessageInfo, int, bool) SetVisual(bool) - SetThreading(string, bool, int, int, bool, bool) + SetThreading(ThreadInfo) SetComposer(Composer) SetAccount(*config.AccountConfig) SetFolder(*models.Directory) @@ -44,6 +44,7 @@ type ThreadInfo struct { Unread int Folded bool Context bool + Orphan bool } type templateData struct { @@ -100,15 +101,8 @@ func (d *templateData) SetVisual(visual bool) { d.visual = visual } -func (d *templateData) SetThreading(prefix string, same bool, count int, - unread int, folded bool, context bool, -) { - d.threadInfo.Prefix = prefix - d.threadInfo.SameSubject = same - d.threadInfo.Count = count - d.threadInfo.Unread = unread - d.threadInfo.Folded = folded - d.threadInfo.Context = context +func (d *templateData) SetThreading(info ThreadInfo) { + d.threadInfo = info } func (d *templateData) SetAccount(acct *config.AccountConfig) { @@ -334,6 +328,10 @@ func (d *templateData) ThreadContext() bool { return d.threadInfo.Context } +func (d *templateData) ThreadOrphan() bool { + return d.threadInfo.Orphan +} + func (d *templateData) Subject() string { var subject string switch { diff --git a/lib/threadbuilder.go b/lib/threadbuilder.go index c18ab3d0..b7dae431 100644 --- a/lib/threadbuilder.go +++ b/lib/threadbuilder.go @@ -165,23 +165,30 @@ func (builder *ThreadBuilder) buildTree(c jwz.Threadable, parent *types.Thread, return } for node := c; node != nil; node = node.GetNext() { - thread := parent - if !node.IsDummy() { - thread = builder.newThread(node, parent) - if rootLevel { - thread.NextSibling = parent.FirstChild - parent.FirstChild = thread - } else { - parent.InsertCmp(thread, bigger) - } + thread := builder.newThread(node, parent, node.IsDummy()) + if rootLevel { + thread.NextSibling = parent.FirstChild + parent.FirstChild = thread + } else { + parent.InsertCmp(thread, bigger) } builder.buildTree(node.GetChild(), thread, bigger, node.IsDummy()) } } -func (builder *ThreadBuilder) newThread(c jwz.Threadable, parent *types.Thread) *types.Thread { +func (builder *ThreadBuilder) newThread(c jwz.Threadable, parent *types.Thread, + hidden bool, +) *types.Thread { + hide := 0 + if hidden { + hide += 1 + } if threadable, ok := c.(*threadable); ok { - return &types.Thread{Uid: threadable.MsgInfo.Uid, Parent: parent} + return &types.Thread{ + Uid: threadable.UID(), + Parent: parent, + Hidden: hide, + } } return nil } @@ -297,6 +304,13 @@ func cleanRefs(m, irp string, refs []string) []string { return cleanRefs } +func (t *threadable) UID() uint32 { + if t.MsgInfo == nil { + return 0 + } + return t.MsgInfo.Uid +} + func (t *threadable) Subject() string { // deactivate threading by subject for now return "" -- cgit