mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 08:16:05 -07:00
Added the subscription for movies !wip
This commit is contained in:
parent
bebf2f2ab8
commit
7a9fc1213f
31 changed files with 1308 additions and 42 deletions
|
@ -9,13 +9,12 @@ using System.Threading.Tasks;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
using Ombi.Store.Repository;
|
||||
using Ombi.Store.Repository.Requests;
|
||||
using Ombi.Store.Entities;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Settings;
|
||||
using Ombi.Settings.Settings.Models;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Repository;
|
||||
|
||||
namespace Ombi.Core.Engine
|
||||
{
|
||||
|
@ -26,11 +25,12 @@ namespace Ombi.Core.Engine
|
|||
private Dictionary<int, TvRequests> _dbTv;
|
||||
|
||||
protected BaseMediaEngine(IPrincipal identity, IRequestServiceMain requestService,
|
||||
IRuleEvaluator rules, OmbiUserManager um, ICacheService cache, ISettingsService<OmbiSettings> ombiSettings) : base(identity, um, rules)
|
||||
IRuleEvaluator rules, OmbiUserManager um, ICacheService cache, ISettingsService<OmbiSettings> ombiSettings, IRepository<RequestSubscription> sub) : base(identity, um, rules)
|
||||
{
|
||||
RequestService = requestService;
|
||||
Cache = cache;
|
||||
OmbiSettings = ombiSettings;
|
||||
_subscriptionRepository = sub;
|
||||
}
|
||||
|
||||
protected IRequestServiceMain RequestService { get; }
|
||||
|
@ -38,6 +38,7 @@ namespace Ombi.Core.Engine
|
|||
protected ITvRequestRepository TvRepository => RequestService.TvRequestService;
|
||||
protected readonly ICacheService Cache;
|
||||
protected readonly ISettingsService<OmbiSettings> OmbiSettings;
|
||||
protected readonly IRepository<RequestSubscription> _subscriptionRepository;
|
||||
|
||||
protected async Task<Dictionary<int, MovieRequests>> GetMovieRequests()
|
||||
{
|
||||
|
@ -108,9 +109,13 @@ namespace Ombi.Core.Engine
|
|||
|
||||
protected async Task<HideResult> HideFromOtherUsers()
|
||||
{
|
||||
var user = await GetUser();
|
||||
if (await IsInRole(OmbiRoles.Admin) || await IsInRole(OmbiRoles.PowerUser))
|
||||
{
|
||||
return new HideResult();
|
||||
return new HideResult
|
||||
{
|
||||
UserId = user.Id
|
||||
};
|
||||
}
|
||||
var settings = await Cache.GetOrAdd(CacheKeys.OmbiSettings, async () => await OmbiSettings.GetSettingsAsync());
|
||||
var result = new HideResult
|
||||
|
@ -119,12 +124,41 @@ namespace Ombi.Core.Engine
|
|||
};
|
||||
if (settings.HideRequestsUsers)
|
||||
{
|
||||
var user = await GetUser();
|
||||
result.UserId = user.Id;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task SubscribeToRequest(int requestId, RequestType type)
|
||||
{
|
||||
var user = await GetUser();
|
||||
var existingSub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(x =>
|
||||
x.UserId.Equals(user.Id) && x.RequestId == requestId && x.RequestType == type);
|
||||
if (existingSub != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var sub = new RequestSubscription
|
||||
{
|
||||
UserId = user.Id,
|
||||
RequestId = requestId,
|
||||
RequestType = type
|
||||
};
|
||||
|
||||
await _subscriptionRepository.Add(sub);
|
||||
}
|
||||
|
||||
public async Task UnSubscribeRequest(int requestId, RequestType type)
|
||||
{
|
||||
var user = await GetUser();
|
||||
var existingSub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(x =>
|
||||
x.UserId.Equals(user.Id) && x.RequestId == requestId && x.RequestType == type);
|
||||
if (existingSub != null)
|
||||
{
|
||||
await _subscriptionRepository.Delete(existingSub);
|
||||
}
|
||||
}
|
||||
|
||||
public class HideResult
|
||||
{
|
||||
public bool Hide { get; set; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue