1
Fork 0
photoview/api/graphql/resolvers/notification.go

29 lines
651 B
Go
Raw Normal View History

package resolvers
import (
"context"
2020-12-17 22:51:43 +01:00
"github.com/photoview/photoview/api/graphql/auth"
"github.com/photoview/photoview/api/graphql/models"
"github.com/photoview/photoview/api/graphql/notification"
)
2020-02-21 20:51:50 +01:00
func (r *subscriptionResolver) Notification(ctx context.Context) (<-chan *models.Notification, error) {
user := auth.UserFromContext(ctx)
if user == nil {
return nil, auth.ErrUnauthorized
}
2020-02-21 20:51:50 +01:00
notificationChannel := make(chan *models.Notification, 1)
listenerID := notification.RegisterListener(user, notificationChannel)
go func() {
<-ctx.Done()
notification.DeregisterListener(listenerID)
}()
return notificationChannel, nil
}