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