2016-11-19 14:54:31 +00:00
|
|
|
package threads
|
|
|
|
|
|
|
|
import (
|
2017-06-26 13:17:53 +00:00
|
|
|
"strings"
|
|
|
|
|
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")
|
|
|
|
thread, err := arn.GetThread(id)
|
2017-06-26 13:17:53 +00:00
|
|
|
user := utils.GetUser(ctx)
|
2016-11-19 14:54:31 +00:00
|
|
|
|
|
|
|
if err != nil {
|
2016-11-23 05:26:59 +00:00
|
|
|
return ctx.Error(404, "Thread not found", err)
|
2016-11-19 14:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
replies, filterErr := arn.FilterPosts(func(post *arn.Post) bool {
|
2017-06-26 13:17:53 +00:00
|
|
|
post.Text = strings.Replace(post.Text, "http://", "https://", -1)
|
2016-11-19 14:54:31 +00:00
|
|
|
return post.ThreadID == thread.ID
|
|
|
|
})
|
|
|
|
|
2016-12-06 03:36:31 +00:00
|
|
|
arn.SortPostsLatestLast(replies)
|
2016-11-19 14:54:31 +00:00
|
|
|
|
2017-06-26 13:17:53 +00:00
|
|
|
for i := 0; i < 7; i++ {
|
|
|
|
replies = append(replies, replies...)
|
|
|
|
}
|
|
|
|
|
|
|
|
println(len(replies))
|
|
|
|
|
|
|
|
// Pre-render markdown
|
|
|
|
// flow.Parallel(func() {
|
|
|
|
// for _, reply := range replies[0:256] {
|
|
|
|
// reply.HTML()
|
|
|
|
// }
|
|
|
|
// }, func() {
|
|
|
|
// for _, reply := range replies[256:512] {
|
|
|
|
// reply.HTML()
|
|
|
|
// }
|
|
|
|
// }, func() {
|
|
|
|
// for _, reply := range replies[512:768] {
|
|
|
|
// reply.HTML()
|
|
|
|
// }
|
|
|
|
// }, func() {
|
|
|
|
// for _, reply := range replies[768:1024] {
|
|
|
|
// reply.HTML()
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
2016-11-19 14:54:31 +00:00
|
|
|
if filterErr != nil {
|
2016-11-23 05:26:59 +00:00
|
|
|
return ctx.Error(500, "Error fetching thread replies", err)
|
2016-11-19 14:54:31 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 13:17:53 +00:00
|
|
|
return ctx.HTML(components.Thread(thread, replies, user))
|
2016-11-19 14:54:31 +00:00
|
|
|
}
|