mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-16 01:00:17 +01:00
ui: validate queue moves against content revisions
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user