Sort items in timeline

This commit is contained in:
Peter Stuifzand 2018-02-19 21:24:53 +01:00
parent 36af7ae115
commit 062e60ee81

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"sort"
"strings"
"github.com/pstuifzand/microsub-server/microsub"
@ -158,6 +159,15 @@ func (b *memoryBackend) TimelineGet(after, before, channel string) microsub.Time
}
}
sort.Slice(items, func(a, b int) bool {
timeA, okA := items[a]["published"].(string)
timeB, okB := items[b]["published"].(string)
if okA && okB {
return strings.Compare(timeA, timeB) > 0
}
return false
})
return microsub.Timeline{
Paging: microsub.Pagination{},
Items: items,