34 lines
757 B
Go
Raw Normal View History

2018-03-24 19:28:27 +00:00
package notifications
import (
"net/http"
"sort"
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2018-03-24 19:28:27 +00:00
"github.com/animenotifier/notify.moe/components"
)
const maxAllNotifications = 150
// All shows all notifications.
2019-06-01 04:55:49 +00:00
func All(ctx aero.Context) error {
2018-03-24 19:28:27 +00:00
notifications, err := arn.AllNotifications()
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Could not retrieve notification list", err)
}
// Sort by date
sort.Slice(notifications, func(i, j int) bool {
return notifications[i].Created > notifications[j].Created
})
// Limit results
if len(notifications) > maxAllNotifications {
notifications = notifications[:maxAllNotifications]
}
return ctx.HTML(components.AllNotifications(notifications))
}