refactor: Change Notifications settings nullable semantics

pull/360/head
Robert Dailey 4 months ago
parent 2bde784d62
commit cbecf28b25

@ -5,13 +5,13 @@ using Serilog.Templates;
namespace Recyclarr.Notifications;
public class NotificationLogSinkConfigurator(NotificationEmitter emitter, ISettings<RecyclarrSettings> settings)
public class NotificationLogSinkConfigurator(NotificationEmitter emitter, ISettings<NotificationSettings> settings)
: ILogConfigurator
{
public void Configure(LoggerConfiguration config)
{
// If the user has disabled notifications, don't bother with adding the notification sink.
if (settings.Value.Notifications is null)
if (!settings.Value.IsConfigured())
{
return;
}

@ -22,7 +22,7 @@ public sealed class NotificationService(
private readonly Dictionary<string, List<IPresentableNotification>> _events = new();
private readonly CompositeDisposable _eventConnection = new();
private readonly AppriseNotificationSettings? _settings = settings.OptionalValue?.Apprise;
private readonly AppriseNotificationSettings? _settings = settings.Value.Apprise;
private string? _activeInstanceName;

@ -33,13 +33,15 @@ public record RecyclarrSettings
public bool EnableSslCertificateValidation { get; [UsedImplicitly] init; } = true;
public LogJanitorSettings LogJanitor { get; [UsedImplicitly] init; } = new();
public string? GitPath { get; [UsedImplicitly] init; }
public NotificationSettings? Notifications { get; [UsedImplicitly] init; }
public NotificationSettings Notifications { get; [UsedImplicitly] init; } = new();
}
public record NotificationSettings
{
public NotificationVerbosity Verbosity { get; [UsedImplicitly] init; } = NotificationVerbosity.Normal;
public AppriseNotificationSettings? Apprise { get; [UsedImplicitly] init; }
public bool IsConfigured() => Apprise is not null;
}
public enum NotificationVerbosity

@ -7,7 +7,7 @@ public class RecyclarrSettingsValidator : AbstractValidator<RecyclarrSettings>
{
public RecyclarrSettingsValidator()
{
RuleFor(x => x.Notifications).SetNonNullableValidator(new NotificationSettingsValidator());
RuleFor(x => x.Notifications).SetValidator(new NotificationSettingsValidator());
}
}

Loading…
Cancel
Save