Use new event API

This commit is contained in:
2021-11-20 20:52:08 +09:00
parent df5f0c0f65
commit 9368689019
8 changed files with 38 additions and 50 deletions

View File

@ -6,6 +6,7 @@ import (
"strconv"
"github.com/aerogo/aero"
"github.com/aerogo/aero/event"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/assets"
)
@ -39,10 +40,7 @@ func MarkNotificationsAsSeen(ctx aero.Context) error {
}
// Update the counter on all clients
user.BroadcastEvent(&aero.Event{
Name: "notificationCount",
Data: 0,
})
user.BroadcastEvent(event.New("notificationCount", 0))
return nil
}

View File

@ -4,6 +4,7 @@ import (
"net/http"
"github.com/aerogo/aero"
"github.com/aerogo/aero/event"
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/components/css"
"github.com/animenotifier/notify.moe/components/js"
@ -22,35 +23,29 @@ func Events(ctx aero.Context) error {
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
stream := aero.NewEventStream()
stream := event.NewStream()
user.AddEventStream(stream)
go func() {
defer user.RemoveEventStream(stream)
// Send the ETag for the scripts
stream.Events <- &aero.Event{
Name: "etag",
Data: struct {
URL string `json:"url"`
ETag string `json:"etag"`
}{
URL: "/scripts",
ETag: scriptsETag,
},
}
stream.Events <- event.New("etag", struct {
URL string `json:"url"`
ETag string `json:"etag"`
}{
URL: "/scripts",
ETag: scriptsETag,
})
// Send the ETag for the styles
stream.Events <- &aero.Event{
Name: "etag",
Data: struct {
URL string `json:"url"`
ETag string `json:"etag"`
}{
URL: "/styles",
ETag: stylesETag,
},
}
stream.Events <- event.New("etag", struct {
URL string `json:"url"`
ETag string `json:"etag"`
}{
URL: "/styles",
ETag: stylesETag,
})
// Wait until the user closes the tab or disconnects
<-stream.Closed