41 lines
860 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-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: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)
}
2017-07-06 01:24:56 +00:00
return ctx.HTML(components.LatestPosts(postables, viewUser, utils.GetUser(ctx), ctx.URI()))
2017-06-22 14:21:26 +00:00
}