This commit is contained in:
Jamie Rees 2019-11-26 08:32:16 +00:00
commit bea8551cd3
60 changed files with 12547 additions and 482 deletions

View file

@ -189,11 +189,7 @@ namespace Ombi.Core.Engine
var requests = await (OrderMovies(allRequests, orderFilter.OrderType)).Skip(position).Take(count)
.ToListAsync();
requests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
await CheckForSubscription(shouldHide, x);
});
await CheckForSubscription(shouldHide, requests);
return new RequestsViewModel<MovieRequests>
{
Collection = requests,
@ -236,11 +232,8 @@ namespace Ombi.Core.Engine
var total = await allRequests.CountAsync();
var requests = await allRequests.Skip(position).Take(count)
.ToListAsync();
requests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
await CheckForSubscription(shouldHide, x);
});
await CheckForSubscription(shouldHide, requests);
return new RequestsViewModel<MovieRequests>
{
Collection = requests,
@ -282,11 +275,8 @@ namespace Ombi.Core.Engine
var total = await allRequests.CountAsync();
var requests = await allRequests.Skip(position).Take(count)
.ToListAsync();
requests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
await CheckForSubscription(shouldHide, x);
});
await CheckForSubscription(shouldHide, requests);
return new RequestsViewModel<MovieRequests>
{
Collection = requests,
@ -369,35 +359,38 @@ namespace Ombi.Core.Engine
allRequests = await MovieRepository.GetWithUser().ToListAsync();
}
allRequests.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
await CheckForSubscription(shouldHide, x);
});
await CheckForSubscription(shouldHide, allRequests);
return allRequests;
}
public async Task<MovieRequests> GetRequest(int requestId)
{
var request = await MovieRepository.GetWithUser().Where(x => x.Id == requestId).FirstOrDefaultAsync();
request.PosterPath = PosterPathHelper.FixPosterPath(request.PosterPath);
await CheckForSubscription(new HideResult(), request);
await CheckForSubscription(new HideResult(), new List<MovieRequests>{request });
return request;
}
private async Task CheckForSubscription(HideResult shouldHide, MovieRequests x)
private async Task CheckForSubscription(HideResult shouldHide, List<MovieRequests> movieRequests)
{
if (shouldHide.UserId == x.RequestedUserId)
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)
.ToListAsync();
foreach (var x in movieRequests)
{
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;
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
if (shouldHide.UserId == x.RequestedUserId)
{
x.ShowSubscribe = false;
}
else
{
x.ShowSubscribe = true;
var hasSub = sub.FirstOrDefault(r => r.RequestId == x.Id);
x.Subscribed = hasSub != null;
}
}
}
@ -420,11 +413,8 @@ namespace Ombi.Core.Engine
}
var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList();
results.ForEach(async x =>
{
x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
await CheckForSubscription(shouldHide, x);
});
await CheckForSubscription(shouldHide, results);
return results;
}
@ -448,7 +438,7 @@ namespace Ombi.Core.Engine
request.Denied = true;
request.DeniedReason = denyReason;
// We are denying a request
NotificationHelper.Notify(request, NotificationType.RequestDeclined);
await NotificationHelper.Notify(request, NotificationType.RequestDeclined);
await MovieRepository.Update(request);
return new RequestEngineResult
@ -476,7 +466,7 @@ namespace Ombi.Core.Engine
var canNotify = await RunSpecificRule(request, SpecificRules.CanSendNotification);
if (canNotify.Success)
{
NotificationHelper.Notify(request, NotificationType.RequestApproved);
await NotificationHelper.Notify(request, NotificationType.RequestApproved);
}
if (request.Approved)
@ -592,7 +582,7 @@ namespace Ombi.Core.Engine
request.Available = true;
request.MarkedAsAvailable = DateTime.Now;
NotificationHelper.Notify(request, NotificationType.RequestAvailable);
await NotificationHelper.Notify(request, NotificationType.RequestAvailable);
await MovieRepository.Update(request);
return new RequestEngineResult
@ -608,8 +598,8 @@ namespace Ombi.Core.Engine
var result = await RunSpecificRule(model, SpecificRules.CanSendNotification);
if (result.Success)
{
NotificationHelper.NewRequest(model);
{
await NotificationHelper.NewRequest(model);
}
await _requestLog.Add(new RequestLog