mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-15 00:42:54 +01:00
sync: preserve legacy identity during queue resets
This commit is contained in:
@@ -704,13 +704,13 @@ class QueueRepository(
|
|||||||
val positionMs = if (remappedCurrent != null && previousSongId == updatedSongId) row.positionMs else 0L
|
val positionMs = if (remappedCurrent != null && previousSongId == updatedSongId) row.positionMs else 0L
|
||||||
dao.clear()
|
dao.clear()
|
||||||
dao.insert(
|
dao.insert(
|
||||||
withOriginEntryIds(entries).mapIndexed { index, entry ->
|
withOriginEntryIds(entries, assignFragmentIds = false).mapIndexed { index, entry ->
|
||||||
entry.copy(id = 0, position = index.toLong())
|
entry.copy(id = 0, position = index.toLong())
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
dao.clearUpNext()
|
dao.clearUpNext()
|
||||||
dao.insertUpNext(
|
dao.insertUpNext(
|
||||||
withOriginEntryIds(upNext).mapIndexed { index, entry ->
|
withOriginEntryIds(upNext, assignFragmentIds = false).mapIndexed { index, entry ->
|
||||||
UpNextEntry.from(entry).copy(id = 0, position = index.toLong())
|
UpNextEntry.from(entry).copy(id = 0, position = index.toLong())
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -831,7 +831,7 @@ class QueueRepository(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun QueueEntry.shouldAssignOriginEntryId(assignFragmentIds: Boolean) =
|
private fun QueueEntry.shouldAssignOriginEntryId(assignFragmentIds: Boolean) =
|
||||||
originEntryId == null && (assignFragmentIds || isWholeOrigin())
|
originEntryId == null && (assignFragmentIds || isWholeOrigin() || id == 0L)
|
||||||
|
|
||||||
private fun withOriginEntryIds(
|
private fun withOriginEntryIds(
|
||||||
entries: List<QueueEntry>,
|
entries: List<QueueEntry>,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.subtracks.data.model.PlaylistSong
|
|||||||
import com.subtracks.data.model.QueueKind
|
import com.subtracks.data.model.QueueKind
|
||||||
import com.subtracks.data.model.QueueOrigin
|
import com.subtracks.data.model.QueueOrigin
|
||||||
import com.subtracks.data.repo.QueueRepository
|
import com.subtracks.data.repo.QueueRepository
|
||||||
|
import com.subtracks.data.repo.QueueResetPreparation
|
||||||
import com.subtracks.data.repo.removeAt
|
import com.subtracks.data.repo.removeAt
|
||||||
import com.subtracks.data.repo.replace
|
import com.subtracks.data.repo.replace
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
@@ -592,7 +593,10 @@ class MigrationsTest {
|
|||||||
repository.setCursor(2)
|
repository.setCursor(2)
|
||||||
val point = repository.captureResetPoint()
|
val point = repository.captureResetPoint()
|
||||||
var resets = 0
|
var resets = 0
|
||||||
repository.setResetListener { resets++ }
|
repository.setResetListener {
|
||||||
|
resets++
|
||||||
|
QueueResetPreparation(it.snapshot)
|
||||||
|
}
|
||||||
db.libraryDao().deletePlaylistSongsFrom(1, "p1", 0)
|
db.libraryDao().deletePlaylistSongsFrom(1, "p1", 0)
|
||||||
db.libraryDao().upsertPlaylistSongs(
|
db.libraryDao().upsertPlaylistSongs(
|
||||||
listOf(
|
listOf(
|
||||||
|
|||||||
@@ -474,6 +474,9 @@ class QueueRepositoryTest {
|
|||||||
repository.removeAt(snapshot, 0)
|
repository.removeAt(snapshot, 0)
|
||||||
|
|
||||||
assertEquals(listOf("s2", "s3"), resolveAll(repository.snapshot()))
|
assertEquals(listOf("s2", "s3"), resolveAll(repository.snapshot()))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
fun aMatchingOriginStillPublishesWhenItsEntriesDoNotChange() =
|
fun aMatchingOriginStillPublishesWhenItsEntriesDoNotChange() =
|
||||||
runTest {
|
runTest {
|
||||||
seedLibrary()
|
seedLibrary()
|
||||||
|
|||||||
Reference in New Issue
Block a user