A new setting, radio_in_apps, off until the person turns it on (Settings, Apps and devices, or PATCH /me/settings). With it off, the list of playlists of an OpenSubsonic app is only the playlists of the person, and a station asked for by id is not found. With it on, the stations come as playlists called Radio · Rock. - migration 0036: user_settings.radio_in_apps - usersettings, the settings API and the OpenAPI spec have the new field; the PATCH now keeps each setting apart (naming one no longer sets the other) - Settings has a switch
57 lines
2 KiB
Go
57 lines
2 KiB
Go
// Package usersettings keeps the settings that belong to one user.
|
|
//
|
|
// They are choices about privacy and taste, not about the server: a user with no
|
|
// stored settings gets the defaults, and the defaults never send anything to a
|
|
// provider.
|
|
package usersettings
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
)
|
|
|
|
// ErrUserNotFound is returned for an account that no longer exists.
|
|
var ErrUserNotFound = errors.New("user not found")
|
|
|
|
// Settings are the choices of one user.
|
|
type Settings struct {
|
|
// DiscoverFromListening lets Discover start from the artists the user listens
|
|
// to most. Doing so sends their names to Last.fm, so it is off until the user
|
|
// turns it on.
|
|
DiscoverFromListening bool
|
|
// RadioInApps puts the stations of the radio in the list of playlists of the apps that speak OpenSubsonic, as
|
|
// playlists with other songs every time. Nothing leaves the server either way: it is only that there are two dozen
|
|
// of them, so they come when the user asks.
|
|
RadioInApps bool
|
|
}
|
|
|
|
// Patch changes some settings. A nil field is left alone.
|
|
type Patch struct {
|
|
DiscoverFromListening *bool
|
|
RadioInApps *bool
|
|
}
|
|
|
|
// Store keeps the settings.
|
|
type Store interface {
|
|
// Get returns the settings, the defaults for a user who never set any, or
|
|
// ErrUserNotFound.
|
|
Get(ctx context.Context, userID int64) (Settings, error)
|
|
// Update applies the patch and returns the result, or ErrUserNotFound.
|
|
Update(ctx context.Context, userID int64, p Patch) (Settings, error)
|
|
}
|
|
|
|
// Service reads and changes a user's own settings.
|
|
type Service struct{ store Store }
|
|
|
|
// NewService builds a Service.
|
|
func NewService(store Store) *Service { return &Service{store: store} }
|
|
|
|
// Get returns the user's settings.
|
|
func (s *Service) Get(ctx context.Context, userID int64) (Settings, error) {
|
|
return s.store.Get(ctx, userID)
|
|
}
|
|
|
|
// Update applies the patch and returns the settings as they are now.
|
|
func (s *Service) Update(ctx context.Context, userID int64, p Patch) (Settings, error) {
|
|
return s.store.Update(ctx, userID, p)
|
|
}
|