mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 19:29:15 +00:00
Work towards subscriptions
- Replace chi with gorilla/mux - Write custom CORS rules - Start on notification subscriptions
This commit is contained in:
27
api/graphql/resolvers/notification.go
Normal file
27
api/graphql/resolvers/notification.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package resolvers
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/viktorstrate/photoview/api/graphql/auth"
|
||||
"github.com/viktorstrate/photoview/api/graphql/notification"
|
||||
)
|
||||
|
||||
func (r *subscriptionResolver) Notification(ctx context.Context) (notification.NotificationChannel, error) {
|
||||
|
||||
user := auth.UserFromContext(ctx)
|
||||
if user == nil {
|
||||
return nil, auth.ErrUnauthorized
|
||||
}
|
||||
|
||||
notificationChannel := make(notification.NotificationChannel, 1)
|
||||
|
||||
listenerID := notification.RegisterListener(user, notificationChannel)
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
notification.DeregisterListener(listenerID)
|
||||
}()
|
||||
|
||||
return notificationChannel, nil
|
||||
}
|
||||
Reference in New Issue
Block a user