32 lines
720 B
Go
Raw Normal View History

2017-06-17 01:25:02 +02:00
package profile
2017-06-08 14:46:38 +02:00
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-07-03 17:21:00 +02:00
"github.com/animenotifier/notify.moe/utils"
2017-06-08 14:46:38 +02:00
)
2017-07-03 17:33:57 +02:00
const maxThreads = 20
2017-06-17 01:25:02 +02:00
// GetThreadsByUser shows all forum threads of a particular user.
func GetThreadsByUser(ctx *aero.Context) string {
2017-06-08 14:46:38 +02:00
nick := ctx.Get("nick")
2017-07-03 17:21:00 +02:00
viewUser, err := arn.GetUserByNick(nick)
2017-06-08 14:46:38 +02:00
if err != nil {
return ctx.Error(http.StatusNotFound, "User not found", err)
}
2017-07-03 17:21:00 +02:00
threads := viewUser.Threads()
2017-06-29 20:52:30 +02:00
arn.SortThreadsLatestFirst(threads)
2017-06-08 14:46:38 +02:00
2017-07-03 17:33:57 +02:00
if len(threads) > maxThreads {
threads = threads[:maxThreads]
}
2017-07-06 03:24:56 +02:00
return ctx.HTML(components.ProfileThreads(threads, viewUser, utils.GetUser(ctx), ctx.URI()))
2017-06-08 14:46:38 +02:00
}