feat: the radio stations are in the apps only when the person asks

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
This commit is contained in:
tgiachi 2026-11-16 12:33:09 +01:00
commit ed32aac228
6 changed files with 310 additions and 25 deletions

View file

@ -4345,6 +4345,12 @@ export interface components {
last_error?: string;
};
UserSettings: {
/**
* @description When true, the stations of the radio (see `GET /radio`) are in the list of playlists of the apps that speak
* OpenSubsonic, as playlists called `Radio · Rock` with other songs every time they are opened. False until you
* turn it on: there are about two dozen of them. Nothing is sent anywhere either way.
*/
radio_in_apps: boolean;
/**
* @description When true, Discover may start from the artists you listen to most. That sends their
* names to Last.fm, which is asked for artists similar to each one (only when an admin
@ -4463,6 +4469,7 @@ export interface components {
};
UpdateUserSettings: {
discover_from_listening?: boolean | null;
radio_in_apps?: boolean | null;
};
TasteArtist: {
/** Format: int64 */

View file

@ -0,0 +1,64 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { beforeEach, expect, test, vi } from 'vitest'
import { initI18n } from '@/i18n'
import { apiError, mockFetch, type MockRoutes } from '@/test/mockFetch'
import RadioInAppsSwitch from './RadioInAppsSwitch'
beforeEach(async () => {
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
await initI18n()
})
function setup(initial: boolean, over: MockRoutes = {}) {
let on = initial
const mocked = mockFetch({
'GET /api/v1/me/settings': () => ({ discover_from_listening: false, radio_in_apps: on }),
'PATCH /api/v1/me/settings': ({ init }) => {
on = JSON.parse(String(init.body)).radio_in_apps
return { discover_from_listening: false, radio_in_apps: on }
},
...over,
})
render(
<QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })}>
<RadioInAppsSwitch />
</QueryClientProvider>,
)
return mocked
}
const switchEl = () => screen.getByRole('switch', { name: 'Show the radio stations in apps' })
test('it is off at first, and says what it does', async () => {
setup(false)
await vi.waitFor(() => expect(switchEl()).not.toBeDisabled())
expect(switchEl()).toHaveAttribute('aria-checked', 'false')
expect(screen.getByText(/Radio · Rock/)).toBeInTheDocument()
})
test('turning it on sends the setting, and the switch shows it', async () => {
const { calls } = setup(false)
await vi.waitFor(() => expect(switchEl()).not.toBeDisabled())
await userEvent.click(switchEl())
await vi.waitFor(() => expect(switchEl()).toHaveAttribute('aria-checked', 'true'))
const sent = calls.find((c) => c.key === 'PATCH /api/v1/me/settings')!
expect(JSON.parse(String(sent.init.body))).toEqual({ radio_in_apps: true })
})
test('turning it off sends it too', async () => {
const { calls } = setup(true)
await vi.waitFor(() => expect(switchEl()).toHaveAttribute('aria-checked', 'true'))
await userEvent.click(switchEl())
await vi.waitFor(() => expect(switchEl()).toHaveAttribute('aria-checked', 'false'))
expect(JSON.parse(String(calls.find((c) => c.key === 'PATCH /api/v1/me/settings')!.init.body))).toEqual({ radio_in_apps: false })
})
test('a setting that cannot be kept says so', async () => {
setup(false, { 'PATCH /api/v1/me/settings': () => apiError(500, 'internal', 'x') })
await vi.waitFor(() => expect(switchEl()).not.toBeDisabled())
await userEvent.click(switchEl())
expect(await screen.findByRole('alert')).toBeInTheDocument()
expect(switchEl()).toHaveAttribute('aria-checked', 'false')
})

View file

@ -0,0 +1,38 @@
import { useTranslation } from 'react-i18next'
import { ApiError } from '@/api/client'
import { useMySettings, useUpdateSettings } from '@/api/discover'
import { Switch } from '@/components/ui/switch'
import { errorMessageKey } from '@/i18n'
/**
* Whether the stations of the radio are in the playlists of the apps (Feishin...). They are about two dozen, so they
* come when asked. Nothing leaves the server either way, so it asks nothing before it turns on.
*/
export default function RadioInAppsSwitch() {
const { t } = useTranslation()
const settings = useMySettings()
const update = useUpdateSettings()
const on = settings.data?.radio_in_apps === true
return (
<div className="flex max-w-xl flex-col gap-3">
<div className="flex items-center gap-4">
<Switch
checked={on}
aria-labelledby="radio-apps-label"
disabled={settings.data === undefined || update.isPending}
onClick={() => update.mutate({ radio_in_apps: !on })}
/>
<span id="radio-apps-label" className="font-semibold">
{t('devices.radio.label')}
</span>
</div>
<p className="text-sm text-muted-foreground">{t('devices.radio.help')}</p>
{update.isError && (
<p role="alert" className="text-sm text-destructive">
{t(errorMessageKey(update.error instanceof ApiError ? update.error.code : 'unknown'))}
</p>
)}
</div>
)
}

View file

@ -105,7 +105,11 @@
"password": "Password",
"copy": "Copy password",
"copied": "Copied",
"done": "Done"
"done": "Done",
"radio": {
"label": "Show the radio stations in apps",
"help": "In apps like Feishin the stations of the radio come as playlists called “Radio · Rock”, with other songs every time you open one. There are about two dozen, so they are off until you ask."
}
},
"favorites": {
"add": "Add to favourites",

View file

@ -105,7 +105,11 @@
"password": "Password",
"copy": "Copia password",
"copied": "Copiata",
"done": "Fatto"
"done": "Fatto",
"radio": {
"label": "Mostra le stazioni radio nelle app",
"help": "Nelle app come Feishin le stazioni della radio arrivano come playlist chiamate «Radio · Rock», con brani diversi ogni volta che ne apri una. Sono circa due dozzine, quindi restano spente finché non lo chiedi."
}
},
"favorites": {
"add": "Aggiungi ai preferiti",

View file

@ -6,6 +6,7 @@ import { logout, useSession } from '@/auth/session'
import ChoiceGroup from '@/components/ChoiceGroup'
import ListeningSwitch from '@/components/ListeningSwitch'
import DevicesBlock from '@/components/DevicesBlock'
import RadioInAppsSwitch from '@/components/RadioInAppsSwitch'
import MastodonBlock from '@/components/MastodonBlock'
import Section from '@/components/Section'
import VersionLabel from '@/components/VersionLabel'
@ -188,6 +189,7 @@ export default function SettingsPage() {
<Section title={t('settings.devices')}>
<DevicesBlock />
<RadioInAppsSwitch />
</Section>
<Section title={t('settings.spotify')}>