mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-23 22:25:14 -04:00
New: Notifications (Connect) Status
(cherry picked from commit e3545801721e00d4e5cac3fa534e66dcbe9d2d05) (cherry picked from commit cb27b05a6c046ca0a6e4998f7e7ecd6b45add1a2)
This commit is contained in:
@@ -9,86 +9,167 @@ namespace NzbDrone.Core.Notifications
|
||||
{
|
||||
public interface INotificationFactory : IProviderFactory<INotification, NotificationDefinition>
|
||||
{
|
||||
List<INotification> OnGrabEnabled();
|
||||
List<INotification> OnDownloadEnabled();
|
||||
List<INotification> OnUpgradeEnabled();
|
||||
List<INotification> OnRenameEnabled();
|
||||
List<INotification> OnMovieAddedEnabled();
|
||||
List<INotification> OnMovieDeleteEnabled();
|
||||
List<INotification> OnMovieFileDeleteEnabled();
|
||||
List<INotification> OnHealthIssueEnabled();
|
||||
List<INotification> OnHealthRestoredEnabled();
|
||||
List<INotification> OnApplicationUpdateEnabled();
|
||||
List<INotification> OnManualInteractionEnabled();
|
||||
List<INotification> OnGrabEnabled(bool filterBlockedNotifications = true);
|
||||
List<INotification> OnDownloadEnabled(bool filterBlockedNotifications = true);
|
||||
List<INotification> OnUpgradeEnabled(bool filterBlockedNotifications = true);
|
||||
List<INotification> OnRenameEnabled(bool filterBlockedNotifications = true);
|
||||
List<INotification> OnMovieAddedEnabled(bool filterBlockedNotifications = true);
|
||||
List<INotification> OnMovieDeleteEnabled(bool filterBlockedNotifications = true);
|
||||
List<INotification> OnMovieFileDeleteEnabled(bool filterBlockedNotifications = true);
|
||||
List<INotification> OnHealthIssueEnabled(bool filterBlockedNotifications = true);
|
||||
List<INotification> OnHealthRestoredEnabled(bool filterBlockedNotifications = true);
|
||||
List<INotification> OnApplicationUpdateEnabled(bool filterBlockedNotifications = true);
|
||||
List<INotification> OnManualInteractionEnabled(bool filterBlockedNotifications = true);
|
||||
}
|
||||
|
||||
public class NotificationFactory : ProviderFactory<INotification, NotificationDefinition>, INotificationFactory
|
||||
{
|
||||
public NotificationFactory(INotificationRepository providerRepository, IEnumerable<INotification> providers, IServiceProvider container, IEventAggregator eventAggregator, Logger logger)
|
||||
private readonly INotificationStatusService _notificationStatusService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public NotificationFactory(INotificationStatusService notificationStatusService, INotificationRepository providerRepository, IEnumerable<INotification> providers, IServiceProvider container, IEventAggregator eventAggregator, Logger logger)
|
||||
: base(providerRepository, providers, container, eventAggregator, logger)
|
||||
{
|
||||
_notificationStatusService = notificationStatusService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<INotification> OnGrabEnabled()
|
||||
public List<INotification> OnGrabEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnGrab)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnGrab).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnDownloadEnabled()
|
||||
public List<INotification> OnDownloadEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnDownload)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnDownload).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnUpgradeEnabled()
|
||||
public List<INotification> OnUpgradeEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnUpgrade)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnUpgrade).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnRenameEnabled()
|
||||
public List<INotification> OnRenameEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnRename)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnRename).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnMovieAddedEnabled()
|
||||
public List<INotification> OnMovieAddedEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnMovieAdded)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnMovieAdded).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnMovieDeleteEnabled()
|
||||
public List<INotification> OnMovieDeleteEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnMovieDelete)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnMovieDelete).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnMovieFileDeleteEnabled()
|
||||
public List<INotification> OnMovieFileDeleteEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnMovieFileDelete)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnMovieFileDelete).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnMovieFileDeleteForUpgradeEnabled()
|
||||
public List<INotification> OnMovieFileDeleteForUpgradeEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnMovieFileDeleteForUpgrade)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnMovieFileDeleteForUpgrade).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnHealthIssueEnabled()
|
||||
public List<INotification> OnHealthIssueEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnHealthIssue)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnHealthIssue).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnHealthRestoredEnabled()
|
||||
public List<INotification> OnHealthRestoredEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnHealthRestored)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnHealthRestored).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnApplicationUpdateEnabled()
|
||||
public List<INotification> OnApplicationUpdateEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnApplicationUpdate)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnApplicationUpdate).ToList();
|
||||
}
|
||||
|
||||
public List<INotification> OnManualInteractionEnabled()
|
||||
public List<INotification> OnManualInteractionEnabled(bool filterBlockedNotifications = true)
|
||||
{
|
||||
if (filterBlockedNotifications)
|
||||
{
|
||||
return FilterBlockedNotifications(GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnManualInteractionRequired)).ToList();
|
||||
}
|
||||
|
||||
return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnManualInteractionRequired).ToList();
|
||||
}
|
||||
|
||||
private IEnumerable<INotification> FilterBlockedNotifications(IEnumerable<INotification> notifications)
|
||||
{
|
||||
var blockedNotifications = _notificationStatusService.GetBlockedProviders().ToDictionary(v => v.ProviderId, v => v);
|
||||
|
||||
foreach (var notification in notifications)
|
||||
{
|
||||
if (blockedNotifications.TryGetValue(notification.Definition.Id, out var notificationStatus))
|
||||
{
|
||||
_logger.Debug("Temporarily ignoring notification {0} till {1} due to recent failures.", notification.Definition.Name, notificationStatus.DisabledTill.Value.ToLocalTime());
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return notification;
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetProviderCharacteristics(INotification provider, NotificationDefinition definition)
|
||||
{
|
||||
base.SetProviderCharacteristics(provider, definition);
|
||||
|
||||
Reference in New Issue
Block a user