mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-18 19:25:00 -04:00
Fix playlist order (#13730)
* Fix playlist order move * Remove extra space * Added more test cases * Change namespace to file-scoped
This commit is contained in:
parent
d7b786e777
commit
2ace880345
2 changed files with 51 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
using Emby.Server.Implementations.Playlists;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Server.Implementations.Tests.Playlists;
|
||||
|
||||
public class PlaylistManagerTests
|
||||
{
|
||||
[Fact]
|
||||
public void DetermineAdjustedIndexMoveToFirstPositionNoPriorInAllList()
|
||||
{
|
||||
var priorIndexAllChildren = 0;
|
||||
var newIndex = 0;
|
||||
|
||||
var adjustedIndex = PlaylistManager.DetermineAdjustedIndex(priorIndexAllChildren, newIndex);
|
||||
|
||||
Assert.Equal(0, adjustedIndex);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DetermineAdjustedIndexPriorInMiddleOfAllList()
|
||||
{
|
||||
var priorIndexAllChildren = 2;
|
||||
var newIndex = 0;
|
||||
|
||||
var adjustedIndex = PlaylistManager.DetermineAdjustedIndex(priorIndexAllChildren, newIndex);
|
||||
|
||||
Assert.Equal(1, adjustedIndex);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DetermineAdjustedIndexMoveMiddleOfPlaylist()
|
||||
{
|
||||
var priorIndexAllChildren = 2;
|
||||
var newIndex = 1;
|
||||
|
||||
var adjustedIndex = PlaylistManager.DetermineAdjustedIndex(priorIndexAllChildren, newIndex);
|
||||
|
||||
Assert.Equal(3, adjustedIndex);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue