summaryrefslogtreecommitdiff
path: root/worker
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-03-08 18:13:39 +0100
committerRobin Jarry <robin@jarry.cc>2022-03-09 00:08:26 +0100
commit65ae87a524ebbb573626afe951d6cd29bc8b24cd (patch)
tree516a6d9fde3c03ce2c21bff7048e549b52f1dc2f /worker
parentcc172970a079bb78847f2276db8bfae375cda185 (diff)
downloadaerc-65ae87a524ebbb573626afe951d6cd29bc8b24cd.zip
threading: honor user-defined sort criteria
Apply the user-defined sort criteria to the message with the highest uid in a threaded discussion. Restore the default sort order when leaving threading mode. Commit 7811620eb809 ("threading: implement on-the-fly message threading") introduced message threading with the threaded messages being only sorted by their message uids irrespective of the defined sorting criteria. It did not restore the default sort order either. Reported-by: Sebastien Binet <s@sbinet.org> Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r--worker/types/thread.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/worker/types/thread.go b/worker/types/thread.go
index 48e4a00..7c0cc5b 100644
--- a/worker/types/thread.go
+++ b/worker/types/thread.go
@@ -3,6 +3,7 @@ package types
import (
"errors"
"fmt"
+ "sort"
)
type Thread struct {
@@ -120,3 +121,15 @@ func (s ByUID) Less(i, j int) bool {
maxUID_j := getMaxUID(s[j])
return maxUID_i < maxUID_j
}
+
+func SortThreadsBy(toSort []*Thread, sortBy []uint32) {
+ // build a map from sortBy
+ uidMap := make(map[uint32]int)
+ for i, uid := range sortBy {
+ uidMap[uid] = i
+ }
+ // sortslice of toSort with less function of indexing the map sortBy
+ sort.Slice(toSort, func(i, j int) bool {
+ return uidMap[getMaxUID(toSort[i])] < uidMap[getMaxUID(toSort[j])]
+ })
+}