41 lines
787 B
Go
Raw Normal View History

2016-11-20 10:26:11 +00:00
package profile
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-06-08 12:46:38 +00:00
"github.com/animenotifier/notify.moe/utils"
2016-11-20 10:26:11 +00:00
)
2017-06-08 12:46:38 +00:00
const maxPosts = 5
2016-11-20 10:26:11 +00:00
// Get ...
func Get(ctx *aero.Context) string {
nick := ctx.Get("nick")
2017-06-08 12:46:38 +00:00
viewUser, err := arn.GetUserByNick(nick)
2016-11-20 10:26:11 +00:00
if err != nil {
2016-11-23 05:26:59 +00:00
return ctx.Error(404, "User not found", err)
2016-11-20 10:26:11 +00:00
}
2017-06-10 00:19:31 +00:00
var user *arn.User
var threads []*arn.Thread
var animeList *arn.AnimeList
2017-06-08 12:46:38 +00:00
2017-06-10 00:19:31 +00:00
aero.Async(func() {
user = utils.GetUser(ctx)
}, func() {
animeList = viewUser.AnimeList()
}, func() {
threads = viewUser.Threads()
2017-06-08 12:46:38 +00:00
2017-06-10 00:19:31 +00:00
arn.SortThreadsByDate(threads)
2017-06-08 12:46:38 +00:00
2017-06-10 00:19:31 +00:00
if len(threads) > maxPosts {
threads = threads[:maxPosts]
}
})
2017-06-08 19:54:39 +00:00
return ctx.HTML(components.Profile(viewUser, user, animeList, threads))
2016-11-20 10:26:11 +00:00
}