Replace Web Push and its service worker with page notifications over SSE
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
|
||||
"g.fc.run/misc/byre/internal/api"
|
||||
)
|
||||
|
||||
func (s *Store) UpdateNotificationPrefs(ctx context.Context, login string, prefs api.NotificationPrefs) (api.User, error) {
|
||||
b, err := json.Marshal(prefs)
|
||||
if err != nil {
|
||||
return api.User{}, err
|
||||
}
|
||||
err = s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
_, err := tx.ExecContext(ctx, `UPDATE users SET notification_prefs = ? WHERE login = ?`, string(b), login)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return emit(api.Event{Kind: "user.updated", Actor: login, Payload: map[string]any{"login": login}})
|
||||
})
|
||||
if err != nil {
|
||||
return api.User{}, err
|
||||
}
|
||||
return s.GetUser(ctx, login)
|
||||
}
|
||||
Reference in New Issue
Block a user