Fix moving a track down in a playlist

Yandex reads both operations of a change against the playlist as it was, so
deleting a track and inserting it at the next row's index put it back where
it was. A track moving down is now inserted after the row it passes. Moving
up was already right. The fix is in the shared client, so the TV app gets it
too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yuriy PanovandClaude Opus 5.5 committed 2026-10-23 16:27:59 +06:00
1 parent 8b7778d95c
commit a60194c5a7
3 files changed
+5 -3

No files matched your search

@@ -456,7 +456,9 @@ class YmClient private constructor(
/** Moves the track at `from` so it ends up at `to`. */
suspend fun moveInPlaylist(id: PlaylistId, track: Track, from: Int, to: Int) {
val add = insert(to, track)
// Yandex reads both operations against the playlist as it was, so a track moving down
// is inserted after the row it passes, not at that row's index.
val add = insert(if (to > from) to + 1 else to, track)
val (rev, _) = revision(id)
change(id, JsonArray(listOf(delete(from, from + 1), add)), rev)
}