2016-11-19 23:54:31 +09:00
|
|
|
package threads
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
)
|
|
|
|
|
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")
|
|
|
|
thread, err := arn.GetThread(id)
|
|
|
|
|
|
|
|
if err != nil {
|
2016-11-23 14:26:59 +09:00
|
|
|
return ctx.Error(404, "Thread not found", err)
|
2016-11-19 23:54:31 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
replies, filterErr := arn.FilterPosts(func(post *arn.Post) bool {
|
|
|
|
return post.ThreadID == thread.ID
|
|
|
|
})
|
|
|
|
|
2016-12-06 12:36:31 +09:00
|
|
|
arn.SortPostsLatestLast(replies)
|
2016-11-19 23:54:31 +09:00
|
|
|
|
|
|
|
if filterErr != nil {
|
2016-11-23 14:26:59 +09:00
|
|
|
return ctx.Error(500, "Error fetching thread replies", err)
|
2016-11-19 23:54:31 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.HTML(components.Thread(thread, replies))
|
|
|
|
}
|