37 lines
725 B
Go
Raw Normal View History

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