31 lines
585 B
Go
Raw Normal View History

2018-11-22 11:51:44 +09:00
package groups
import (
"net/http"
"sort"
"github.com/aerogo/aero"
2019-11-17 16:59:34 +09:00
"github.com/animenotifier/notify.moe/arn"
2018-11-22 11:51:44 +09:00
)
// Joined shows the most popular joined groups.
2019-06-01 13:55:49 +09:00
func Joined(ctx aero.Context) error {
2019-11-17 16:59:34 +09:00
user := arn.GetUserFromContext(ctx)
2018-11-22 11:51:44 +09:00
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
groups := fetchGroups(user.ID)
// Sort by join date
sort.Slice(groups, func(i, j int) bool {
aMember := groups[i].FindMember(user.ID)
bMember := groups[j].FindMember(user.ID)
return aMember.Joined > bMember.Joined
})
return render(ctx, groups)
}