feat: new-music notices come from the scanner; request notices and the original specs go
release / web (push) Failing after 1m29s
release / go (push) Successful in 1m55s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m22s
release / android (push) Successful in 4m57s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 4m23s

Request notifications (approved, declined, completed, pending) are removed
along with the request flow that produced them. A new_music kind takes the
"new music arrived" slot: when a scan or a watcher batch finishes, the
scanner claims every album not yet announced (albums.announced_at) and tells
every user about the ones that are new: an album with a track on disk and
no track older than itself. The first import into an empty library, and an
album formed only by retagging tracks already held, announce nothing. One
notice per scan, carrying up to 50 albums and the total; it is never
coalesced, so a notice already emailed can't quietly absorb later arrivals.
It feeds the daily summary email, grouped by artist. Defaults: inbox and
email on, phone off.

Migration 0103 deletes request-kind notification rows and prefs, swaps the
kind CHECKs to new_music, and adds albums.announced_at with every album
held marked announced, so the first scan after it announces nothing old.

Web and Android: labels, the Android "Requests" settings section becomes
"New music", the shade channel your_requests becomes new_music (the old one
is deleted at startup), and "/" opens Home in the app. TrackLabel moves to
the notifications package. docs/smart-music-{server,client}-spec.md are
deleted per the operator; an Android comment loses the word "exchanges".

Grimoire #7666, #7671.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 23:29:13 -05:00
co-authored by Claude Opus 5.5
parent 9d267ba8dd
commit 561c1d5eae
42 changed files with 647 additions and 859 deletions
@@ -9,7 +9,7 @@ import kotlinx.datetime.Instant
* Cache row for one artist.
*
* Column names follow Kotlin idiom (camelCase) — the schema is purely
* internal to the app; the sync controller exchanges snake_case JSON
* internal to the app; the sync controller trades snake_case JSON
* with the server and our mappers translate at the boundary.
*/
@Entity(tableName = "cached_artists")
@@ -76,7 +76,7 @@ internal fun announcementFor(fresh: List<CachedNotificationEntity>): Announcemen
channel = if (fresh.all { shadeChannelFor(it.kind) == ShadeChannel.LIBRARY_HEALTH }) {
ShadeChannel.LIBRARY_HEALTH
} else {
ShadeChannel.YOUR_REQUESTS
ShadeChannel.NEW_MUSIC
},
lines = fresh.sortedByDescending { it.createdAt }.take(PILE_LINES).map { it.title },
)
@@ -94,15 +94,18 @@ internal fun phoneOnFor(settings: NotificationSettingsWire?): (String) -> Boolea
* user's system-level choice for it.
*/
internal enum class ShadeChannel(val id: String, val title: String, val description: String) {
YOUR_REQUESTS("your_requests", "Your requests", "Approved, declined, and new music arriving"),
LIBRARY_HEALTH("library_health", "Library health", "For admins: requests to review and library problems"),
NEW_MUSIC("new_music", "New music", "Albums arriving in the library"),
LIBRARY_HEALTH("library_health", "Library health", "For admins: flagged tracks and library problems"),
}
private val requesterKinds = setOf("request_approved", "request_rejected", "request_completed")
/** Channel ids the app does not post to; deleted at startup so system settings lists only live ones. */
internal val retiredShadeChannelIds = listOf("your_requests")
private val listenerKinds = setOf("new_music")
/** Everything a listener can receive is theirs; the rest is admin work. */
internal fun shadeChannelFor(kind: String): ShadeChannel =
if (kind in requesterKinds) ShadeChannel.YOUR_REQUESTS else ShadeChannel.LIBRARY_HEALTH
if (kind in listenerKinds) ShadeChannel.NEW_MUSIC else ShadeChannel.LIBRARY_HEALTH
/** The delivery service runs exactly while signed in with background delivery on. */
internal fun deliveryWanted(signedIn: Boolean, enabled: Boolean): Boolean = signedIn && enabled
@@ -79,6 +79,7 @@ class NotificationPoster @Inject constructor(
private fun ensureChannels() {
val manager = context.getSystemService(NotificationManager::class.java) ?: return
retiredShadeChannelIds.forEach { manager.deleteNotificationChannel(it) }
ShadeChannel.entries.forEach { c ->
manager.createNotificationChannel(
NotificationChannel(c.id, c.title, NotificationManager.IMPORTANCE_DEFAULT)
@@ -4,10 +4,12 @@ import com.fabledsword.minstrel.nav.Admin
import com.fabledsword.minstrel.nav.AdminQuarantine
import com.fabledsword.minstrel.nav.AlbumDetail
import com.fabledsword.minstrel.nav.ArtistDetail
import com.fabledsword.minstrel.nav.Home
/**
* The app screen for a notice's link. The server writes web paths, the same
* for every client; this maps them onto the app's routes. The library's
* for every client; this maps them onto the app's routes. "/" is Home,
* where several new albums at once are found under Recently added. The library's
* health pages sit under Collection on the web: Reports opens the
* app's report screen, and the ones the app has no screen for (duplicates,
* suspect sources, missing files) open the Admin landing, as do other Admin
@@ -18,6 +20,8 @@ private val ADMIN_COLLECTION_PAGES = setOf("duplicates", "suspect-sources", "mis
internal fun routeForLink(link: String): Any? {
val parts = link.substringBefore('?').trim('/').split('/').filter { it.isNotEmpty() }
return when {
link.isBlank() -> null
parts.isEmpty() -> Home
parts.size == 2 && parts[0] == "albums" -> AlbumDetail(parts[1])
parts.size == 2 && parts[0] == "artists" -> ArtistDetail(parts[1])
parts == listOf("collection", "reports") -> AdminQuarantine
@@ -110,7 +110,7 @@ private fun SettingsBody(
verticalArrangement = Arrangement.spacedBy(SectionGap),
) {
Section("This device") { deviceRows() }
Section("Requests", trailing = { ChannelHeaders() }) {
Section("New music", trailing = { ChannelHeaders() }) {
settings.kinds.filter { !it.adminOnly }.forEach { KindRow(it, settings.emailAvailable, onSet) }
if (!settings.emailAvailable) {
Muted(emailUnavailableLine(settings.emailUnavailableReason, isAdmin))
@@ -248,10 +248,7 @@ internal fun channelLabel(c: NotificationChannel): String = when (c) {
/** Short row labels, the same as the web's. Unknown kinds show their key. */
internal fun kindLabel(kind: String): String = when (kind) {
"request_approved" -> "Request approved"
"request_rejected" -> "Request declined"
"request_completed" -> "New music arrived"
"request_pending" -> "Requests to review"
"new_music" -> "New music arrived"
"quarantine_flagged" -> "Tracks flagged"
"scan_failed" -> "Library scan failed"
"tracks_missing" -> "Tracks gone missing"
@@ -38,7 +38,7 @@ class NotificationSettingsRepositoryTest {
private val settings = NotificationSettingsWire(
kinds = listOf(
NotificationKindSettingWire("request_completed", false, inbox = true, phone = true, email = true),
NotificationKindSettingWire("new_music", false, inbox = true, phone = true, email = true),
),
emailAvailable = true,
)
@@ -58,12 +58,12 @@ class NotificationSettingsRepositoryTest {
val body = slot<PutNotificationSettingsBody>()
coEvery { api.putSettings(capture(body)) } returns settings
repo.set("request_completed", NotificationChannel.EMAIL, false)
repo.set("new_music", NotificationChannel.EMAIL, false)
val optimistic = json.decodeFromString(NotificationSettingsWire.serializer(), saved.first().json)
assertFalse(optimistic.kinds.single().email)
assertEquals(
listOf(NotificationSettingChangeWire(kind = "request_completed", email = false)),
listOf(NotificationSettingChangeWire(kind = "new_music", email = false)),
body.captured.kinds,
)
coVerify(exactly = 0) { queue.enqueueNotificationSettingSet(any()) }
@@ -75,10 +75,10 @@ class NotificationSettingsRepositoryTest {
coEvery { mutationDao.hasPending(MutationKind.NOTIFICATION_SETTING_SET) } returns false
coEvery { api.putSettings(any()) } throws IOException("offline")
repo.set("request_completed", NotificationChannel.PHONE, false)
repo.set("new_music", NotificationChannel.PHONE, false)
coVerify {
queue.enqueueNotificationSettingSet(NotificationSettingPayload("request_completed", "phone", false))
queue.enqueueNotificationSettingSet(NotificationSettingPayload("new_music", "phone", false))
}
}
@@ -87,11 +87,11 @@ class NotificationSettingsRepositoryTest {
cached()
coEvery { mutationDao.hasPending(MutationKind.NOTIFICATION_SETTING_SET) } returns true
repo.set("request_completed", NotificationChannel.INBOX, false)
repo.set("new_music", NotificationChannel.INBOX, false)
coVerify(exactly = 0) { api.putSettings(any()) }
coVerify {
queue.enqueueNotificationSettingSet(NotificationSettingPayload("request_completed", "inbox", false))
queue.enqueueNotificationSettingSet(NotificationSettingPayload("new_music", "inbox", false))
}
}
@@ -41,10 +41,10 @@ class NotificationsRepositoryTest {
private fun row(id: String, created: String, readAt: Instant? = null) = CachedNotificationEntity(
id = id,
kind = "request_completed",
kind = "new_music",
title = "t",
body = "b",
link = "/requests",
link = "/",
createdAt = Instant.parse(created),
readAt = readAt,
)
@@ -108,8 +108,8 @@ class NotificationsRepositoryTest {
coEvery { dao.getAll() } returns listOf(row("a", "2026-10-08T10:00:00Z", readAt = readHere))
coEvery { api.list(any()) } returns NotificationsPageWire(
items = listOf(
NotificationWire("a", "request_completed", "t", "b", "/requests", "2026-10-08T10:00:00Z", null),
NotificationWire("b", "request_completed", "t", "b", "/requests", "2026-10-08T11:00:00Z", null),
NotificationWire("a", "new_music", "t", "b", "/", "2026-10-08T10:00:00Z", null),
NotificationWire("b", "new_music", "t", "b", "/", "2026-10-08T11:00:00Z", null),
),
unreadCount = 2,
)
@@ -17,14 +17,14 @@ class DeliveryPlanTest {
private fun notice(
id: String,
minutes: Long,
kind: String = "request_approved",
kind: String = "new_music",
read: Boolean = false,
) = CachedNotificationEntity(
id = id,
kind = kind,
title = "t-$id",
body = "b-$id",
link = "/requests",
link = "/",
createdAt = Instant.fromEpochMilliseconds(t0.toEpochMilliseconds() + minutes * 60_000),
readAt = if (read) t0 else null,
)
@@ -75,17 +75,17 @@ class DeliveryPlanTest {
fun `phone prefs come from the cached settings, with every kind on when none are cached`() {
val settings = NotificationSettingsWire(
kinds = listOf(
NotificationKindSettingWire("request_approved", false, inbox = true, phone = false, email = true),
NotificationKindSettingWire("request_completed", false, inbox = false, phone = true, email = true),
NotificationKindSettingWire("request_rejected", false, inbox = true, phone = true, email = true),
NotificationKindSettingWire("new_music", false, inbox = true, phone = false, email = true),
NotificationKindSettingWire("tracks_missing", true, inbox = false, phone = true, email = true),
NotificationKindSettingWire("quarantine_flagged", true, inbox = true, phone = true, email = true),
),
emailAvailable = true,
)
val phoneOn = phoneOnFor(settings)
assertFalse(phoneOn("request_approved"))
assertFalse(phoneOn("request_completed"), "phone rides on the inbox")
assertTrue(phoneOn("request_rejected"))
assertTrue(phoneOnFor(null)("tracks_missing"))
assertFalse(phoneOn("new_music"))
assertFalse(phoneOn("tracks_missing"), "phone rides on the inbox")
assertTrue(phoneOn("quarantine_flagged"))
assertTrue(phoneOnFor(null)("scan_failed"))
}
@Test
@@ -97,7 +97,7 @@ class DeliveryPlanTest {
val five = (1..5).map { notice("n$it", it.toLong()) }
val pile = assertIs<Announcement.Pile>(announcementFor(five))
assertEquals(5, pile.count)
assertEquals(ShadeChannel.YOUR_REQUESTS, pile.channel)
assertEquals(ShadeChannel.NEW_MUSIC, pile.channel)
assertEquals("5 new notifications", pileText(pile.count))
assertEquals(listOf("t-n5", "t-n4", "t-n3", "t-n2", "t-n1"), pile.lines)
assertNull(pileMore(pile))
@@ -116,15 +116,14 @@ class DeliveryPlanTest {
val admin = (1..4).map { notice("a$it", it.toLong(), kind = "tracks_missing") }
assertEquals(ShadeChannel.LIBRARY_HEALTH, assertIs<Announcement.Pile>(announcementFor(admin)).channel)
val mixed = admin + notice("r", 9)
assertEquals(ShadeChannel.YOUR_REQUESTS, assertIs<Announcement.Pile>(announcementFor(mixed)).channel)
assertEquals(ShadeChannel.NEW_MUSIC, assertIs<Announcement.Pile>(announcementFor(mixed)).channel)
}
@Test
fun `listener kinds are their requests, the rest is library health`() {
listOf("request_approved", "request_rejected", "request_completed").forEach {
assertEquals(ShadeChannel.YOUR_REQUESTS, shadeChannelFor(it))
}
listOf("request_pending", "quarantine_flagged", "scan_failed", "tracks_missing").forEach {
fun `new music has its own channel, the rest is library health`() {
assertEquals(ShadeChannel.NEW_MUSIC, shadeChannelFor("new_music"))
assertTrue(ShadeChannel.entries.none { it.id in retiredShadeChannelIds }, "a live channel is never deleted")
listOf("quarantine_flagged", "scan_failed", "tracks_missing").forEach {
assertEquals(ShadeChannel.LIBRARY_HEALTH, shadeChannelFor(it))
}
}
@@ -5,6 +5,7 @@ import com.fabledsword.minstrel.nav.Admin
import com.fabledsword.minstrel.nav.AdminQuarantine
import com.fabledsword.minstrel.nav.AlbumDetail
import com.fabledsword.minstrel.nav.ArtistDetail
import com.fabledsword.minstrel.nav.Home
import com.fabledsword.minstrel.notifications.data.NotificationChannel
import com.fabledsword.minstrel.shared.widgets.badgeLabel
import kotlinx.datetime.Instant
@@ -17,6 +18,9 @@ import kotlin.test.assertTrue
class NotificationUiTest {
@Test
fun `server links open the matching screens`() {
assertEquals(Home, routeForLink("/"))
// A pile carries no link: it opens the inbox, not Home.
assertNull(routeForLink(""))
assertEquals(AlbumDetail("al-1"), routeForLink("/albums/al-1"))
assertEquals(ArtistDetail("ar-1"), routeForLink("/artists/ar-1"))
assertEquals(AdminQuarantine, routeForLink("/collection/reports"))
@@ -50,7 +54,7 @@ class NotificationUiTest {
@Test
fun `phone and email ride on the inbox, and email needs to be available`() {
val on = NotificationKindSettingWire("request_completed", false, inbox = true, phone = true, email = true)
val on = NotificationKindSettingWire("new_music", false, inbox = true, phone = true, email = true)
val off = on.copy(inbox = false)
assertTrue(channelEnabled(on, NotificationChannel.PHONE, emailAvailable = true))
assertFalse(channelEnabled(off, NotificationChannel.PHONE, emailAvailable = true))
@@ -29,10 +29,10 @@ class NotificationsViewModelTest {
private fun row(id: String, read: Boolean) = CachedNotificationEntity(
id = id,
kind = "request_completed",
kind = "new_music",
title = "t",
body = "b",
link = "/requests",
link = "/",
createdAt = Instant.parse("2026-10-23T12:00:00Z"),
readAt = if (read) Instant.parse("2026-10-23T12:05:00Z") else null,
)