aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-12-31 15:29:27 +0100
committerRobin Jarry <robin@jarry.cc>2024-01-07 12:04:54 +0100
commitf41a39578f0319d255f32fc08cef6b7b73d6bdac (patch)
tree3dff80300636a48a73cf2827ee8433eae3d56d0e
parentef4b7dc5d46b7d40c79131d812a6296d1bb9668c (diff)
downloadaerc-f41a39578f0319d255f32fc08cef6b7b73d6bdac.tar.gz
commands: treat folded threads as one entity
Treat folded threads as one entity and apply any operation on its hidden children as well. Fixes: https://todo.sr.ht/~rjarry/aerc/206 Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--commands/util.go31
1 files changed, 30 insertions, 1 deletions
diff --git a/commands/util.go b/commands/util.go
index c2c530da..6247f579 100644
--- a/commands/util.go
+++ b/commands/util.go
@@ -177,13 +177,42 @@ func MarkedOrSelected(pm app.ProvidesMessages) ([]uint32, error) {
return nil, err
}
if len(marked) > 0 {
+ marked = expandFoldedThreads(pm, marked)
return marked, nil
}
msg, err := pm.SelectedMessage()
if err != nil {
return nil, err
}
- return []uint32{msg.Uid}, nil
+ return expandFoldedThreads(pm, []uint32{msg.Uid}), nil
+}
+
+func expandFoldedThreads(pm app.ProvidesMessages, uids []uint32) []uint32 {
+ store := pm.Store()
+ if store == nil {
+ return uids
+ }
+ expanded := make([]uint32, len(uids))
+ copy(expanded, uids)
+ for _, uid := range uids {
+ thread, err := store.Thread(uid)
+ if err != nil {
+ continue
+ }
+ if thread != nil && thread.FirstChild != nil && thread.FirstChild.Hidden > 0 {
+ _ = thread.Walk(func(t *types.Thread, _ int, __ error) error {
+ if t.Uid != uid {
+ expanded = append(expanded, t.Uid)
+ }
+ return nil
+ })
+ }
+
+ }
+ if len(uids) != len(expanded) {
+ log.Debugf("expand folded threads: %v -> %v\n", uids, expanded)
+ }
+ return expanded
}
// UidsFromMessageInfos extracts a uid slice from a slice of MessageInfos