From 65ae87a524ebbb573626afe951d6cd29bc8b24cd Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Tue, 8 Mar 2022 18:13:39 +0100 Subject: 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 Signed-off-by: Koni Marti Acked-by: Robin Jarry --- worker/types/thread.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'worker') 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])] + }) +} -- cgit v1.2.3