ui: validate queue moves against content revisions

This commit is contained in:
austinried
2026-11-14 12:05:29 +00:00
parent e4549f5fa1
commit b95b8c3569
3 changed files with 57 additions and 2 deletions
@@ -586,6 +586,7 @@ class PlaybackController(
from: Long,
to: Long,
resetVersion: Long? = null,
expectedContentVersion: Long? = null,
): Boolean {
if (from == to) return false
val requestedVersion = resetVersion ?: snapshot?.resetVersion ?: return false
@@ -593,6 +594,7 @@ class PlaybackController(
queueRepository.withMutationLock {
val snapshot = this@PlaybackController.snapshot ?: return@withMutationLock
if (snapshot.resetVersion != requestedVersion) return@withMutationLock
if (expectedContentVersion != null && snapshot.version != expectedContentVersion) return@withMutationLock
if (from !in 0 until snapshot.size || to !in 0 until snapshot.size) return@withMutationLock
val player = player ?: return@withMutationLock
val current = currentQueuePosition() ?: return@withMutationLock
@@ -195,7 +195,7 @@ class QueueViewModel(
}
} else {
val usedIds = updated.mapTo(HashSet()) { it.id }
val unresolvedTail = rows.filter { it.id !in usedIds }
val unresolvedTail = rows.filter { it.position > end && it.id !in usedIds }
rows.clear()
rows.addAll(updated)
rows.addAll(unresolvedTail)
@@ -302,12 +302,13 @@ class QueueViewModel(
val resetVersion = rows.firstOrNull { it.position == from }?.resetVersion ?: return rejectMove(edit, onComplete)
val targetResetVersion = targetResetVersion ?: rows.firstOrNull { it.position == to }?.resetVersion ?: resetVersion
if (resetVersion != targetResetVersion) return rejectMove(edit, onComplete)
val expectedContentVersion = queueRepository.contentVersion()
reorderPending = true
viewModelScope.launch {
try {
val applied =
mutex.withLock {
val applied = playbackController.move(from, to, resetVersion)
val applied = playbackController.move(from, to, resetVersion, expectedContentVersion)
if (!applied) rollbackReorder(edit)
reconcileLocked()
applied