Sort comments on Rophako ingest

This commit is contained in:
Noah 2017-12-24 10:24:42 -08:00
parent baaf7bcfac
commit c664c07a74
2 changed files with 10 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"time"
@ -189,6 +190,9 @@ func migrateComments() {
t.Post(new)
}
// Re-sort the comments by date.
sort.Sort(comments.ByCreated(t.Comments))
// Check for subscribers
subs := legacySubscribers{}
err = inDB.Get(fmt.Sprintf("comments/subscribers/%s", id), &subs)

View File

@ -60,6 +60,12 @@ type Comment struct {
Editing bool `json:"-"`
}
type ByCreated []*Comment
func (a ByCreated) Len() int { return len(a) }
func (a ByCreated) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByCreated) Less(i, j int) bool { return a[i].Created.Before(a[j].Created) }
// New initializes a new comment thread.
func New(id string) Thread {
return Thread{