mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 02:11:10 +00:00
Fixes media consumption tracking, statistics, and reader page counting
This commit is contained in:
1 parent
e56712731f
commit
02bcf91661
40 files changed
+298
-168
No files matched your search
+16
-1
@@ -128,7 +128,7 @@ public class GetGenreConsumptionQueryHandler : IQueryHandler<GetGenreConsumption
|
||||
Dictionary<(MediaKind MediaKind, Guid MediaItemId, Guid LibraryId), List<string>> genreNamesByItem = [];
|
||||
foreach (TrackEntity track in tracks)
|
||||
{
|
||||
List<string> itemGenres = [.. track.Genres.Select(genre => genre.Name).OfType<string>()];
|
||||
List<string> itemGenres = GetTrackGenreNames(track);
|
||||
if (itemGenres.Count > 0)
|
||||
genreNamesByItem[(MediaKind.MusicTrack, track.Id, track.LibraryId)] = itemGenres;
|
||||
}
|
||||
@@ -181,6 +181,21 @@ public class GetGenreConsumptionQueryHandler : IQueryHandler<GetGenreConsumption
|
||||
return Result.From(genreConsumptions.ToResponses());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the genre names of <paramref name="track"/>, falling back to the genres of its album and then its artist.
|
||||
/// </summary>
|
||||
/// <param name="track">The track whose genres are resolved.</param>
|
||||
/// <returns>The genre names of the track, its album, or its artist, in the first level that has any.</returns>
|
||||
private static List<string> GetTrackGenreNames(TrackEntity track)
|
||||
{
|
||||
List<string> genreNames = [.. track.Genres.Select(genre => genre.Name).OfType<string>()];
|
||||
if (genreNames.Count == 0 && track.Album is not null)
|
||||
genreNames = [.. track.Album.Genres.Select(genre => genre.Name).OfType<string>()];
|
||||
if (genreNames.Count == 0 && track.Album is not null && track.Album.Artist is not null)
|
||||
genreNames = [.. track.Album.Artist.Genres.Select(genre => genre.Name).OfType<string>()];
|
||||
return genreNames;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the lowercase <paramref name="names"/> of one item to the accumulated <paramref name="genres"/>.
|
||||
/// </summary>
|
||||
|
||||
+20
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
@@ -89,6 +90,25 @@ public class GetResumePointQueryHandler : IQueryHandler<GetResumePointQuery, Res
|
||||
if (getResumePointResult.Value is null)
|
||||
return DomainErrors.MediaConsumption.MediaResumePointNotFound;
|
||||
|
||||
// A resume point stored before progress tracking was turned off must not be served, because the library no longer remembers positions.
|
||||
// It is deleted as stale data, so turning tracking on again starts from a fresh position instead of an old one.
|
||||
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository
|
||||
.GetByIdAsync(getResumePointResult.Value.LibraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsFailure)
|
||||
return getLibraryResult.Errors;
|
||||
if (getLibraryResult.Value is not null && !getLibraryResult.Value.ShouldTrackConsumptionProgress)
|
||||
{
|
||||
Result<Deleted> deleteStaleResumePointResult = await _unitOfWork.MediaResumePointRepository.DeleteForUserAndMediaItemAsync(userId, mediaKind, mediaItemId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteStaleResumePointResult.IsFailure)
|
||||
return deleteStaleResumePointResult.Errors;
|
||||
Result<Success> saveStaleResumePointDeletionResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
// A concurrent deletion of the same stale resume point is the desired outcome, so only other persistence failures are returned.
|
||||
if (saveStaleResumePointDeletionResult.IsFailure &&
|
||||
!saveStaleResumePointDeletionResult.Errors.Any(error => error == ApplicationErrors.Persistence.ConcurrencyConflict))
|
||||
return saveStaleResumePointDeletionResult.Errors;
|
||||
return DomainErrors.MediaConsumption.MediaResumePointNotFound;
|
||||
}
|
||||
|
||||
// The media item must still exist in the library the resume point was recorded in. A resume point whose item was deleted, or whose item no
|
||||
// longer belongs to that library, is an orphan, so it is removed before the same not-found result as a missing item is returned.
|
||||
if (mediaKind == MediaKind.MusicTrack)
|
||||
|
||||
+16
-1
@@ -128,7 +128,7 @@ public class GetTagConsumptionQueryHandler : IQueryHandler<GetTagConsumptionQuer
|
||||
Dictionary<(MediaKind MediaKind, Guid MediaItemId, Guid LibraryId), List<string>> tagNamesByItem = [];
|
||||
foreach (TrackEntity track in tracks)
|
||||
{
|
||||
List<string> itemTags = [.. track.Tags.Select(tag => tag.Name).OfType<string>()];
|
||||
List<string> itemTags = GetTrackTagNames(track);
|
||||
if (itemTags.Count > 0)
|
||||
tagNamesByItem[(MediaKind.MusicTrack, track.Id, track.LibraryId)] = itemTags;
|
||||
}
|
||||
@@ -181,6 +181,21 @@ public class GetTagConsumptionQueryHandler : IQueryHandler<GetTagConsumptionQuer
|
||||
return Result.From(tagConsumptions.ToResponses());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tag names of <paramref name="track"/>, falling back to the tags of its album and then its artist.
|
||||
/// </summary>
|
||||
/// <param name="track">The track whose tags are resolved.</param>
|
||||
/// <returns>The tag names of the track, its album, or its artist, in the first level that has any.</returns>
|
||||
private static List<string> GetTrackTagNames(TrackEntity track)
|
||||
{
|
||||
List<string> tagNames = [.. track.Tags.Select(tag => tag.Name).OfType<string>()];
|
||||
if (tagNames.Count == 0 && track.Album is not null)
|
||||
tagNames = [.. track.Album.Tags.Select(tag => tag.Name).OfType<string>()];
|
||||
if (tagNames.Count == 0 && track.Album is not null && track.Album.Artist is not null)
|
||||
tagNames = [.. track.Album.Artist.Tags.Select(tag => tag.Name).OfType<string>()];
|
||||
return tagNames;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the lowercase <paramref name="names"/> of one item to the accumulated <paramref name="tags"/>.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user