36 lines
773 B
Go
Raw Normal View History

2017-07-14 21:50:34 +00:00
package notifications
import (
"net/http"
2018-02-27 14:27:16 +00:00
"sort"
2017-07-14 21:50:34 +00:00
"github.com/aerogo/aero"
2018-02-27 14:27:16 +00:00
"github.com/animenotifier/notify.moe/components"
2017-07-14 21:50:34 +00:00
"github.com/animenotifier/notify.moe/utils"
)
2018-02-28 23:10:35 +00:00
const maxNotifications = 30
2018-02-28 23:06:03 +00:00
2018-02-27 14:27:16 +00:00
// All shows all notifications sent so far.
func All(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
}
notifications := user.Notifications().Notifications()
// Sort by date
sort.Slice(notifications, func(i, j int) bool {
return notifications[i].Created > notifications[j].Created
})
2018-02-28 23:06:03 +00:00
// Limit results
if len(notifications) > maxNotifications {
notifications = notifications[:maxNotifications]
2018-02-28 15:26:49 +00:00
}
2018-02-28 23:06:03 +00:00
return ctx.HTML(components.Notifications(notifications, user))
2017-07-14 21:50:34 +00:00
}