diff --git a/PlexRequests.Store/RequestedModel.cs b/PlexRequests.Store/RequestedModel.cs index 4b6f288cf..0f4a28f23 100644 --- a/PlexRequests.Store/RequestedModel.cs +++ b/PlexRequests.Store/RequestedModel.cs @@ -40,6 +40,7 @@ namespace PlexRequests.Store public List RequestedUsers { get; set; } public string ArtistName { get; set; } public string ArtistId { get; set; } + public List UsersToNotify { get; private set; } [JsonIgnore] public List AllUsers @@ -61,18 +62,27 @@ namespace PlexRequests.Store } [JsonIgnore] - public bool CanApprove - { - get - { - return !Approved && !Available; - } - } + public bool CanApprove => !Approved && !Available; public bool UserHasRequested(string username) { return AllUsers.Any(x => x.Equals(username, StringComparison.OrdinalIgnoreCase)); } + + public void AddUserToNotification(string username) + { + if (UsersToNotify == null) + { + UsersToNotify = new List(); + } + if (UsersToNotify.FirstOrDefault(x => x == username) != null) + { + // User already exists in the notification list + return; + } + + UsersToNotify.Add(username); + } } public enum RequestType diff --git a/PlexRequests.UI/Content/search.js b/PlexRequests.UI/Content/search.js index e92b32454..363e79689 100644 --- a/PlexRequests.UI/Content/search.js +++ b/PlexRequests.UI/Content/search.js @@ -114,6 +114,10 @@ $(function () { var url = $form.prop('action'); var data = $form.serialize(); + var $notify = $('#notifyUser').is(':checked'); + + data = data + "¬ify=" + $notify; + sendRequestAjax(data, type, url, buttonId); }); diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 3001b8511..8f9e1ed4c 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -97,7 +97,7 @@ namespace PlexRequests.UI.Modules Get["movie/upcoming"] = parameters => UpcomingMovies(); Get["movie/playing"] = parameters => CurrentlyPlayingMovies(); - Post["request/movie"] = parameters => RequestMovie((int)Request.Form.movieId); + Post["request/movie"] = parameters => RequestMovie((int)Request.Form.movieId, (bool)Request.Form.notify); Post["request/tv"] = parameters => RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons); Post["request/album"] = parameters => RequestAlbum((string)Request.Form.albumId); } @@ -211,7 +211,7 @@ namespace PlexRequests.UI.Modules var cpCached = CpCacher.QueuedIds(); var plexMovies = Checker.GetPlexMovies(); - + var settings = PrService.GetSettings(); var viewMovies = new List(); foreach (MovieResult movie in apiMovies) { @@ -232,12 +232,12 @@ namespace PlexRequests.UI.Modules VoteAverage = movie.VoteAverage, VoteCount = movie.VoteCount }; - + var canSee = CanUserSeeThisRequest(viewMovie.Id, settings.UsersCanViewOnlyOwnRequests, dbMovies); if (Checker.IsMovieAvailable(plexMovies.ToArray(), movie.Title, movie.ReleaseDate?.Year.ToString())) { viewMovie.Available = true; } - else if (dbMovies.ContainsKey(movie.Id)) // compare to the requests db + else if (dbMovies.ContainsKey(movie.Id) && canSee) // compare to the requests db { var dbm = dbMovies[movie.Id]; @@ -245,7 +245,7 @@ namespace PlexRequests.UI.Modules viewMovie.Approved = dbm.Approved; viewMovie.Available = dbm.Available; } - else if (cpCached.Contains(movie.Id)) // compare to the couchpotato db + else if (cpCached.Contains(movie.Id) && canSee) // compare to the couchpotato db { viewMovie.Requested = true; } @@ -256,6 +256,17 @@ namespace PlexRequests.UI.Modules return Response.AsJson(viewMovies); } + private bool CanUserSeeThisRequest(int movieId, bool usersCanViewOnlyOwnRequests, Dictionary moviesInDb) + { + if (usersCanViewOnlyOwnRequests) + { + var result = moviesInDb.FirstOrDefault(x => x.Value.ProviderId == movieId); + return result.Value != null && result.Value.UserHasRequested(Username); + } + + return true; + } + private Response SearchTvShow(string searchTerm) { Log.Trace("Searching for TV Show {0}", searchTerm); @@ -409,7 +420,7 @@ namespace PlexRequests.UI.Modules return Response.AsJson(viewAlbum); } - private Response RequestMovie(int movieId) + private Response RequestMovie(int movieId, bool notify = false) { var movieApi = new TheMovieDbApi(); var movieInfo = movieApi.GetMovieInformation(movieId).Result; @@ -428,6 +439,10 @@ namespace PlexRequests.UI.Modules // check if the current user is already marked as a requester for this movie, if not, add them if (!existingRequest.UserHasRequested(Username)) { + if (notify) + { + existingRequest.AddUserToNotification(Username); + } existingRequest.RequestedUsers.Add(Username); RequestService.UpdateRequest(existingRequest); } @@ -463,10 +478,16 @@ namespace PlexRequests.UI.Modules Status = movieInfo.Status, RequestedDate = DateTime.UtcNow, Approved = false, - RequestedUsers = new List() { Username }, + RequestedUsers = new List { Username }, Issues = IssueState.None, + }; + if (notify) + { + model.AddUserToNotification(Username); + } + Log.Trace(settings.DumpJson()); if (ShouldAutoApprove(RequestType.Movie, settings)) { diff --git a/PlexRequests.UI/Views/Search/Index.cshtml b/PlexRequests.UI/Views/Search/Index.cshtml index 9293f05d9..1c419cdc8 100644 --- a/PlexRequests.UI/Views/Search/Index.cshtml +++ b/PlexRequests.UI/Views/Search/Index.cshtml @@ -12,6 +12,14 @@

Want to watch something that is not currently on Plex?! No problem! Just search for it below and request it!


+
+
+ +
+
+ - +
@if (Model.SearchForMovies) @@ -136,26 +144,26 @@ {{#if_eq available true}} {{else}} - {{#if_eq requested true}} - - {{else}} - {{#if_eq type "movie"}} - - {{/if_eq}} - {{#if_eq type "tv"}} - - {{/if_eq}} - {{/if_eq}} + {{#if_eq requested true}} + + {{else}} + {{#if_eq type "movie"}} + + {{/if_eq}} + {{#if_eq type "tv"}} + + {{/if_eq}} + {{/if_eq}} {{/if_eq}}

@@ -201,11 +209,11 @@ {{#if_eq available true}} {{else}} - {{#if_eq requested true}} - - {{else}} - - {{/if_eq}} + {{#if_eq requested true}} + + {{else}} + + {{/if_eq}} {{/if_eq}}
Track Count: {{trackCount}}