2018-11-22 02:51:44 +00:00
|
|
|
package groups
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Joined shows the most popular joined groups.
|
2019-06-01 04:55:49 +00:00
|
|
|
func Joined(ctx aero.Context) error {
|
2018-11-22 02:51:44 +00:00
|
|
|
user := utils.GetUser(ctx)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|