37 lines
744 B
Go
Raw Normal View History

2016-11-19 14:54:31 +00:00
package threads
import (
2017-06-26 21:41:16 +00:00
"net/http"
2017-06-26 13:17:53 +00:00
2016-11-19 14:54:31 +00:00
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-06-26 13:17:53 +00:00
"github.com/animenotifier/notify.moe/utils"
2016-11-19 14:54:31 +00:00
)
2017-06-16 23:25:02 +00:00
// Get thread.
2016-11-19 14:54:31 +00:00
func Get(ctx *aero.Context) string {
id := ctx.Get("id")
2017-06-26 13:17:53 +00:00
user := utils.GetUser(ctx)
2016-11-19 14:54:31 +00:00
2017-06-26 21:41:16 +00:00
// Fetch thread
thread, err := arn.GetThread(id)
2016-11-19 14:54:31 +00:00
if err != nil {
2017-06-26 21:41:16 +00:00
return ctx.Error(http.StatusNotFound, "Thread not found", err)
2016-11-19 14:54:31 +00:00
}
2017-06-26 21:41:16 +00:00
// Fetch posts
2017-10-27 07:11:56 +00:00
postObjects := arn.DB.GetMany("Post", thread.Posts)
posts := make([]*arn.Post, len(postObjects), len(postObjects))
2016-11-19 14:54:31 +00:00
2017-10-27 07:11:56 +00:00
for i, obj := range postObjects {
posts[i] = obj.(*arn.Post)
2017-06-26 21:41:16 +00:00
}
2016-11-19 14:54:31 +00:00
2017-06-26 21:41:16 +00:00
// Sort posts
arn.SortPostsLatestLast(posts)
2016-11-19 14:54:31 +00:00
2017-06-26 21:41:16 +00:00
return ctx.HTML(components.Thread(thread, posts, user))
2016-11-19 14:54:31 +00:00
}