diff --git a/src/Ombi.Core/Engine/BaseMediaEngine.cs b/src/Ombi.Core/Engine/BaseMediaEngine.cs index 19cab0d5a..273c71ef0 100644 --- a/src/Ombi.Core/Engine/BaseMediaEngine.cs +++ b/src/Ombi.Core/Engine/BaseMediaEngine.cs @@ -79,7 +79,7 @@ namespace Ombi.Core.Engine var pendingTv = 0; var approvedTv = 0; - var availableTv = 0; + var availableTv = 0; foreach (var tv in tvQuery) { foreach (var child in tv.ChildRequests) @@ -120,12 +120,9 @@ namespace Ombi.Core.Engine var settings = await Cache.GetOrAdd(CacheKeys.OmbiSettings, async () => await OmbiSettings.GetSettingsAsync()); var result = new HideResult { - Hide = settings.HideRequestsUsers + Hide = settings.HideRequestsUsers, + UserId = user.Id }; - if (settings.HideRequestsUsers) - { - result.UserId = user.Id; - } return result; } diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index e8c0289f3..460752bb1 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -138,10 +138,10 @@ namespace Ombi.Core.Engine { allRequests = await MovieRepository.GetWithUser().Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync(); } - allRequests.ForEach(x => + allRequests.ForEach(async x => { x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); - CheckForSubscription(shouldHide, x); + await CheckForSubscription(shouldHide, x); }); return allRequests; } @@ -176,19 +176,27 @@ namespace Ombi.Core.Engine allRequests = await MovieRepository.GetWithUser().ToListAsync(); } - allRequests.ForEach(x => + allRequests.ForEach(async x => { x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); - CheckForSubscription(shouldHide, x); + await CheckForSubscription(shouldHide, x); }); return allRequests; } - private void CheckForSubscription(HideResult shouldHide, MovieRequests x) + private async Task CheckForSubscription(HideResult shouldHide, MovieRequests x) { - var sub = _subscriptionRepository.GetAll().FirstOrDefaultAsync(s => - s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.Movie); - x.Subscribed = sub != null; + if (shouldHide.UserId == x.RequestedUserId) + { + x.ShowSubscribe = false; + } + else + { + x.ShowSubscribe = true; + var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s => + s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.Movie); + x.Subscribed = sub != null; + } } /// @@ -209,10 +217,10 @@ namespace Ombi.Core.Engine allRequests = await MovieRepository.GetWithUser().ToListAsync(); } var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList(); - results.ForEach(x => + results.ForEach(async x => { x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); - CheckForSubscription(shouldHide, x); + await CheckForSubscription(shouldHide, x); }); return results; } diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index d75df6588..d74b45e5e 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -157,6 +157,8 @@ namespace Ombi.Core.Engine .Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync(); } + allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + return allRequests; } @@ -182,25 +184,28 @@ namespace Ombi.Core.Engine .ThenInclude(x => x.Episodes) .Skip(position).Take(count).ToListAsync(); } + + allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); return ParseIntoTreeNode(allRequests); } public async Task> GetRequests() { var shouldHide = await HideFromOtherUsers(); - IQueryable allRequests; + List allRequests; if (shouldHide.Hide) { - allRequests = TvRepository.Get(shouldHide.UserId); + allRequests = await TvRepository.Get(shouldHide.UserId).ToListAsync(); FilterChildren(allRequests, shouldHide); } else { - allRequests = TvRepository.Get(); + allRequests = await TvRepository.Get().ToListAsync(); } - return await allRequests.ToListAsync(); + allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + return allRequests; } private static void FilterChildren(IEnumerable allRequests, HideResult shouldHide) @@ -233,6 +238,8 @@ namespace Ombi.Core.Engine allRequests = await TvRepository.GetChild().Include(x => x.SeasonRequests).Where(x => x.ParentRequestId == tvId).ToListAsync(); } + allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + return allRequests; } @@ -249,6 +256,8 @@ namespace Ombi.Core.Engine allRequests = TvRepository.Get(); } var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync(); + + results.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); return results; } @@ -265,6 +274,7 @@ namespace Ombi.Core.Engine allRequests = TvRepository.Get(); } var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync(); + results.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); return ParseIntoTreeNode(results); } @@ -446,6 +456,29 @@ namespace Ombi.Core.Engine } } + private async Task CheckForSubscription(HideResult shouldHide, TvRequests x) + { + foreach (var tv in x.ChildRequests) + { + await CheckForSubscription(shouldHide, tv); + } + } + + private async Task CheckForSubscription(HideResult shouldHide, ChildRequests x) + { + if (shouldHide.UserId == x.RequestedUserId) + { + x.ShowSubscribe = false; + } + else + { + x.ShowSubscribe = true; + var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s => + s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.TvShow); + x.Subscribed = sub != null; + } + } + private async Task AddExistingRequest(ChildRequests newRequest, TvRequests existingRequest) { // Add the child diff --git a/src/Ombi.Store/Entities/Requests/ChildRequests.cs b/src/Ombi.Store/Entities/Requests/ChildRequests.cs index 64c0bcc5c..3b5156ce5 100644 --- a/src/Ombi.Store/Entities/Requests/ChildRequests.cs +++ b/src/Ombi.Store/Entities/Requests/ChildRequests.cs @@ -13,6 +13,15 @@ namespace Ombi.Store.Entities.Requests public int? IssueId { get; set; } public SeriesType SeriesType { get; set; } + /// + /// This is to see if the user is subscribed in the UI + /// + [NotMapped] + public bool Subscribed { get; set; } + + [NotMapped] + public bool ShowSubscribe { get; set; } + [ForeignKey(nameof(IssueId))] public List Issues { get; set; } diff --git a/src/Ombi.Store/Entities/Requests/MovieRequests.cs b/src/Ombi.Store/Entities/Requests/MovieRequests.cs index 7dd4e557a..675035140 100644 --- a/src/Ombi.Store/Entities/Requests/MovieRequests.cs +++ b/src/Ombi.Store/Entities/Requests/MovieRequests.cs @@ -14,6 +14,8 @@ namespace Ombi.Store.Entities.Requests [NotMapped] public bool Subscribed { get; set; } + [NotMapped] + public bool ShowSubscribe { get; set; } public int RootPathOverride { get; set; } public int QualityOverride { get; set; } diff --git a/src/Ombi.Store/Entities/Requests/TvRequests.cs b/src/Ombi.Store/Entities/Requests/TvRequests.cs index f9e71bfa3..432bc88ab 100644 --- a/src/Ombi.Store/Entities/Requests/TvRequests.cs +++ b/src/Ombi.Store/Entities/Requests/TvRequests.cs @@ -17,11 +17,6 @@ namespace Ombi.Store.Entities.Requests public DateTime ReleaseDate { get; set; } public string Status { get; set; } - /// - /// This is to see if the user is subscribed in the UI - /// - [NotMapped] - public bool Subscribed { get; set; } /// /// This is so we can correctly send the right amount of seasons to Sonarr /// diff --git a/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts b/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts index 2cea1cc06..1895914c3 100644 --- a/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts +++ b/src/Ombi/ClientApp/app/interfaces/IRequestModel.ts @@ -13,6 +13,7 @@ export interface IMovieRequests extends IFullBaseRequest { qualityOverride: number; digitalReleaseDate: Date; subscribed: boolean; + showSubscribe: boolean; // For the UI rootPathOverrideTitle: string; @@ -78,6 +79,8 @@ export interface ITvRequests { export interface IChildRequests extends IBaseRequest { seasonRequests: INewSeasonRequests[]; + subscribed: boolean; + showSubscribe: boolean; } export interface ITvUpdateModel { diff --git a/src/Ombi/ClientApp/app/requests/movierequests.component.html b/src/Ombi/ClientApp/app/requests/movierequests.component.html index d8d073e1c..629fe3147 100644 --- a/src/Ombi/ClientApp/app/requests/movierequests.component.html +++ b/src/Ombi/ClientApp/app/requests/movierequests.component.html @@ -128,8 +128,8 @@
- - + +
diff --git a/src/Ombi/ClientApp/app/requests/movierequests.component.ts b/src/Ombi/ClientApp/app/requests/movierequests.component.ts index fa4b0a48d..ff181540a 100644 --- a/src/Ombi/ClientApp/app/requests/movierequests.component.ts +++ b/src/Ombi/ClientApp/app/requests/movierequests.component.ts @@ -219,7 +219,7 @@ export class MovieRequestsComponent implements OnInit { public unSubscribe(request: IMovieRequests) { request.subscribed = false; - this.requestService.subscribeToMovie(request.id) + this.requestService.unSubscribeToMovie(request.id) .subscribe(x => { this.notificationService.success("Unsubscribed Movie!"); }); diff --git a/src/Ombi/ClientApp/app/requests/tvrequest-children.component.html b/src/Ombi/ClientApp/app/requests/tvrequest-children.component.html index 736878d4b..12b093bca 100644 --- a/src/Ombi/ClientApp/app/requests/tvrequest-children.component.html +++ b/src/Ombi/ClientApp/app/requests/tvrequest-children.component.html @@ -11,8 +11,11 @@ {{child.requestedUser.userName}}
-
+ + + +
diff --git a/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts b/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts index e9da2342f..4a10dc937 100644 --- a/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts +++ b/src/Ombi/ClientApp/app/requests/tvrequest-children.component.ts @@ -94,6 +94,22 @@ export class TvRequestChildrenComponent { }); } + public subscribe(request: IChildRequests) { + request.subscribed = true; + this.requestService.subscribeToTv(request.id) + .subscribe(x => { + this.notificationService.success("Subscribed To TV Show!"); + }); + } + + public unSubscribe(request: IChildRequests) { + request.subscribed = false; + this.requestService.unSubscribeToTv(request.id) + .subscribe(x => { + this.notificationService.success("Unsubscribed TV Show!"); + }); + } + private removeRequestFromUi(key: IChildRequests) { const index = this.childRequests.indexOf(key, 0); if (index > -1) {