aboutsummaryrefslogtreecommitdiffstats
path: root/lib/threadbuilder.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-10-20 16:43:41 +0200
committerRobin Jarry <robin@jarry.cc>2022-10-27 22:44:39 +0200
commitc5face0b6f922781f1d2ae754c00fdee6c58af20 (patch)
tree13fd5d1026319f36921be6776b13ae87c68f16ec /lib/threadbuilder.go
parentc83ffabf3853e5f06294bba78dc23bc7ff84b0af (diff)
downloadaerc-c5face0b6f922781f1d2ae754c00fdee6c58af20.tar.gz
store: reverse message list order with iterators
Reverse the order of the messages in the message list. The complexity of reversing the order is abstracted away by the iterators. To reverse the message list, add the following to your aerc.conf: [ui] reverse-msglist-order=true Thanks to |cos| for sharing his initial implementation of reversing the order in the message list [0]. [0]: https://git.netizen.se/aerc/commit/?h=topic/asc_sort_imap Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/threadbuilder.go')
-rw-r--r--lib/threadbuilder.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/threadbuilder.go b/lib/threadbuilder.go
index 6cd98e87..75a80797 100644
--- a/lib/threadbuilder.go
+++ b/lib/threadbuilder.go
@@ -4,6 +4,7 @@ import (
"sync"
"time"
+ "git.sr.ht/~rjarry/aerc/lib/iterator"
"git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -16,13 +17,15 @@ type ThreadBuilder struct {
messageidToUid map[string]uint32
seen map[uint32]bool
threadedUids []uint32
+ iterFactory iterator.Factory
}
-func NewThreadBuilder() *ThreadBuilder {
+func NewThreadBuilder(i iterator.Factory) *ThreadBuilder {
tb := &ThreadBuilder{
threadBlocks: make(map[uint32]jwz.Threadable),
messageidToUid: make(map[string]uint32),
seen: make(map[uint32]bool),
+ iterFactory: i,
}
return tb
}
@@ -154,17 +157,20 @@ func (builder *ThreadBuilder) sortThreads(threads []*types.Thread, orderedUids [
// RebuildUids rebuilds the uids from the given slice of threads
func (builder *ThreadBuilder) RebuildUids(threads []*types.Thread) {
uids := make([]uint32, 0, len(threads))
- for i := len(threads) - 1; i >= 0; i-- {
- _ = threads[i].Walk(func(t *types.Thread, level int, currentErr error) error {
- uids = append(uids, t.Uid)
- return nil
- })
+ iterT := builder.iterFactory.NewIterator(threads)
+ for iterT.Next() {
+ _ = iterT.Value().(*types.Thread).Walk(
+ func(t *types.Thread, level int, currentErr error) error {
+ uids = append(uids, t.Uid)
+ return nil
+ })
}
- // copy in reverse as msgList displays backwards
- for i, j := 0, len(uids)-1; i < j; i, j = i+1, j-1 {
- uids[i], uids[j] = uids[j], uids[i]
+ result := make([]uint32, 0, len(uids))
+ iterU := builder.iterFactory.NewIterator(uids)
+ for iterU.Next() {
+ result = append(result, iterU.Value().(uint32))
}
- builder.threadedUids = uids
+ builder.threadedUids = result
}
// threadable implements the jwz.threadable interface which is required for the