From 51afbb8df521303d4aca648db46d4991266fdd72 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sun, 22 Nov 2026 19:11:00 -0500 Subject: [PATCH] feat(android): Admin Quarantine is Reports, with the web's two removals The Admin card is Reports ("Tracks listeners flagged"). Each report offers Resolve, Remove the file (the file goes and the track waits for a good copy, with its likes and plays) and Remove from library (track, file and history). Both removals now ask first; Delete file used to delete on the tap. They stay online-only: each deletes a file for good against a live queue, so a replay hours later could act on a decision another admin has since made. Offline they fail with the reason and the row returns. Co-Authored-By: Claude Opus 5.5 --- .../admin/data/AdminQuarantineRepository.kt | 9 +- .../minstrel/admin/ui/AdminLandingScreen.kt | 4 +- .../admin/ui/AdminQuarantineScreen.kt | 82 +++++++++++++++++-- .../admin/ui/AdminQuarantineViewModel.kt | 6 +- .../api/endpoints/AdminQuarantineApi.kt | 11 ++- .../admin/ui/AdminQuarantineViewModelTest.kt | 61 ++++++++++++++ internal/api/reset_test.go | 14 ---- 7 files changed, 156 insertions(+), 31 deletions(-) create mode 100644 android/app/src/test/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineViewModelTest.kt delete mode 100644 internal/api/reset_test.go diff --git a/android/app/src/main/java/com/fabledsword/minstrel/admin/data/AdminQuarantineRepository.kt b/android/app/src/main/java/com/fabledsword/minstrel/admin/data/AdminQuarantineRepository.kt index 1c99ff86..988f8355 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/admin/data/AdminQuarantineRepository.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/admin/data/AdminQuarantineRepository.kt @@ -11,9 +11,10 @@ import javax.inject.Inject import javax.inject.Singleton /** - * Read-through accessor for the admin quarantine queue. No Room cache: - * it is an admin's live work list, read fresh each time. Three resolution - * actions all delete the row from the queue once the server accepts them. + * Read-through accessor for the admin Reports queue. No Room cache: it is an + * admin's live work list, read fresh each time, and its actions go straight + * to the server, so offline they fail with the reason rather than queueing. + * Each action takes the row off the queue once the server accepts it. */ @Singleton class AdminQuarantineRepository @Inject constructor( @@ -25,6 +26,8 @@ class AdminQuarantineRepository @Inject constructor( suspend fun resolve(trackId: String) = api.resolve(trackId) + suspend fun removeFile(trackId: String) = api.removeFile(trackId) + suspend fun deleteFile(trackId: String) = api.deleteFile(trackId) } diff --git a/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminLandingScreen.kt b/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminLandingScreen.kt index 74589622..e6ea91bc 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminLandingScreen.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminLandingScreen.kt @@ -148,8 +148,8 @@ private fun SectionList(counts: AdminCounts, navController: NavHostController) { item { SectionCard( icon = Lucide.TriangleAlert, - title = "Quarantine", - subtitle = "Resolve scan failures", + title = "Reports", + subtitle = "Tracks listeners flagged", count = counts.quarantine, onClick = { navController.navigate(AdminQuarantine) }, ) diff --git a/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineScreen.kt b/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineScreen.kt index 16873f6f..5d7ef57e 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineScreen.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.material3.AlertDialog import androidx.compose.material3.AssistChip import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.HorizontalDivider @@ -21,7 +22,9 @@ import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextOverflow @@ -56,7 +59,7 @@ fun AdminQuarantineScreen( modifier = Modifier.fillMaxSize(), topBar = { MinstrelTopAppBar( - title = "Admin · Quarantine", + title = "Admin · Reports", navController = navController, currentRouteName = AdminQuarantine::class.qualifiedName, onBack = { navController.popBackStack() }, @@ -71,9 +74,9 @@ fun AdminQuarantineScreen( when (val s = state) { AdminQuarantineUiState.Loading -> LoadingCentered() AdminQuarantineUiState.Empty -> EmptyState( - title = "Queue is empty", - body = "When users flag tracks as bad rips, wrong tags, or " + - "duplicates, their reports get aggregated and surfaced here.", + title = "No reports", + body = "When listeners flag a track as a bad rip, wrong tags or " + + "a duplicate, their reports gather here.", ) is AdminQuarantineUiState.Error -> ErrorRetry( title = "Couldn't load queue", @@ -83,6 +86,7 @@ fun AdminQuarantineScreen( is AdminQuarantineUiState.Success -> QueueList( rows = s.rows, onResolve = viewModel::resolve, + onRemoveFile = viewModel::removeFile, onDeleteFile = viewModel::deleteFile, ) } @@ -90,28 +94,91 @@ fun AdminQuarantineScreen( } } +/** A confirm asked of the admin before a removal: which one, and of which track. */ +private enum class Removal { File, Library } + +private data class PendingRemoval(val row: AdminQuarantineItemRef, val kind: Removal) + @Composable private fun QueueList( rows: List, onResolve: (String) -> Unit, + onRemoveFile: (String) -> Unit, onDeleteFile: (String) -> Unit, ) { + var pending by remember { mutableStateOf(null) } LazyColumn(modifier = Modifier.fillMaxSize()) { items(items = rows, key = { it.trackId }) { row -> QuarantineRow( row = row, onResolve = { onResolve(row.trackId) }, - onDeleteFile = { onDeleteFile(row.trackId) }, + onRemoveFile = { pending = PendingRemoval(row, Removal.File) }, + onDeleteFile = { pending = PendingRemoval(row, Removal.Library) }, ) HorizontalDivider() } } + pending?.let { p -> + RemovalConfirm( + pending = p, + onConfirm = { + pending = null + when (p.kind) { + Removal.File -> onRemoveFile(p.row.trackId) + Removal.Library -> onDeleteFile(p.row.trackId) + } + }, + onDismiss = { pending = null }, + ) + } +} + +/** + * Both removals delete the file, so each asks first. Remove the file keeps the + * track waiting for a good copy, with its likes and plays; Remove from library + * takes the track and its history too. + */ +@Composable +private fun RemovalConfirm( + pending: PendingRemoval, + onConfirm: () -> Unit, + onDismiss: () -> Unit, +) { + val title = pending.row.trackTitle + val (heading, body, action) = when (pending.kind) { + Removal.File -> Triple( + "Remove the file?", + "Delete the file of \u201c$title\u201d and keep the track. It waits, with its likes " + + "and plays, and takes over a good copy when one is in the library. Its reports are cleared.", + "Remove the file", + ) + Removal.Library -> Triple( + "Remove from library?", + "Remove \u201c$title\u201d and its file for good, with its likes, plays and playlist " + + "places. To keep the track for a good copy, remove the file instead.", + "Remove from library", + ) + } + AlertDialog( + onDismissRequest = onDismiss, + title = { Text(heading) }, + text = { + Text( + text = body, + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + }, + confirmButton = { TextButton(onClick = onConfirm) { Text(action) } }, + dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } }, + ) } @Composable private fun QuarantineRow( row: AdminQuarantineItemRef, onResolve: () -> Unit, + onRemoveFile: () -> Unit, onDeleteFile: () -> Unit, ) { Column( @@ -160,6 +227,7 @@ private fun QuarantineRow( } ActionButtons( onResolve = onResolve, + onRemoveFile = onRemoveFile, onDeleteFile = onDeleteFile, ) } @@ -168,6 +236,7 @@ private fun QuarantineRow( @Composable private fun ActionButtons( onResolve: () -> Unit, + onRemoveFile: () -> Unit, onDeleteFile: () -> Unit, ) { Row( @@ -175,6 +244,7 @@ private fun ActionButtons( horizontalArrangement = Arrangement.spacedBy(8.dp, Alignment.End), ) { TextButton(onClick = onResolve) { Text("Resolve") } - OutlinedButton(onClick = onDeleteFile) { Text("Delete file") } + TextButton(onClick = onDeleteFile) { Text("Remove from library") } + OutlinedButton(onClick = onRemoveFile) { Text("Remove the file") } } } diff --git a/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineViewModel.kt b/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineViewModel.kt index b233a459..a2e9397f 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineViewModel.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineViewModel.kt @@ -39,9 +39,8 @@ class AdminQuarantineViewModel @Inject constructor( /** * One-shot messages for the screen's snackbar. A failed action has to say - * why: the row quietly reappearing reads as a glitch, and for a Delete - * file refused by a read-only library it hides the one thing an - * admin can fix. + * why: the row quietly reappearing reads as a glitch, and for a removal + * refused by a read-only library it hides the one thing an admin can fix. */ private val transientMessagesChannel = Channel(Channel.BUFFERED) val transientMessages: Flow = transientMessagesChannel.receiveAsFlow() @@ -81,6 +80,7 @@ class AdminQuarantineViewModel @Inject constructor( } fun resolve(trackId: String) = act(trackId) { repository.resolve(it) } + fun removeFile(trackId: String) = act(trackId) { repository.removeFile(it) } fun deleteFile(trackId: String) = act(trackId) { repository.deleteFile(it) } private fun act(trackId: String, action: suspend (String) -> Unit) { diff --git a/android/app/src/main/java/com/fabledsword/minstrel/api/endpoints/AdminQuarantineApi.kt b/android/app/src/main/java/com/fabledsword/minstrel/api/endpoints/AdminQuarantineApi.kt index cde7fba6..ec1116c5 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/api/endpoints/AdminQuarantineApi.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/api/endpoints/AdminQuarantineApi.kt @@ -8,9 +8,11 @@ import retrofit2.http.Path /** * Retrofit interface for `/api/admin/quarantine`. * - * Two resolution endpoints: - * - `resolve` → admin reviewed, no action taken (clears flags). - * - `delete-file` → delete the track's file and row. + * Three resolution endpoints: + * - `resolve` → admin reviewed, no action taken (clears the reports). + * - `remove-file` → delete the track's file and keep the track, which waits + * for a good copy with its likes and plays. + * - `delete-file` → remove the track from the library, file and history. */ interface AdminQuarantineApi { @GET("api/admin/quarantine") @@ -19,6 +21,9 @@ interface AdminQuarantineApi { @POST("api/admin/quarantine/{trackId}/resolve") suspend fun resolve(@Path("trackId") trackId: String) + @POST("api/admin/quarantine/{trackId}/remove-file") + suspend fun removeFile(@Path("trackId") trackId: String) + @POST("api/admin/quarantine/{trackId}/delete-file") suspend fun deleteFile(@Path("trackId") trackId: String) } diff --git a/android/app/src/test/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineViewModelTest.kt b/android/app/src/test/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineViewModelTest.kt new file mode 100644 index 00000000..b38bd2f4 --- /dev/null +++ b/android/app/src/test/java/com/fabledsword/minstrel/admin/ui/AdminQuarantineViewModelTest.kt @@ -0,0 +1,61 @@ +package com.fabledsword.minstrel.admin.ui + +import com.fabledsword.minstrel.admin.data.AdminQuarantineRepository +import com.fabledsword.minstrel.connectivity.NetworkStatusController +import com.fabledsword.minstrel.connectivity.ServerHealth +import com.fabledsword.minstrel.events.EventsStream +import com.fabledsword.minstrel.events.LiveEvent +import com.fabledsword.minstrel.models.AdminQuarantineItemRef +import com.fabledsword.minstrel.testutil.MainDispatcherExtension +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.every +import io.mockk.mockk +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import kotlin.test.assertEquals + +/** Reports' two removals each reach their own endpoint, and either takes the row off the queue. */ +@ExtendWith(MainDispatcherExtension::class) +class AdminQuarantineViewModelTest { + private val row = AdminQuarantineItemRef( + trackId = "t1", + trackTitle = "Roygbiv", + artistName = "Boards of Canada", + albumTitle = "Geogaddi", + albumId = "al1", + reportCount = 1, + ) + private val repository: AdminQuarantineRepository = mockk(relaxed = true) { + coEvery { list() } returns listOf(row) + } + private val eventsStream: EventsStream = mockk { + every { events } returns MutableSharedFlow() + } + private val network: NetworkStatusController = mockk { + every { state } returns MutableStateFlow(ServerHealth.Healthy) + } + + // Lazy: built inside each test, after the extension has swapped in the test Main dispatcher. + private val viewModel by lazy { AdminQuarantineViewModel(repository, eventsStream, network) } + + @Test + fun `remove the file keeps the track and clears the row`() { + viewModel.removeFile("t1") + + coVerify(exactly = 1) { repository.removeFile("t1") } + coVerify(exactly = 0) { repository.deleteFile(any()) } + assertEquals(AdminQuarantineUiState.Empty, viewModel.uiState.value) + } + + @Test + fun `remove from library is the separate full removal`() { + viewModel.deleteFile("t1") + + coVerify(exactly = 1) { repository.deleteFile("t1") } + coVerify(exactly = 0) { repository.removeFile(any()) } + assertEquals(AdminQuarantineUiState.Empty, viewModel.uiState.value) + } +} diff --git a/internal/api/reset_test.go b/internal/api/reset_test.go deleted file mode 100644 index fd4e4c82..00000000 --- a/internal/api/reset_test.go +++ /dev/null @@ -1,14 +0,0 @@ -package api - -import ( - "context" - "testing" -) - -// resetRequests clears requests rows between tests. -func resetRequests(t *testing.T, h *handlers) { - t.Helper() - if _, err := h.pool.Exec(context.Background(), "DELETE FROM requests"); err != nil { - t.Fatalf("resetRequests: %v", err) - } -}