51 lines
1014 B
Go
Raw Normal View History

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