diff --git a/cmd/rophako-import/main.go b/cmd/rophako-import/main.go index 39e1559..e3955be 100644 --- a/cmd/rophako-import/main.go +++ b/cmd/rophako-import/main.go @@ -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) diff --git a/core/models/comments/comments.go b/core/models/comments/comments.go index 9f136d7..816b5ef 100644 --- a/core/models/comments/comments.go +++ b/core/models/comments/comments.go @@ -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{