|
|
|
@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
|
using ServiceStack.ServiceHost;
|
|
|
|
|
using System;
|
|
|
|
@ -81,7 +82,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
items = request.Recursive ? folder.RecursiveChildren: folder.Children;
|
|
|
|
|
items = request.Recursive ? folder.RecursiveChildren : folder.Children;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -162,18 +163,20 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
if (filters.Contains(ItemFilter.Dislikes))
|
|
|
|
|
{
|
|
|
|
|
items = items.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
|
|
|
|
{
|
|
|
|
|
var item = i.GetItem().Result;
|
|
|
|
|
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
|
|
|
|
|
|
|
|
|
return userdata != null && userdata.Likes.HasValue && !userdata.Likes.Value;
|
|
|
|
|
});
|
|
|
|
|
return userdata != null && userdata.Likes.HasValue && !userdata.Likes.Value;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (filters.Contains(ItemFilter.Likes))
|
|
|
|
|
{
|
|
|
|
|
items = items.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
|
|
|
|
var item = i.GetItem().Result;
|
|
|
|
|
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
|
|
|
|
|
|
|
|
|
return userdata != null && userdata.Likes.HasValue && userdata.Likes.Value;
|
|
|
|
|
});
|
|
|
|
@ -183,12 +186,8 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
{
|
|
|
|
|
items = items.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
|
|
|
|
|
|
|
|
|
if (userdata == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var item = i.GetItem().Result;
|
|
|
|
|
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
|
|
|
|
|
|
|
|
|
var likes = userdata.Likes ?? false;
|
|
|
|
|
var favorite = userdata.IsFavorite;
|
|
|
|
@ -201,7 +200,8 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
{
|
|
|
|
|
items = items.Where(i =>
|
|
|
|
|
{
|
|
|
|
|
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
|
|
|
|
var item = i.GetItem().Result;
|
|
|
|
|
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
|
|
|
|
|
|
|
|
|
return userdata != null && userdata.Likes.HasValue && userdata.IsFavorite;
|
|
|
|
|
});
|
|
|
|
@ -220,7 +220,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
{
|
|
|
|
|
if (string.Equals(request.SortBy, "SortName", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
if (request.SortOrder.HasValue && request.SortOrder.Value == Model.Entities.SortOrder.Descending)
|
|
|
|
|
if (request.SortOrder.HasValue && request.SortOrder.Value == SortOrder.Descending)
|
|
|
|
|
{
|
|
|
|
|
items = items.OrderByDescending(i => i.Name);
|
|
|
|
|
}
|
|
|
|
@ -231,7 +231,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals(request.SortBy, "Random", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
if (request.SortOrder.HasValue && request.SortOrder.Value == Model.Entities.SortOrder.Descending)
|
|
|
|
|
if (request.SortOrder.HasValue && request.SortOrder.Value == SortOrder.Descending)
|
|
|
|
|
{
|
|
|
|
|
items = items.OrderByDescending(i => Guid.NewGuid());
|
|
|
|
|
}
|
|
|
|
@ -361,26 +361,17 @@ namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
public class IbnStub<T>
|
|
|
|
|
where T : BaseItem
|
|
|
|
|
{
|
|
|
|
|
private readonly Func<string,Task<T>> _itemFunction;
|
|
|
|
|
private readonly Func<string, Task<T>> _itemFunction;
|
|
|
|
|
private Task<T> _itemTask;
|
|
|
|
|
|
|
|
|
|
public string Name;
|
|
|
|
|
|
|
|
|
|
private UserItemData _userData;
|
|
|
|
|
|
|
|
|
|
public Task<T> GetItem()
|
|
|
|
|
{
|
|
|
|
|
return _itemTask ?? (_itemTask = _itemFunction(Name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<UserItemData> GetUserItemData(IUserDataRepository repo, Guid userId)
|
|
|
|
|
{
|
|
|
|
|
var item = await GetItem().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return _userData ?? (_userData = repo.GetUserData(userId, item.GetUserDataKey()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IbnStub(string name, Func<string,Task<T>> item)
|
|
|
|
|
public IbnStub(string name, Func<string, Task<T>> item)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
_itemFunction = item;
|
|
|
|
|