54 lines
1.1 KiB
Go
Raw Normal View History

2016-11-20 19:26:11 +09:00
package profile
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-06-08 14:46:38 +02:00
"github.com/animenotifier/notify.moe/utils"
2016-11-20 19:26:11 +09:00
)
2017-06-08 14:46:38 +02:00
const maxPosts = 5
2017-06-17 01:25:02 +02:00
// Get user profile page.
2016-11-20 19:26:11 +09:00
func Get(ctx *aero.Context) string {
nick := ctx.Get("nick")
2017-06-08 14:46:38 +02:00
viewUser, err := arn.GetUserByNick(nick)
2016-11-20 19:26:11 +09:00
if err != nil {
2016-11-23 14:26:59 +09:00
return ctx.Error(404, "User not found", err)
2016-11-20 19:26:11 +09:00
}
2017-06-20 14:16:23 +02:00
return Profile(ctx, viewUser)
}
// Profile renders the user profile page of the given viewUser.
func Profile(ctx *aero.Context, viewUser *arn.User) string {
2017-06-10 02:19:31 +02:00
var user *arn.User
var threads []*arn.Thread
var animeList *arn.AnimeList
2017-06-22 11:21:26 -03:00
var posts []*arn.Post
2017-06-22 12:03:43 -03:00
2017-06-11 11:13:59 +02:00
aero.Parallel(func() {
2017-06-10 02:19:31 +02:00
user = utils.GetUser(ctx)
}, func() {
animeList = viewUser.AnimeList()
}, func() {
threads = viewUser.Threads()
2017-06-08 14:46:38 +02:00
2017-06-10 02:19:31 +02:00
arn.SortThreadsByDate(threads)
2017-06-08 14:46:38 +02:00
2017-06-10 02:19:31 +02:00
if len(threads) > maxPosts {
threads = threads[:maxPosts]
}
2017-06-22 12:03:43 -03:00
}, func() {
posts = viewUser.Posts()
2017-06-22 17:49:32 +02:00
arn.SortPostsLatestFirst(posts)
2017-06-22 12:03:43 -03:00
if len(posts) > maxPosts {
posts = posts[:maxPosts]
}
})
2017-06-22 11:21:26 -03:00
return ctx.HTML(components.Profile(viewUser, user, animeList, threads, posts))
2016-11-20 19:26:11 +09:00
}