Added notification count badge
This commit is contained in:
@ -213,6 +213,7 @@ func Configure(app *aero.Application) {
|
||||
app.Get("/api/me", me.Get)
|
||||
app.Get("/api/popular/anime/titles/:count", popular.AnimeTitles)
|
||||
app.Get("/api/test/notification", notifications.Test)
|
||||
app.Get("/api/count/notifications/unseen", notifications.CountUnseen)
|
||||
|
||||
// Legal stuff
|
||||
l.Page("/terms", terms.Get)
|
||||
|
@ -3,6 +3,7 @@ package notifications
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
@ -28,6 +29,26 @@ func All(ctx *aero.Context) string {
|
||||
return ctx.HTML(components.Notifications(notifications, user))
|
||||
}
|
||||
|
||||
// CountUnseen sends the number of unseen notifications.
|
||||
func CountUnseen(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
if user == nil {
|
||||
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
|
||||
}
|
||||
|
||||
notifications := user.Notifications().Notifications()
|
||||
unseen := 0
|
||||
|
||||
for _, notification := range notifications {
|
||||
if notification.Seen == "" {
|
||||
unseen++
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.Text(strconv.Itoa(unseen))
|
||||
}
|
||||
|
||||
// Test sends a test notification to the logged in user.
|
||||
func Test(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
|
Reference in New Issue
Block a user