Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subscribe button for movies #4585

Merged
merged 8 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/Ombi.Core/Engine/MovieRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public async Task<RequestsViewModel<MovieRequests>> GetRequests(int count, int p
var requests = await (OrderMovies(allRequests, orderFilter.OrderType)).Skip(position).Take(count)
.ToListAsync();

await CheckForSubscription(shouldHide, requests);
await CheckForSubscription(shouldHide.UserId, requests);
return new RequestsViewModel<MovieRequests>
{
Collection = requests,
Expand Down Expand Up @@ -295,7 +295,7 @@ public async Task<RequestsViewModel<MovieRequests>> GetRequests(int count, int p
var total = requests.Count();
requests = requests.Skip(position).Take(count).ToList();

await CheckForSubscription(shouldHide, requests);
await CheckForSubscription(shouldHide.UserId, requests);
return new RequestsViewModel<MovieRequests>
{
Collection = requests,
Expand Down Expand Up @@ -380,7 +380,7 @@ public async Task<RequestsViewModel<MovieRequests>> GetRequestsByStatus(int coun
// TODO fix this so we execute this on the server
requests = requests.Skip(position).Take(count).ToList();

await CheckForSubscription(shouldHide, requests);
await CheckForSubscription(shouldHide.UserId, requests);
return new RequestsViewModel<MovieRequests>
{
Collection = requests,
Expand Down Expand Up @@ -423,7 +423,7 @@ public async Task<RequestsViewModel<MovieRequests>> GetUnavailableRequests(int c
var total = requests.Count();
requests = requests.Skip(position).Take(count).ToList();

await CheckForSubscription(shouldHide, requests);
await CheckForSubscription(shouldHide.UserId, requests);
return new RequestsViewModel<MovieRequests>
{
Collection = requests,
Expand Down Expand Up @@ -505,29 +505,29 @@ public async Task<IEnumerable<MovieRequests>> GetRequests()
allRequests = await MovieRepository.GetWithUser().ToListAsync();
}

await CheckForSubscription(shouldHide, allRequests);
await CheckForSubscription(shouldHide.UserId, allRequests);

return allRequests;
}

public async Task<MovieRequests> GetRequest(int requestId)
{
var request = await MovieRepository.GetWithUser().Where(x => x.Id == requestId).FirstOrDefaultAsync();
await CheckForSubscription(new HideResult(), new List<MovieRequests> { request });
await CheckForSubscription((await GetUser()).Id, new List<MovieRequests> { request });

return request;
}

private async Task CheckForSubscription(HideResult shouldHide, List<MovieRequests> movieRequests)
private async Task CheckForSubscription(string UserId, List<MovieRequests> movieRequests)
{
var requestIds = movieRequests.Select(x => x.Id);
var sub = await _subscriptionRepository.GetAll().Where(s =>
s.UserId == shouldHide.UserId && requestIds.Contains(s.RequestId) && s.RequestType == RequestType.Movie)
s.UserId == UserId && requestIds.Contains(s.RequestId) && s.RequestType == RequestType.Movie)
.ToListAsync();
foreach (var x in movieRequests)
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
if (shouldHide.UserId == x.RequestedUserId)
if (UserId == x.RequestedUserId)
{
x.ShowSubscribe = false;
}
Expand Down Expand Up @@ -559,7 +559,7 @@ public async Task<IEnumerable<MovieRequests>> SearchMovieRequest(string search)
}

var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList();
await CheckForSubscription(shouldHide, results);
await CheckForSubscription(shouldHide.UserId, results);

return results;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Ombi.Core/Models/Search/SearchViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations.Schema;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using Ombi.Store.Entities;

namespace Ombi.Core.Models.Search
Expand Down Expand Up @@ -32,6 +33,7 @@ public abstract class SearchViewModel
public string TheMovieDbId { get; set; }

[NotMapped]
[Obsolete("Use request service instead")]
public bool Subscribed { get; set; }
[NotMapped]
public bool ShowSubscribe { get; set; }
Expand Down
Loading