mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 08:11:10 +00:00
Adds playback preferences and auto-persisted playback state to user settings
This commit is contained in:
1 parent
aab36dcd29
commit
dd76309ded
81 files changed
+6102
-173
No files matched your search
@@ -14,5 +14,15 @@ public static partial class Errors
|
||||
public static Error UserSettingsAlreadyExists => Error.Conflict(description: nameof(UserSettingsAlreadyExists));
|
||||
public static Error UserSettingsNotFound => Error.NotFound(description: nameof(UserSettingsNotFound));
|
||||
public static Error ItemsPerPageMustBeGreaterThanZero => Error.Validation(description: nameof(ItemsPerPageMustBeGreaterThanZero));
|
||||
public static Error VolumeCannotBeNull => Error.Validation(description: nameof(VolumeCannotBeNull));
|
||||
public static Error VolumeMustBeBetweenZeroAndOne => Error.Validation(description: nameof(VolumeMustBeBetweenZeroAndOne));
|
||||
public static Error IsMutedCannotBeNull => Error.Validation(description: nameof(IsMutedCannotBeNull));
|
||||
public static Error ShouldKeepDownloadingWhilePausedCannotBeNull => Error.Validation(description: nameof(ShouldKeepDownloadingWhilePausedCannotBeNull));
|
||||
public static Error ShouldAutoplayCannotBeNull => Error.Validation(description: nameof(ShouldAutoplayCannotBeNull));
|
||||
public static Error IsGaplessPlaybackEnabledCannotBeNull => Error.Validation(description: nameof(IsGaplessPlaybackEnabledCannotBeNull));
|
||||
public static Error ReplayGainModeCannotBeNull => Error.Validation(description: nameof(ReplayGainModeCannotBeNull));
|
||||
public static Error StreamingQualityCannotBeNull => Error.Validation(description: nameof(StreamingQualityCannotBeNull));
|
||||
public static Error InvalidReplayGainMode => Error.Validation(description: nameof(InvalidReplayGainMode));
|
||||
public static Error InvalidStreamingQuality => Error.Validation(description: nameof(InvalidStreamingQuality));
|
||||
}
|
||||
}
|
||||
+165
-30
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -23,6 +23,13 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
private const bool DEFAULT_AGGREGATE_ARTWORK_WHEN_MISSING = false;
|
||||
private const bool DEFAULT_SHOULD_RENDER_PDF_AS_IMAGES = false;
|
||||
private const bool DEFAULT_SHOULD_PRESERVE_BOOK_STYLES = true;
|
||||
private const bool DEFAULT_SHOULD_KEEP_DOWNLOADING_WHILE_PAUSED = true;
|
||||
private const bool DEFAULT_SHOULD_AUTOPLAY = true;
|
||||
private const bool DEFAULT_IS_GAPLESS_PLAYBACK_ENABLED = true;
|
||||
private const ReplayGainMode DEFAULT_REPLAY_GAIN_MODE = ReplayGainMode.Off;
|
||||
private const PlaybackStreamingQuality DEFAULT_STREAMING_QUALITY = PlaybackStreamingQuality.Auto;
|
||||
private const double DEFAULT_VOLUME = 1.0;
|
||||
private const bool DEFAULT_IS_MUTED = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the object representing the unique identifier of the user that owns these settings.
|
||||
@@ -72,6 +79,41 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
/// </summary>
|
||||
public bool ShouldPreserveBookStyles { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the player keeps downloading a track while playback is paused, or not, up to the entire file.
|
||||
/// </summary>
|
||||
public bool ShouldKeepDownloadingWhilePaused { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the player continues playback at the end of an album or artist, or not.
|
||||
/// </summary>
|
||||
public bool ShouldAutoplay { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the player transitions between consecutive tracks without a gap, or not.
|
||||
/// </summary>
|
||||
public bool IsGaplessPlaybackEnabled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the way ReplayGain normalization is applied to the tracks the user plays.
|
||||
/// </summary>
|
||||
public ReplayGainMode ReplayGainMode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the quality cap applied to the audio the server normalizes for the user.
|
||||
/// </summary>
|
||||
public PlaybackStreamingQuality StreamingQuality { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last volume the player reported for the user. It is written automatically by the player, and is not part of the settings the user edits.
|
||||
/// </summary>
|
||||
public double Volume { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last mute state the player reported for the user. It is written automatically by the player, and is not part of the settings the user edits.
|
||||
/// </summary>
|
||||
public bool IsMuted { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserSettings"/> class.
|
||||
/// </summary>
|
||||
@@ -85,6 +127,13 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
/// <param name="shouldAggregateArtworkWhenMissing">Whether the artwork of the media library items is aggregated from multiple providers, when it is missing, or not.</param>
|
||||
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user, or not.</param>
|
||||
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user, or not.</param>
|
||||
/// <param name="shouldKeepDownloadingWhilePaused">Whether the player keeps downloading a track while playback is paused, or not.</param>
|
||||
/// <param name="shouldAutoplay">Whether the player continues playback at the end of an album or artist, or not.</param>
|
||||
/// <param name="isGaplessPlaybackEnabled">Whether the player transitions between consecutive tracks without a gap, or not.</param>
|
||||
/// <param name="replayGainMode">The way ReplayGain normalization is applied to the tracks the user plays.</param>
|
||||
/// <param name="streamingQuality">The quality cap applied to the audio the server normalizes for the user.</param>
|
||||
/// <param name="volume">The last volume the player reported for the user.</param>
|
||||
/// <param name="isMuted">The last mute state the player reported for the user.</param>
|
||||
private UserSettings(
|
||||
UserSettingsId id,
|
||||
UserId userId,
|
||||
@@ -95,7 +144,14 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
bool shouldAggregateMetadataWhenMissing,
|
||||
bool shouldAggregateArtworkWhenMissing,
|
||||
bool shouldRenderPdfAsImages,
|
||||
bool shouldPreserveBookStyles) : base(id)
|
||||
bool shouldPreserveBookStyles,
|
||||
bool shouldKeepDownloadingWhilePaused,
|
||||
bool shouldAutoplay,
|
||||
bool isGaplessPlaybackEnabled,
|
||||
ReplayGainMode replayGainMode,
|
||||
PlaybackStreamingQuality streamingQuality,
|
||||
double volume,
|
||||
bool isMuted) : base(id)
|
||||
{
|
||||
UserId = userId;
|
||||
IsPaginationEnabled = isPaginationEnabled;
|
||||
@@ -106,6 +162,13 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
ShouldAggregateArtworkWhenMissing = shouldAggregateArtworkWhenMissing;
|
||||
ShouldRenderPdfAsImages = shouldRenderPdfAsImages;
|
||||
ShouldPreserveBookStyles = shouldPreserveBookStyles;
|
||||
ShouldKeepDownloadingWhilePaused = shouldKeepDownloadingWhilePaused;
|
||||
ShouldAutoplay = shouldAutoplay;
|
||||
IsGaplessPlaybackEnabled = isGaplessPlaybackEnabled;
|
||||
ReplayGainMode = replayGainMode;
|
||||
StreamingQuality = streamingQuality;
|
||||
Volume = volume;
|
||||
IsMuted = isMuted;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -117,15 +180,22 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
public static Result<UserSettings> Create()
|
||||
{
|
||||
return Create(
|
||||
UserId.CreateUnique(),
|
||||
DEFAULT_IS_PAGINATION_ENABLED,
|
||||
DEFAULT_ITEMS_PER_PAGE,
|
||||
DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER,
|
||||
DEFAULT_IS_THEME_CACHING_ENABLED,
|
||||
DEFAULT_AGGREGATE_METADATA_WHEN_MISSING,
|
||||
UserId.CreateUnique(),
|
||||
DEFAULT_IS_PAGINATION_ENABLED,
|
||||
DEFAULT_ITEMS_PER_PAGE,
|
||||
DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER,
|
||||
DEFAULT_IS_THEME_CACHING_ENABLED,
|
||||
DEFAULT_AGGREGATE_METADATA_WHEN_MISSING,
|
||||
DEFAULT_AGGREGATE_ARTWORK_WHEN_MISSING,
|
||||
DEFAULT_SHOULD_RENDER_PDF_AS_IMAGES,
|
||||
DEFAULT_SHOULD_PRESERVE_BOOK_STYLES
|
||||
DEFAULT_SHOULD_PRESERVE_BOOK_STYLES,
|
||||
DEFAULT_SHOULD_KEEP_DOWNLOADING_WHILE_PAUSED,
|
||||
DEFAULT_SHOULD_AUTOPLAY,
|
||||
DEFAULT_IS_GAPLESS_PLAYBACK_ENABLED,
|
||||
DEFAULT_REPLAY_GAIN_MODE,
|
||||
DEFAULT_STREAMING_QUALITY,
|
||||
DEFAULT_VOLUME,
|
||||
DEFAULT_IS_MUTED
|
||||
);
|
||||
}
|
||||
|
||||
@@ -139,15 +209,22 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
public static Result<UserSettings> Create(UserId userId)
|
||||
{
|
||||
return Create(
|
||||
userId,
|
||||
DEFAULT_IS_PAGINATION_ENABLED,
|
||||
DEFAULT_ITEMS_PER_PAGE,
|
||||
DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER,
|
||||
DEFAULT_IS_THEME_CACHING_ENABLED,
|
||||
DEFAULT_AGGREGATE_METADATA_WHEN_MISSING,
|
||||
userId,
|
||||
DEFAULT_IS_PAGINATION_ENABLED,
|
||||
DEFAULT_ITEMS_PER_PAGE,
|
||||
DEFAULT_IGNORE_THE_PREFIX_FOR_ALPHA_PICKER,
|
||||
DEFAULT_IS_THEME_CACHING_ENABLED,
|
||||
DEFAULT_AGGREGATE_METADATA_WHEN_MISSING,
|
||||
DEFAULT_AGGREGATE_ARTWORK_WHEN_MISSING,
|
||||
DEFAULT_SHOULD_RENDER_PDF_AS_IMAGES,
|
||||
DEFAULT_SHOULD_PRESERVE_BOOK_STYLES
|
||||
DEFAULT_SHOULD_PRESERVE_BOOK_STYLES,
|
||||
DEFAULT_SHOULD_KEEP_DOWNLOADING_WHILE_PAUSED,
|
||||
DEFAULT_SHOULD_AUTOPLAY,
|
||||
DEFAULT_IS_GAPLESS_PLAYBACK_ENABLED,
|
||||
DEFAULT_REPLAY_GAIN_MODE,
|
||||
DEFAULT_STREAMING_QUALITY,
|
||||
DEFAULT_VOLUME,
|
||||
DEFAULT_IS_MUTED
|
||||
);
|
||||
}
|
||||
|
||||
@@ -163,6 +240,13 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
/// <param name="shouldAggregateArtworkWhenMissing">Whether the artwork of the media library items is aggregated from multiple providers, when it is missing, or not.</param>
|
||||
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user, or not.</param>
|
||||
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user, or not.</param>
|
||||
/// <param name="shouldKeepDownloadingWhilePaused">Whether the player keeps downloading a track while playback is paused, or not.</param>
|
||||
/// <param name="shouldAutoplay">Whether the player continues playback at the end of an album or artist, or not.</param>
|
||||
/// <param name="isGaplessPlaybackEnabled">Whether the player transitions between consecutive tracks without a gap, or not.</param>
|
||||
/// <param name="replayGainMode">The way ReplayGain normalization is applied to the tracks the user plays.</param>
|
||||
/// <param name="streamingQuality">The quality cap applied to the audio the server normalizes for the user.</param>
|
||||
/// <param name="volume">The last volume the player reported for the user.</param>
|
||||
/// <param name="isMuted">The last mute state the player reported for the user.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="UserSettings"/>, or an error message.
|
||||
/// </returns>
|
||||
@@ -175,11 +259,15 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
bool shouldAggregateMetadataWhenMissing,
|
||||
bool shouldAggregateArtworkWhenMissing,
|
||||
bool shouldRenderPdfAsImages,
|
||||
bool shouldPreserveBookStyles)
|
||||
bool shouldPreserveBookStyles,
|
||||
bool shouldKeepDownloadingWhilePaused,
|
||||
bool shouldAutoplay,
|
||||
bool isGaplessPlaybackEnabled,
|
||||
ReplayGainMode replayGainMode,
|
||||
PlaybackStreamingQuality streamingQuality,
|
||||
double volume,
|
||||
bool isMuted)
|
||||
{
|
||||
if (itemsPerPage <= 0)
|
||||
return Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero;
|
||||
|
||||
return new UserSettings(
|
||||
UserSettingsId.CreateUnique(),
|
||||
userId,
|
||||
@@ -190,7 +278,14 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
shouldAggregateMetadataWhenMissing,
|
||||
shouldAggregateArtworkWhenMissing,
|
||||
shouldRenderPdfAsImages,
|
||||
shouldPreserveBookStyles);
|
||||
shouldPreserveBookStyles,
|
||||
shouldKeepDownloadingWhilePaused,
|
||||
shouldAutoplay,
|
||||
isGaplessPlaybackEnabled,
|
||||
replayGainMode,
|
||||
streamingQuality,
|
||||
volume,
|
||||
isMuted);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -206,6 +301,13 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
/// <param name="shouldAggregateArtworkWhenMissing">Whether the artwork of the media library items is aggregated from multiple providers, when it is missing, or not.</param>
|
||||
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user, or not.</param>
|
||||
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user, or not.</param>
|
||||
/// <param name="shouldKeepDownloadingWhilePaused">Whether the player keeps downloading a track while playback is paused, or not.</param>
|
||||
/// <param name="shouldAutoplay">Whether the player continues playback at the end of an album or artist, or not.</param>
|
||||
/// <param name="isGaplessPlaybackEnabled">Whether the player transitions between consecutive tracks without a gap, or not.</param>
|
||||
/// <param name="replayGainMode">The way ReplayGain normalization is applied to the tracks the user plays.</param>
|
||||
/// <param name="streamingQuality">The quality cap applied to the audio the server normalizes for the user.</param>
|
||||
/// <param name="volume">The last volume the player reported for the user.</param>
|
||||
/// <param name="isMuted">The last mute state the player reported for the user.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="UserSettings"/>, or an error message.
|
||||
/// </returns>
|
||||
@@ -219,17 +321,25 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
bool shouldAggregateMetadataWhenMissing,
|
||||
bool shouldAggregateArtworkWhenMissing,
|
||||
bool shouldRenderPdfAsImages,
|
||||
bool shouldPreserveBookStyles)
|
||||
bool shouldPreserveBookStyles,
|
||||
bool shouldKeepDownloadingWhilePaused,
|
||||
bool shouldAutoplay,
|
||||
bool isGaplessPlaybackEnabled,
|
||||
ReplayGainMode replayGainMode,
|
||||
PlaybackStreamingQuality streamingQuality,
|
||||
double volume,
|
||||
bool isMuted)
|
||||
{
|
||||
if (itemsPerPage <= 0)
|
||||
return Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero;
|
||||
|
||||
return new UserSettings(id, userId, isPaginationEnabled, itemsPerPage, shouldIgnoreThePrefixForAlphaPicker, isThemeCachingEnabled, shouldAggregateMetadataWhenMissing, shouldAggregateArtworkWhenMissing, shouldRenderPdfAsImages, shouldPreserveBookStyles);
|
||||
return new UserSettings(id, userId, isPaginationEnabled, itemsPerPage, shouldIgnoreThePrefixForAlphaPicker, isThemeCachingEnabled, shouldAggregateMetadataWhenMissing, shouldAggregateArtworkWhenMissing, shouldRenderPdfAsImages, shouldPreserveBookStyles, shouldKeepDownloadingWhilePaused, shouldAutoplay, isGaplessPlaybackEnabled, replayGainMode, streamingQuality, volume, isMuted);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the settings of the user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The playback state the player reports automatically (the volume and the mute state) is not part of the settings the user edits, so
|
||||
/// this method neither accepts nor changes it.
|
||||
/// </remarks>
|
||||
/// <param name="isPaginationEnabled">Whether pagination is enabled for the user, or not.</param>
|
||||
/// <param name="itemsPerPage">The number of library items displayed per page when pagination is enabled.</param>
|
||||
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker, or not.</param>
|
||||
@@ -238,6 +348,11 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
/// <param name="shouldAggregateArtworkWhenMissing">Whether the artwork of the media library items is aggregated from multiple providers, when it is missing, or not.</param>
|
||||
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user, or not.</param>
|
||||
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user, or not.</param>
|
||||
/// <param name="shouldKeepDownloadingWhilePaused">Whether the player keeps downloading a track while playback is paused, or not.</param>
|
||||
/// <param name="shouldAutoplay">Whether the player continues playback at the end of an album or artist, or not.</param>
|
||||
/// <param name="isGaplessPlaybackEnabled">Whether the player transitions between consecutive tracks without a gap, or not.</param>
|
||||
/// <param name="replayGainMode">The way ReplayGain normalization is applied to the tracks the user plays.</param>
|
||||
/// <param name="streamingQuality">The quality cap applied to the audio the server normalizes for the user.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful update, or an error.</returns>
|
||||
public Result<Updated> UpdateSettings(
|
||||
bool isPaginationEnabled,
|
||||
@@ -247,11 +362,13 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
bool shouldAggregateMetadataWhenMissing,
|
||||
bool shouldAggregateArtworkWhenMissing,
|
||||
bool shouldRenderPdfAsImages,
|
||||
bool shouldPreserveBookStyles)
|
||||
bool shouldPreserveBookStyles,
|
||||
bool shouldKeepDownloadingWhilePaused,
|
||||
bool shouldAutoplay,
|
||||
bool isGaplessPlaybackEnabled,
|
||||
ReplayGainMode replayGainMode,
|
||||
PlaybackStreamingQuality streamingQuality)
|
||||
{
|
||||
if (itemsPerPage <= 0)
|
||||
return Errors.UserSettings.ItemsPerPageMustBeGreaterThanZero;
|
||||
|
||||
IsPaginationEnabled = isPaginationEnabled;
|
||||
ItemsPerPage = itemsPerPage;
|
||||
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker;
|
||||
@@ -260,6 +377,24 @@ public class UserSettings : AggregateRoot<UserSettingsId>
|
||||
ShouldAggregateArtworkWhenMissing = shouldAggregateArtworkWhenMissing;
|
||||
ShouldRenderPdfAsImages = shouldRenderPdfAsImages;
|
||||
ShouldPreserveBookStyles = shouldPreserveBookStyles;
|
||||
ShouldKeepDownloadingWhilePaused = shouldKeepDownloadingWhilePaused;
|
||||
ShouldAutoplay = shouldAutoplay;
|
||||
IsGaplessPlaybackEnabled = isGaplessPlaybackEnabled;
|
||||
ReplayGainMode = replayGainMode;
|
||||
StreamingQuality = streamingQuality;
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the playback state the player reports automatically.
|
||||
/// </summary>
|
||||
/// <param name="volume">The last volume the player reported for the user.</param>
|
||||
/// <param name="isMuted">The last mute state the player reported for the user.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful update, or an error.</returns>
|
||||
public Result<Updated> UpdatePlaybackState(double volume, bool isMuted)
|
||||
{
|
||||
Volume = volume;
|
||||
IsMuted = isMuted;
|
||||
return Result.Updated;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user