aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Playlists
diff options
context:
space:
mode:
authorQuyet Vu <72632257+quyet-v@users.noreply.github.com>2025-03-31 16:39:51 +1300
committerGitHub <noreply@github.com>2025-03-30 21:39:51 -0600
commit2ace8803453b235b0b0ae29f0069f9e5a3c069c8 (patch)
tree577be35d5efbc012050409c38df85200e636d0ca /Emby.Server.Implementations/Playlists
parentd7b786e7778c42a02b9fad2024ce4eea9af035a6 (diff)
Fix playlist order (#13730)
* Fix playlist order move * Remove extra space * Added more test cases * Change namespace to file-scoped
Diffstat (limited to 'Emby.Server.Implementations/Playlists')
-rw-r--r--Emby.Server.Implementations/Playlists/PlaylistManager.cs12
1 files changed, 11 insertions, 1 deletions
diff --git a/Emby.Server.Implementations/Playlists/PlaylistManager.cs b/Emby.Server.Implementations/Playlists/PlaylistManager.cs
index 7b0a16441..98a43b6c9 100644
--- a/Emby.Server.Implementations/Playlists/PlaylistManager.cs
+++ b/Emby.Server.Implementations/Playlists/PlaylistManager.cs
@@ -283,6 +283,16 @@ namespace Emby.Server.Implementations.Playlists
RefreshPriority.High);
}
+ internal static int DetermineAdjustedIndex(int newPriorIndexAllChildren, int newIndex)
+ {
+ if (newIndex == 0)
+ {
+ return newPriorIndexAllChildren > 0 ? newPriorIndexAllChildren - 1 : 0;
+ }
+
+ return newPriorIndexAllChildren + 1;
+ }
+
public async Task MoveItemAsync(string playlistId, string entryId, int newIndex, Guid callingUserId)
{
if (_libraryManager.GetItemById(playlistId) is not Playlist playlist)
@@ -305,7 +315,7 @@ namespace Emby.Server.Implementations.Playlists
var newPriorItemIndex = newIndex > oldIndexAccessible ? newIndex : newIndex - 1 < 0 ? 0 : newIndex - 1;
var newPriorItemId = accessibleChildren[newPriorItemIndex].Item1.ItemId;
var newPriorItemIndexOnAllChildren = children.FindIndex(c => c.Item1.ItemId.Equals(newPriorItemId));
- var adjustedNewIndex = newPriorItemIndexOnAllChildren + 1;
+ var adjustedNewIndex = DetermineAdjustedIndex(newPriorItemIndexOnAllChildren, newIndex);
var item = playlist.LinkedChildren.FirstOrDefault(i => string.Equals(entryId, i.ItemId?.ToString("N", CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase));
if (item is null)