filter by date and descneding order
Some checks failed
🏗️ Build Plugin / call (push) Failing after 0s
📝 Create/Update Release Draft & Release Bump PR / call (push) Failing after 0s
🔬 Run CodeQL / call (push) Failing after 0s
🧪 Test Plugin / call (push) Failing after 0s

This commit is contained in:
Duncan Tourolle 2025-12-14 00:07:18 +01:00
parent 4679b77d1a
commit 2bcc7733b6

View File

@ -137,11 +137,11 @@ public class JellypodChannel : IChannel, IHasCacheKey, IRequiresMediaInfoCallbac
/// <inheritdoc />
public async Task<ChannelItemResult> GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken)
{
_logger.LogDebug("GetChannelItems called for folder {FolderId}", query.FolderId);
_logger.LogDebug("GetChannelItems called for folder {FolderId}, SortBy: {SortBy}, SortDescending: {SortDescending}", query.FolderId, query.SortBy, query.SortDescending);
try
{
var items = await GetFolderItemsAsync(query.FolderId, cancellationToken).ConfigureAwait(false);
var items = await GetFolderItemsAsync(query.FolderId, query.SortBy, query.SortDescending, cancellationToken).ConfigureAwait(false);
_logger.LogDebug("Returning {Count} channel items for folder {FolderId}", items.Count, query.FolderId);
return new ChannelItemResult
@ -157,7 +157,7 @@ public class JellypodChannel : IChannel, IHasCacheKey, IRequiresMediaInfoCallbac
}
}
private async Task<List<ChannelItemInfo>> GetFolderItemsAsync(string? folderId, CancellationToken cancellationToken)
private async Task<List<ChannelItemInfo>> GetFolderItemsAsync(string? folderId, ChannelItemSortField? sortBy, bool? sortDescending, CancellationToken cancellationToken)
{
// Root level - show all subscribed podcasts as folders
if (string.IsNullOrEmpty(folderId))
@ -168,7 +168,7 @@ public class JellypodChannel : IChannel, IHasCacheKey, IRequiresMediaInfoCallbac
// Podcast folder - show episodes
if (Guid.TryParse(folderId, out var podcastId))
{
return await GetPodcastEpisodesAsync(podcastId, cancellationToken).ConfigureAwait(false);
return await GetPodcastEpisodesAsync(podcastId, sortBy, sortDescending, cancellationToken).ConfigureAwait(false);
}
return new List<ChannelItemInfo>();
@ -203,7 +203,7 @@ public class JellypodChannel : IChannel, IHasCacheKey, IRequiresMediaInfoCallbac
return items;
}
private async Task<List<ChannelItemInfo>> GetPodcastEpisodesAsync(Guid podcastId, CancellationToken cancellationToken)
private async Task<List<ChannelItemInfo>> GetPodcastEpisodesAsync(Guid podcastId, ChannelItemSortField? sortBy, bool? sortDescending, CancellationToken cancellationToken)
{
var items = new List<ChannelItemInfo>();
var podcast = await _storageService.GetPodcastAsync(podcastId).ConfigureAwait(false);
@ -214,10 +214,25 @@ public class JellypodChannel : IChannel, IHasCacheKey, IRequiresMediaInfoCallbac
return items;
}
// Sort episodes by published date, newest first
var episodes = podcast.Episodes
.OrderByDescending(e => e.PublishedDate)
.ToList();
// Default to sorting by premiere date descending (newest first)
var sortField = sortBy ?? ChannelItemSortField.PremiereDate;
var descending = sortDescending ?? true;
_logger.LogDebug("Sorting episodes by {SortField}, descending: {Descending}", sortField, descending);
// Sort episodes based on query parameters
IEnumerable<Episode> sortedEpisodes = sortField switch
{
ChannelItemSortField.Name => descending
? podcast.Episodes.OrderByDescending(e => e.Title)
: podcast.Episodes.OrderBy(e => e.Title),
ChannelItemSortField.DateCreated or ChannelItemSortField.PremiereDate => descending
? podcast.Episodes.OrderByDescending(e => e.PublishedDate)
: podcast.Episodes.OrderBy(e => e.PublishedDate),
_ => podcast.Episodes.OrderByDescending(e => e.PublishedDate)
};
var episodes = sortedEpisodes.ToList();
foreach (var episode in episodes)
{