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 7811620eb8
("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>
This commit is contained in:
parent
cc172970a0
commit
65ae87a524
3 changed files with 70 additions and 50 deletions
worker/types
|
@ -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])]
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue