Added notification count badge

This commit is contained in:
2018-02-28 16:26:49 +01:00
parent 6f01b654d3
commit fceec3f193
8 changed files with 80 additions and 3 deletions

View File

@ -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)