split notification sending to seperate method

This commit is contained in:
Stevie Robinson 2024-01-31 07:57:32 +01:00
parent 0b5e19ec78
commit 74ded61a71
1 changed files with 24 additions and 52 deletions

View File

@ -73,11 +73,6 @@ namespace NzbDrone.Core.Download
var grabbedHistories = _historyService.FindByDownloadId(trackedDownload.DownloadItem.DownloadId).Where(h => h.EventType == EpisodeHistoryEventType.Grabbed).ToList();
var historyItem = grabbedHistories.MaxBy(h => h.Date);
if (grabbedHistories.Count == 0)
{
grabbedHistories = new List<EpisodeHistory> { new EpisodeHistory() };
}
if (historyItem == null && trackedDownload.DownloadItem.Category.IsNullOrWhiteSpace())
{
trackedDownload.Warn("Download wasn't grabbed by Sonarr and not in a category, Skipping.");
@ -101,16 +96,7 @@ namespace NzbDrone.Core.Download
if (series == null)
{
trackedDownload.Warn("Series title mismatch; automatic import is not possible. Check the download troubleshooting entry on the wiki for common causes.");
if (!trackedDownload.HasNotifiedManualInteractionRequired)
{
trackedDownload.HasNotifiedManualInteractionRequired = true;
var releaseInfo = new GrabbedReleaseInfo(grabbedHistories);
var manualInteractionEvent = new ManualInteractionRequiredEvent(trackedDownload, releaseInfo);
_eventAggregator.PublishEvent(manualInteractionEvent);
}
SendManualInteractionRequiredNotification(trackedDownload);
return;
}
@ -122,16 +108,7 @@ namespace NzbDrone.Core.Download
if (seriesMatchType == SeriesMatchType.Id && releaseSource != ReleaseSourceType.InteractiveSearch)
{
trackedDownload.Warn("Found matching series via grab history, but release was matched to series by ID. Automatic import is not possible. See the FAQ for details.");
if (!trackedDownload.HasNotifiedManualInteractionRequired)
{
trackedDownload.HasNotifiedManualInteractionRequired = true;
var releaseInfo = new GrabbedReleaseInfo(grabbedHistories);
var manualInteractionEvent = new ManualInteractionRequiredEvent(trackedDownload, releaseInfo);
_eventAggregator.PublishEvent(manualInteractionEvent);
}
SendManualInteractionRequiredNotification(trackedDownload);
return;
}
@ -149,26 +126,10 @@ namespace NzbDrone.Core.Download
return;
}
var grabbedHistories = _historyService.FindByDownloadId(trackedDownload.DownloadItem.DownloadId).Where(h => h.EventType == EpisodeHistoryEventType.Grabbed).ToList();
if (grabbedHistories.Count == 0)
{
grabbedHistories = new List<EpisodeHistory> { new EpisodeHistory() };
}
if (trackedDownload.RemoteEpisode == null)
{
trackedDownload.Warn("Unable to parse download, automatic import is not possible.");
if (!trackedDownload.HasNotifiedManualInteractionRequired)
{
trackedDownload.HasNotifiedManualInteractionRequired = true;
var releaseInfo = new GrabbedReleaseInfo(grabbedHistories);
var manualInteractionEvent = new ManualInteractionRequiredEvent(trackedDownload, releaseInfo);
_eventAggregator.PublishEvent(manualInteractionEvent);
}
SendManualInteractionRequiredNotification(trackedDownload);
return;
}
@ -226,16 +187,7 @@ namespace NzbDrone.Core.Download
if (statusMessages.Any())
{
trackedDownload.Warn(statusMessages.ToArray());
if (!trackedDownload.HasNotifiedManualInteractionRequired)
{
trackedDownload.HasNotifiedManualInteractionRequired = true;
var releaseInfo = new GrabbedReleaseInfo(grabbedHistories);
var manualInteractionEvent = new ManualInteractionRequiredEvent(trackedDownload, releaseInfo);
_eventAggregator.PublishEvent(manualInteractionEvent);
}
SendManualInteractionRequiredNotification(trackedDownload);
}
}
@ -302,6 +254,26 @@ namespace NzbDrone.Core.Download
return false;
}
private void SendManualInteractionRequiredNotification(TrackedDownload trackedDownload)
{
if (!trackedDownload.HasNotifiedManualInteractionRequired)
{
var grabbedHistories = _historyService.FindByDownloadId(trackedDownload.DownloadItem.DownloadId).Where(h => h.EventType == EpisodeHistoryEventType.Grabbed).ToList();
if (grabbedHistories.Count == 0)
{
grabbedHistories = new List<EpisodeHistory> { new EpisodeHistory() };
}
trackedDownload.HasNotifiedManualInteractionRequired = true;
var releaseInfo = new GrabbedReleaseInfo(grabbedHistories);
var manualInteractionEvent = new ManualInteractionRequiredEvent(trackedDownload, releaseInfo);
_eventAggregator.PublishEvent(manualInteractionEvent);
}
}
private void SetImportItem(TrackedDownload trackedDownload)
{
trackedDownload.ImportItem = _provideImportItemService.ProvideImportItem(trackedDownload.DownloadItem, trackedDownload.ImportItem);