Files
byre/internal/store/notifications.go
T

28 lines
695 B
Go

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