From 69fcd8ec9447b6de651f1c560764b69614139c1f Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 2 Jul 2022 15:53:56 -0500 Subject: [PATCH] Fixed: Notify on Bulk Adds (Lists, Collections, Imports) Closes #7351 --- .../Movies/Events/MoviesImportedEvent.cs | 6 ++--- src/NzbDrone.Core/Movies/MovieAddedHandler.cs | 2 +- src/NzbDrone.Core/Movies/MovieService.cs | 2 +- .../Notifications/NotificationService.cs | 22 +++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core/Movies/Events/MoviesImportedEvent.cs b/src/NzbDrone.Core/Movies/Events/MoviesImportedEvent.cs index 7dd1cdd33..1d5a2d96b 100644 --- a/src/NzbDrone.Core/Movies/Events/MoviesImportedEvent.cs +++ b/src/NzbDrone.Core/Movies/Events/MoviesImportedEvent.cs @@ -5,11 +5,11 @@ namespace NzbDrone.Core.Movies.Events { public class MoviesImportedEvent : IEvent { - public List MovieIds { get; private set; } + public List Movies { get; private set; } - public MoviesImportedEvent(List movieIds) + public MoviesImportedEvent(List movies) { - MovieIds = movieIds; + Movies = movies; } } } diff --git a/src/NzbDrone.Core/Movies/MovieAddedHandler.cs b/src/NzbDrone.Core/Movies/MovieAddedHandler.cs index fecb27460..1e3f1a9ad 100644 --- a/src/NzbDrone.Core/Movies/MovieAddedHandler.cs +++ b/src/NzbDrone.Core/Movies/MovieAddedHandler.cs @@ -23,7 +23,7 @@ public void Handle(MovieAddedEvent message) public void Handle(MoviesImportedEvent message) { - _commandQueueManager.PushMany(message.MovieIds.Select(s => new RefreshMovieCommand(new List { s }, true)).ToList()); + _commandQueueManager.PushMany(message.Movies.Select(s => new RefreshMovieCommand(new List { s.Id }, true)).ToList()); } } } diff --git a/src/NzbDrone.Core/Movies/MovieService.cs b/src/NzbDrone.Core/Movies/MovieService.cs index ef01187d9..14bbc34c9 100644 --- a/src/NzbDrone.Core/Movies/MovieService.cs +++ b/src/NzbDrone.Core/Movies/MovieService.cs @@ -100,7 +100,7 @@ public List AddMovies(List newMovies) { _movieRepository.InsertMany(newMovies); - _eventAggregator.PublishEvent(new MoviesImportedEvent(newMovies.Select(s => s.Id).ToList())); + _eventAggregator.PublishEvent(new MoviesImportedEvent(newMovies)); return newMovies; } diff --git a/src/NzbDrone.Core/Notifications/NotificationService.cs b/src/NzbDrone.Core/Notifications/NotificationService.cs index 2bfba5116..1b3bea066 100644 --- a/src/NzbDrone.Core/Notifications/NotificationService.cs +++ b/src/NzbDrone.Core/Notifications/NotificationService.cs @@ -20,6 +20,7 @@ public class NotificationService IHandle, IHandle, IHandle, + IHandle, IHandle, IHandle, IHandle, @@ -174,6 +175,27 @@ public void Handle(MovieAddedEvent message) } } + public void Handle(MoviesImportedEvent message) + { + foreach (var notification in _notificationFactory.OnMovieAddedEnabled()) + { + try + { + foreach (var movie in message.Movies) + { + if (ShouldHandleMovie(notification.Definition, movie)) + { + notification.OnMovieAdded(movie); + } + } + } + catch (Exception ex) + { + _logger.Warn(ex, "Unable to send OnMovieAdded notification to: " + notification.Definition.Name); + } + } + } + public void Handle(MovieRenamedEvent message) { foreach (var notification in _notificationFactory.OnRenameEnabled())