diff --git a/src/NzbDrone.Core/Download/FailedDownloadService.cs b/src/NzbDrone.Core/Download/FailedDownloadService.cs index a710a924f4..72b33dca8b 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/FailedDownloadService.cs @@ -40,12 +40,23 @@ public void MarkAsFailed(int historyId, bool skipRedownload = false) if (downloadId.IsNullOrWhiteSpace()) { PublishDownloadFailedEvent(new List { history }, "Manually marked as failed", skipRedownload: skipRedownload); + + return; } - else + + var grabbedHistory = new List(); + + // If the history item is a grabbed item (it should be, at least from the UI) add it as the first history item + if (history.EventType == EntityHistoryEventType.Grabbed) { - var grabbedHistory = _historyService.Find(downloadId, EntityHistoryEventType.Grabbed).ToList(); - PublishDownloadFailedEvent(grabbedHistory, "Manually marked as failed"); + grabbedHistory.Add(history); } + + // Add any other history items for the download ID then filter out any duplicate history items. + grabbedHistory.AddRange(_historyService.Find(downloadId, EntityHistoryEventType.Grabbed)); + grabbedHistory = grabbedHistory.DistinctBy(h => h.Id).ToList(); + + PublishDownloadFailedEvent(grabbedHistory, "Manually marked as failed"); } public void MarkAsFailed(string downloadId, bool skipRedownload = false) @@ -56,7 +67,7 @@ public void MarkAsFailed(string downloadId, bool skipRedownload = false) { var trackedDownload = _trackedDownloadService.Find(downloadId); - PublishDownloadFailedEvent(history, "Manually marked as failed", trackedDownload, skipRedownload); + PublishDownloadFailedEvent(history, "Manually marked as failed", trackedDownload, skipRedownload: skipRedownload); } } @@ -124,7 +135,7 @@ private void PublishDownloadFailedEvent(List historyItems, string var downloadFailedEvent = new DownloadFailedEvent { ArtistId = historyItem.ArtistId, - AlbumIds = historyItems.Select(h => h.AlbumId).ToList(), + AlbumIds = historyItems.Select(h => h.AlbumId).Distinct().ToList(), Quality = historyItem.Quality, SourceTitle = historyItem.SourceTitle, DownloadClient = historyItem.Data.GetValueOrDefault(EntityHistory.DOWNLOAD_CLIENT),