40 lines
854 B
Go
Raw Normal View History

2016-11-19 23:54:31 +09:00
package threads
import (
2017-06-26 15:17:53 +02:00
"strings"
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")
thread, err := arn.GetThread(id)
2017-06-26 15:17:53 +02:00
user := utils.GetUser(ctx)
2016-11-19 23:54:31 +09:00
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 {
2017-06-26 15:17:53 +02:00
post.Text = strings.Replace(post.Text, "http://", "https://", -1)
2016-11-19 23:54:31 +09:00
return post.ThreadID == thread.ID
})
2016-12-06 12:36:31 +09:00
arn.SortPostsLatestLast(replies)
2016-11-19 23:54:31 +09:00
2017-06-26 16:23:38 +02:00
// Benchmark
// for i := 0; i < 7; i++ {
// replies = append(replies, replies...)
// }
2017-06-26 15:17:53 +02:00
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
}
2017-06-26 15:17:53 +02:00
return ctx.HTML(components.Thread(thread, replies, user))
2016-11-19 23:54:31 +09:00
}