40 lines
766 B
Go
Raw Normal View History

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-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")
user, 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)
}
posts := user.Posts()
arn.SortPostsLatestLast(posts)
2017-06-22 15:03:43 +00:00
var postables []arn.Postable
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
}
2017-06-22 15:03:43 +00:00
postables = make([]arn.Postable, len(posts), len(posts))
2017-06-22 14:21:26 +00:00
2017-06-22 15:03:43 +00:00
for i, post := range posts {
2017-06-22 14:21:26 +00:00
postables[i] = arn.ToPostable(post)
}
return ctx.HTML(components.PostableList(postables))
}