60 lines
1.2 KiB
Go
Raw Normal View History

2016-11-19 23:54:31 +09:00
package dashboard
import (
"github.com/aerogo/aero"
2017-06-26 12:50:15 -03:00
"github.com/aerogo/flow"
2017-06-08 01:14:45 +02:00
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-06-15 23:03:55 +02:00
"github.com/animenotifier/notify.moe/pages/frontpage"
2017-06-07 23:37:13 +02:00
"github.com/animenotifier/notify.moe/utils"
2016-11-19 23:54:31 +09:00
)
2016-12-06 12:36:31 +09:00
const maxPosts = 5
const maxFollowing = 5
2016-11-19 23:54:31 +09:00
func Get(ctx *aero.Context) string {
2017-06-08 01:14:45 +02:00
user := utils.GetUser(ctx)
2017-06-15 23:03:55 +02:00
if user == nil {
return frontpage.Get(ctx)
}
2017-06-26 12:50:15 -03:00
return Dashboard(ctx)
}
2017-06-07 21:12:59 +02:00
2017-06-26 12:50:15 -03:00
// Get dashboard.
func Dashboard(ctx *aero.Context) string {
2017-06-26 13:53:06 -03:00
user := utils.GetUser(ctx)
2017-06-26 12:50:15 -03:00
var posts []*arn.Post
var err error
2017-06-26 13:53:06 -03:00
var followIDList []string
var userList interface{}
var followingList []*arn.User
2017-06-07 21:12:59 +02:00
2017-06-26 12:50:15 -03:00
flow.Parallel(func() {
posts, err = arn.AllPostsSlice()
arn.SortPostsLatestFirst(posts)
2017-06-07 21:12:59 +02:00
2017-06-26 12:50:15 -03:00
if len(posts) > maxPosts {
posts = posts[:maxPosts]
}
2017-06-24 18:57:36 -03:00
2017-06-26 13:53:06 -03:00
}, func() {
followIDList = user.Following
userList, err = arn.DB.GetMany("User", followIDList)
followingList = userList.([]*arn.User)
followingList = arn.SortUsersLastSeen(followingList)
if len(followingList) > maxFollowing {
followingList = followingList[:maxFollowing]
}
2017-06-26 13:53:06 -03:00
})
if err != nil {
2017-06-26 12:50:15 -03:00
return ctx.Error(500, "Error displaying dashboard", err)
2017-06-25 15:30:24 +02:00
}
return ctx.HTML(components.Dashboard(posts, followingList))
2016-11-19 23:54:31 +09:00
}