aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-10-20 16:43:44 +0200
committerRobin Jarry <robin@jarry.cc>2022-10-27 22:44:39 +0200
commit006e10357b0e89ba3a8216ff5a6435c5d8f77187 (patch)
tree62cd69a39c68948e0e36e03a7106fc80ccc35b6e /lib
parent88afe7bb4a7425fbce767a64ed454151514fa4f2 (diff)
downloadaerc-006e10357b0e89ba3a8216ff5a6435c5d8f77187.tar.gz
threads: reverse thread ordering
Add reverse-thread-order option to the ui config to enable reverse display of the mesage threads. Default order is the the intial message is on the top with all the replies being displayed below. The reverse options will put the initial message at the bottom with the replies on top. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/msgstore.go26
-rw-r--r--lib/threadbuilder.go16
2 files changed, 30 insertions, 12 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index d6ca26e2..a22e1961 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -39,9 +39,10 @@ type MessageStore struct {
sortCriteria []*types.SortCriterion
- threadedView bool
- buildThreads bool
- builder *ThreadBuilder
+ threadedView bool
+ reverseThreadOrder bool
+ buildThreads bool
+ builder *ThreadBuilder
// Map of uids we've asked the worker to fetch
onUpdate func(store *MessageStore) // TODO: multiple onUpdate handlers
@@ -74,7 +75,7 @@ func NewMessageStore(worker *types.Worker,
dirInfo *models.DirectoryInfo,
defaultSortCriteria []*types.SortCriterion,
thread bool, clientThreads bool, clientThreadsDelay time.Duration,
- reverseOrder bool,
+ reverseOrder bool, reverseThreadOrder bool,
triggerNewEmail func(*models.MessageInfo),
triggerDirectoryChange func(),
) *MessageStore {
@@ -91,8 +92,9 @@ func NewMessageStore(worker *types.Worker,
bodyCallbacks: make(map[uint32][]func(*types.FullMessage)),
- threadedView: thread,
- buildThreads: clientThreads,
+ threadedView: thread,
+ buildThreads: clientThreads,
+ reverseThreadOrder: reverseThreadOrder,
filter: []string{"filter"},
sortCriteria: defaultSortCriteria,
@@ -231,7 +233,7 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
newMap := make(map[uint32]*models.MessageInfo)
builder := NewThreadBuilder(store.iterFactory)
- builder.RebuildUids(msg.Threads)
+ builder.RebuildUids(msg.Threads, store.reverseThreadOrder)
store.uids = builder.Uids()
store.threads = msg.Threads
@@ -364,6 +366,14 @@ func (store *MessageStore) update(threads bool) {
}
}
+func (store *MessageStore) SetReverseThreadOrder(reverse bool) {
+ store.reverseThreadOrder = reverse
+}
+
+func (store *MessageStore) ReverseThreadOrder() bool {
+ return store.reverseThreadOrder
+}
+
func (store *MessageStore) SetThreadedView(thread bool) {
store.threadedView = thread
if store.buildThreads {
@@ -424,7 +434,7 @@ func (store *MessageStore) runThreadBuilderNow() {
}
}
// build new threads
- th := store.builder.Threads(store.uids)
+ th := store.builder.Threads(store.uids, store.reverseThreadOrder)
// save local threads to the message store variable and
// run callback if defined (callback should reposition cursor)
diff --git a/lib/threadbuilder.go b/lib/threadbuilder.go
index 75a80797..b1609257 100644
--- a/lib/threadbuilder.go
+++ b/lib/threadbuilder.go
@@ -55,7 +55,7 @@ func (builder *ThreadBuilder) Update(msg *models.MessageInfo) {
}
// Threads returns a slice of threads for the given list of uids
-func (builder *ThreadBuilder) Threads(uids []uint32) []*types.Thread {
+func (builder *ThreadBuilder) Threads(uids []uint32, inverse bool) []*types.Thread {
builder.Lock()
defer builder.Unlock()
@@ -67,7 +67,7 @@ func (builder *ThreadBuilder) Threads(uids []uint32) []*types.Thread {
builder.sortThreads(threads, uids)
// rebuild uids from threads
- builder.RebuildUids(threads)
+ builder.RebuildUids(threads, inverse)
elapsed := time.Since(start)
logging.Infof("%d threads created in %s", len(threads), elapsed)
@@ -155,15 +155,23 @@ 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) {
+func (builder *ThreadBuilder) RebuildUids(threads []*types.Thread, inverse bool) {
uids := make([]uint32, 0, len(threads))
iterT := builder.iterFactory.NewIterator(threads)
for iterT.Next() {
+ var threaduids []uint32
_ = iterT.Value().(*types.Thread).Walk(
func(t *types.Thread, level int, currentErr error) error {
- uids = append(uids, t.Uid)
+ threaduids = append(threaduids, t.Uid)
return nil
})
+ if inverse {
+ for j := len(threaduids) - 1; j >= 0; j-- {
+ uids = append(uids, threaduids[j])
+ }
+ } else {
+ uids = append(uids, threaduids...)
+ }
}
result := make([]uint32, 0, len(uids))
iterU := builder.iterFactory.NewIterator(uids)