32 lines
583 B
Go
Raw Normal View History

2018-04-25 16:59:23 +00:00
package thread
2016-11-19 14:54:31 +00:00
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
2018-10-29 00:15:45 +00:00
posts := thread.Posts()
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
}