mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-15 00:42:54 +01:00
library: skip queue resets for missing songs
This commit is contained in:
@@ -542,7 +542,7 @@ interface LibraryDao {
|
|||||||
sourceId: Long,
|
sourceId: Long,
|
||||||
id: String,
|
id: String,
|
||||||
starred: Long?,
|
starred: Long?,
|
||||||
)
|
): Int
|
||||||
|
|
||||||
@Query("SELECT id FROM artists WHERE sourceId = :sourceId")
|
@Query("SELECT id FROM artists WHERE sourceId = :sourceId")
|
||||||
suspend fun artistIds(sourceId: Long): List<String>
|
suspend fun artistIds(sourceId: Long): List<String>
|
||||||
|
|||||||
@@ -459,8 +459,9 @@ class LibraryRepository(
|
|||||||
val previous = song(sourceId, id).first()?.starred
|
val previous = song(sourceId, id).first()?.starred
|
||||||
if (previous == starred) return
|
if (previous == starred) return
|
||||||
val point = queueRepository.captureResetPoint()
|
val point = queueRepository.captureResetPoint()
|
||||||
dao.setSongStar(sourceId, id, starred)
|
if (dao.setSongStar(sourceId, id, starred) > 0) {
|
||||||
queueRepository.resetChangedOrigins(setOf(QueueOrigin(QueueKind.Starred, sourceId, "")), point)
|
queueRepository.resetChangedOrigins(setOf(QueueOrigin(QueueKind.Starred, sourceId, "")), point)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
when (type) {
|
when (type) {
|
||||||
StarType.Album -> dao.setAlbumStar(sourceId, id, starred)
|
StarType.Album -> dao.setAlbumStar(sourceId, id, starred)
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class LibraryRepositoryTest {
|
|||||||
private lateinit var db: SubtracksDatabase
|
private lateinit var db: SubtracksDatabase
|
||||||
private lateinit var sourceRepository: SourceRepository
|
private lateinit var sourceRepository: SourceRepository
|
||||||
private lateinit var repository: LibraryRepository
|
private lateinit var repository: LibraryRepository
|
||||||
|
private lateinit var queues: QueueRepository
|
||||||
private lateinit var scope: CoroutineScope
|
private lateinit var scope: CoroutineScope
|
||||||
private val messages = ArrayList<String>()
|
private val messages = ArrayList<String>()
|
||||||
private lateinit var resources: Resources
|
private lateinit var resources: Resources
|
||||||
@@ -66,13 +67,14 @@ class LibraryRepositoryTest {
|
|||||||
scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||||
sourceRepository =
|
sourceRepository =
|
||||||
SourceRepository(db, OkHttpClient(), fakeUserPreferences(), ArtworkStore(File(context.cacheDir, "art")), scope = scope)
|
SourceRepository(db, OkHttpClient(), fakeUserPreferences(), ArtworkStore(File(context.cacheDir, "art")), scope = scope)
|
||||||
|
queues = QueueRepository(db)
|
||||||
repository =
|
repository =
|
||||||
LibraryRepository(
|
LibraryRepository(
|
||||||
db,
|
db,
|
||||||
sourceRepository,
|
sourceRepository,
|
||||||
NetworkServerActionSink(sourceRepository),
|
NetworkServerActionSink(sourceRepository),
|
||||||
fakeUserPreferences(),
|
fakeUserPreferences(),
|
||||||
queueRepository = QueueRepository(db),
|
queueRepository = queues,
|
||||||
showMessage = { messages += it.resolve(resources) },
|
showMessage = { messages += it.resolve(resources) },
|
||||||
scope = scope,
|
scope = scope,
|
||||||
)
|
)
|
||||||
@@ -160,6 +162,26 @@ class LibraryRepositoryTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun starringAMissingSongDoesNotResetTheStarredQueue() =
|
||||||
|
runBlocking {
|
||||||
|
withSource { server ->
|
||||||
|
val sourceId = sourceRepository.activeSourceIdOnce()!!
|
||||||
|
db.libraryDao().setSongStar(sourceId, "s1", 1)
|
||||||
|
queues.replace(listOf(queues.starredEntry(sourceId).copy(rangeStart = 0, rangeEnd = 0)))
|
||||||
|
val before = queues.snapshot()
|
||||||
|
server.enqueue(ok())
|
||||||
|
|
||||||
|
assertTrue(repository.setStar(StarType.Song, "pruned-id", true).isSuccess)
|
||||||
|
|
||||||
|
val after = queues.snapshot()
|
||||||
|
assertEquals(before.resetVersion, after.resetVersion)
|
||||||
|
assertEquals(before.entries.map { it.entry }, after.entries.map { it.entry })
|
||||||
|
assertNull(db.libraryDao().songOnce(sourceId, "pruned-id"))
|
||||||
|
assertEquals("/rest/star.view", server.takeRequest().requestUrl!!.encodedPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun albumSongOrdinalFollowsTheAlbumOrder() =
|
fun albumSongOrdinalFollowsTheAlbumOrder() =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
|
|||||||
Reference in New Issue
Block a user