67 lines
1.6 KiB
Go
Raw Normal View History

2016-11-20 10:26:11 +00:00
package profile
import (
2017-07-06 01:24:56 +00:00
"sort"
2016-11-20 10:26:11 +00:00
"github.com/aerogo/aero"
2017-06-23 16:22:48 +00:00
"github.com/aerogo/flow"
2016-11-20 10:26:11 +00:00
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-06-08 12:46:38 +00:00
"github.com/animenotifier/notify.moe/utils"
2016-11-20 10:26:11 +00:00
)
2017-06-08 12:46:38 +00:00
const maxPosts = 5
2017-06-27 16:44:22 +00:00
const maxTracks = 3
2017-06-08 12:46:38 +00:00
2017-06-16 23:25:02 +00:00
// Get user profile page.
2016-11-20 10:26:11 +00:00
func Get(ctx *aero.Context) string {
nick := ctx.Get("nick")
2017-06-08 12:46:38 +00:00
viewUser, err := arn.GetUserByNick(nick)
2016-11-20 10:26:11 +00:00
if err != nil {
2016-11-23 05:26:59 +00:00
return ctx.Error(404, "User not found", err)
2016-11-20 10:26:11 +00:00
}
2017-06-20 12:16:23 +00:00
return Profile(ctx, viewUser)
}
// Profile renders the user profile page of the given viewUser.
func Profile(ctx *aero.Context, viewUser *arn.User) string {
2017-06-10 00:19:31 +00:00
var user *arn.User
var threads []*arn.Thread
var animeList *arn.AnimeList
2017-06-27 15:51:15 +00:00
var tracks []*arn.SoundTrack
2017-06-22 14:21:26 +00:00
var posts []*arn.Post
2017-06-22 15:03:43 +00:00
2017-06-23 16:22:48 +00:00
flow.Parallel(func() {
2017-06-10 00:19:31 +00:00
user = utils.GetUser(ctx)
}, func() {
animeList = viewUser.AnimeList()
2017-07-06 01:24:56 +00:00
// Sort by rating
sort.Slice(animeList.Items, func(i, j int) bool {
return animeList.Items[i].Rating.Overall > animeList.Items[j].Rating.Overall
})
2017-06-22 15:03:43 +00:00
})
2017-06-22 14:21:26 +00:00
2017-07-21 06:09:22 +00:00
openGraph := &arn.OpenGraph{
Tags: map[string]string{
"og:title": viewUser.Nick,
"og:image": viewUser.LargeAvatar(),
"og:url": "https://" + ctx.App.Config.Domain + viewUser.Link(),
"og:site_name": "notify.moe",
"og:description": viewUser.Tagline,
"og:type": "profile",
"profile:username": viewUser.Nick,
},
Meta: map[string]string{
"description": viewUser.Tagline,
"keywords": viewUser.Nick + ",profile",
},
}
ctx.Data = openGraph
2017-07-06 01:24:56 +00:00
return ctx.HTML(components.Profile(viewUser, user, animeList, threads, posts, tracks, ctx.URI()))
2016-11-20 10:26:11 +00:00
}