2017-06-22 14:21:26 +00:00
|
|
|
package profile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/animenotifier/notify.moe/components"
|
2017-07-03 15:21:00 +00:00
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
2017-06-22 14:21:26 +00:00
|
|
|
)
|
|
|
|
|
2017-06-22 15:03:43 +00:00
|
|
|
const postLimit = 10
|
|
|
|
|
2017-06-22 15:33:41 +00:00
|
|
|
// GetPostsByUser shows all forum posts of a particular user.
|
2017-06-22 14:21:26 +00:00
|
|
|
func GetPostsByUser(ctx *aero.Context) string {
|
|
|
|
nick := ctx.Get("nick")
|
2017-07-03 15:21:00 +00:00
|
|
|
viewUser, err := arn.GetUserByNick(nick)
|
2017-06-22 15:03:43 +00:00
|
|
|
|
2017-06-22 14:21:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "User not found", err)
|
|
|
|
}
|
|
|
|
|
2017-07-03 15:21:00 +00:00
|
|
|
posts := viewUser.Posts()
|
2017-06-22 15:42:17 +00:00
|
|
|
arn.SortPostsLatestFirst(posts)
|
2017-06-22 15:13:55 +00:00
|
|
|
|
2017-06-22 14:21:26 +00:00
|
|
|
if len(posts) >= postLimit {
|
2017-06-22 15:03:43 +00:00
|
|
|
posts = posts[:postLimit]
|
2017-06-22 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 08:05:55 +00:00
|
|
|
return ctx.HTML(components.LatestPosts(arn.ToPostables(posts), viewUser, utils.GetUser(ctx), ctx.URI()))
|
2017-06-22 14:21:26 +00:00
|
|
|
|
|
|
|
}
|