@ -97,7 +97,7 @@ namespace PlexRequests.UI.Modules
Get [ "movie/upcoming" ] = parameters = > UpcomingMovies ( ) ;
Get [ "movie/upcoming" ] = parameters = > UpcomingMovies ( ) ;
Get [ "movie/playing" ] = parameters = > CurrentlyPlayingMovies ( ) ;
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/tv" ] = parameters = > RequestTvShow ( ( int ) Request . Form . tvId , ( string ) Request . Form . seasons ) ;
Post [ "request/album" ] = parameters = > RequestAlbum ( ( string ) Request . Form . albumId ) ;
Post [ "request/album" ] = parameters = > RequestAlbum ( ( string ) Request . Form . albumId ) ;
}
}
@ -211,7 +211,7 @@ namespace PlexRequests.UI.Modules
var cpCached = CpCacher . QueuedIds ( ) ;
var cpCached = CpCacher . QueuedIds ( ) ;
var plexMovies = Checker . GetPlexMovies ( ) ;
var plexMovies = Checker . GetPlexMovies ( ) ;
var settings = PrService . GetSettings ( ) ;
var viewMovies = new List < SearchMovieViewModel > ( ) ;
var viewMovies = new List < SearchMovieViewModel > ( ) ;
foreach ( MovieResult movie in apiMovies )
foreach ( MovieResult movie in apiMovies )
{
{
@ -232,12 +232,12 @@ namespace PlexRequests.UI.Modules
VoteAverage = movie . VoteAverage ,
VoteAverage = movie . VoteAverage ,
VoteCount = movie . VoteCount
VoteCount = movie . VoteCount
} ;
} ;
var canSee = CanUserSeeThisRequest ( viewMovie . Id , settings . UsersCanViewOnlyOwnRequests , dbMovies ) ;
if ( Checker . IsMovieAvailable ( plexMovies . ToArray ( ) , movie . Title , movie . ReleaseDate ? . Year . ToString ( ) ) )
if ( Checker . IsMovieAvailable ( plexMovies . ToArray ( ) , movie . Title , movie . ReleaseDate ? . Year . ToString ( ) ) )
{
{
viewMovie . Available = true ;
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 ] ;
var dbm = dbMovies [ movie . Id ] ;
@ -245,7 +245,7 @@ namespace PlexRequests.UI.Modules
viewMovie . Approved = dbm . Approved ;
viewMovie . Approved = dbm . Approved ;
viewMovie . Available = dbm . Available ;
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 ;
viewMovie . Requested = true ;
}
}
@ -256,6 +256,17 @@ namespace PlexRequests.UI.Modules
return Response . AsJson ( viewMovies ) ;
return Response . AsJson ( viewMovies ) ;
}
}
private bool CanUserSeeThisRequest ( int movieId , bool usersCanViewOnlyOwnRequests , Dictionary < int , RequestedModel > 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 )
private Response SearchTvShow ( string searchTerm )
{
{
Log . Trace ( "Searching for TV Show {0}" , searchTerm ) ;
Log . Trace ( "Searching for TV Show {0}" , searchTerm ) ;
@ -409,7 +420,7 @@ namespace PlexRequests.UI.Modules
return Response . AsJson ( viewAlbum ) ;
return Response . AsJson ( viewAlbum ) ;
}
}
private Response RequestMovie ( int movieId )
private Response RequestMovie ( int movieId , bool notify = false )
{
{
var movieApi = new TheMovieDbApi ( ) ;
var movieApi = new TheMovieDbApi ( ) ;
var movieInfo = movieApi . GetMovieInformation ( movieId ) . Result ;
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
// check if the current user is already marked as a requester for this movie, if not, add them
if ( ! existingRequest . UserHasRequested ( Username ) )
if ( ! existingRequest . UserHasRequested ( Username ) )
{
{
if ( notify )
{
existingRequest . AddUserToNotification ( Username ) ;
}
existingRequest . RequestedUsers . Add ( Username ) ;
existingRequest . RequestedUsers . Add ( Username ) ;
RequestService . UpdateRequest ( existingRequest ) ;
RequestService . UpdateRequest ( existingRequest ) ;
}
}
@ -463,10 +478,16 @@ namespace PlexRequests.UI.Modules
Status = movieInfo . Status ,
Status = movieInfo . Status ,
RequestedDate = DateTime . UtcNow ,
RequestedDate = DateTime . UtcNow ,
Approved = false ,
Approved = false ,
RequestedUsers = new List < string > ( ) { Username } ,
RequestedUsers = new List < string > { Username } ,
Issues = IssueState . None ,
Issues = IssueState . None ,
} ;
} ;
if ( notify )
{
model . AddUserToNotification ( Username ) ;
}
Log . Trace ( settings . DumpJson ( ) ) ;
Log . Trace ( settings . DumpJson ( ) ) ;
if ( ShouldAutoApprove ( RequestType . Movie , settings ) )
if ( ShouldAutoApprove ( RequestType . Movie , settings ) )
{
{