support recursive played filter
This commit is contained in:
parent
98b6046f04
commit
d0a5197c0a
|
@ -137,24 +137,14 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
{
|
{
|
||||||
var libraryItems = user.RootFolder.GetRecursiveChildren(user).ToList();
|
var libraryItems = user.RootFolder.GetRecursiveChildren(user).ToList();
|
||||||
|
|
||||||
items = items.Where(i => GetLibraryItems(i, libraryItems).All(l =>
|
items = items.Where(i => GetLibraryItems(i, libraryItems).All(l => l.IsPlayed(user)));
|
||||||
{
|
|
||||||
var userdata = UserDataRepository.GetUserData(user.Id, l.GetUserDataKey());
|
|
||||||
|
|
||||||
return userdata != null && userdata.Played;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filters.Contains(ItemFilter.IsUnplayed))
|
if (filters.Contains(ItemFilter.IsUnplayed))
|
||||||
{
|
{
|
||||||
var libraryItems = user.RootFolder.GetRecursiveChildren(user).ToList();
|
var libraryItems = user.RootFolder.GetRecursiveChildren(user).ToList();
|
||||||
|
|
||||||
items = items.Where(i => GetLibraryItems(i, libraryItems).All(l =>
|
items = items.Where(i => GetLibraryItems(i, libraryItems).All(l => !l.IsPlayed(user)));
|
||||||
{
|
|
||||||
var userdata = UserDataRepository.GetUserData(user.Id, l.GetUserDataKey());
|
|
||||||
|
|
||||||
return userdata == null || !userdata.Played;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
|
|
|
@ -386,6 +386,9 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
/// <returns>IEnumerable{BaseItem}.</returns>
|
/// <returns>IEnumerable{BaseItem}.</returns>
|
||||||
internal static IEnumerable<BaseItem> ApplyFilter(IEnumerable<BaseItem> items, ItemFilter filter, User user, IUserDataManager repository)
|
internal static IEnumerable<BaseItem> ApplyFilter(IEnumerable<BaseItem> items, ItemFilter filter, User user, IUserDataManager repository)
|
||||||
{
|
{
|
||||||
|
// Avoid implicitly captured closure
|
||||||
|
var currentUser = user;
|
||||||
|
|
||||||
switch (filter)
|
switch (filter)
|
||||||
{
|
{
|
||||||
case ItemFilter.IsFavoriteOrLikes:
|
case ItemFilter.IsFavoriteOrLikes:
|
||||||
|
@ -440,20 +443,10 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
});
|
});
|
||||||
|
|
||||||
case ItemFilter.IsPlayed:
|
case ItemFilter.IsPlayed:
|
||||||
return items.Where(item =>
|
return items.Where(item => item.IsPlayed(currentUser));
|
||||||
{
|
|
||||||
var userdata = repository.GetUserData(user.Id, item.GetUserDataKey());
|
|
||||||
|
|
||||||
return userdata != null && userdata.Played;
|
|
||||||
});
|
|
||||||
|
|
||||||
case ItemFilter.IsUnplayed:
|
case ItemFilter.IsUnplayed:
|
||||||
return items.Where(item =>
|
return items.Where(item => !item.IsPlayed(currentUser));
|
||||||
{
|
|
||||||
var userdata = repository.GetUserData(user.Id, item.GetUserDataKey());
|
|
||||||
|
|
||||||
return userdata == null || !userdata.Played;
|
|
||||||
});
|
|
||||||
|
|
||||||
case ItemFilter.IsFolder:
|
case ItemFilter.IsFolder:
|
||||||
return items.Where(item => item.IsFolder);
|
return items.Where(item => item.IsFolder);
|
||||||
|
|
|
@ -167,6 +167,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
public static ILocalizationManager LocalizationManager { get; set; }
|
public static ILocalizationManager LocalizationManager { get; set; }
|
||||||
public static IItemRepository ItemRepository { get; set; }
|
public static IItemRepository ItemRepository { get; set; }
|
||||||
public static IFileSystem FileSystem { get; set; }
|
public static IFileSystem FileSystem { get; set; }
|
||||||
|
public static IUserDataManager UserDataManager { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="System.String" /> that represents this instance.
|
/// Returns a <see cref="System.String" /> that represents this instance.
|
||||||
|
@ -1705,5 +1706,12 @@ namespace MediaBrowser.Controller.Entities
|
||||||
// Directory watchers should repeat this, but do a quick refresh first
|
// Directory watchers should repeat this, but do a quick refresh first
|
||||||
return RefreshMetadata(CancellationToken.None, forceSave: true, allowSlowProviders: false);
|
return RefreshMetadata(CancellationToken.None, forceSave: true, allowSlowProviders: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool IsPlayed(User user)
|
||||||
|
{
|
||||||
|
var userdata = UserDataManager.GetUserData(user.Id, GetUserDataKey());
|
||||||
|
|
||||||
|
return userdata != null && userdata.Played;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1084,5 +1084,10 @@ namespace MediaBrowser.Controller.Entities
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsPlayed(User user)
|
||||||
|
{
|
||||||
|
return GetRecursiveChildren(user).Where(i => !i.IsFolder).All(i => i.IsPlayed(user));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,14 +32,7 @@ namespace MediaBrowser.Server.Implementations.Sorting
|
||||||
/// <returns>DateTime.</returns>
|
/// <returns>DateTime.</returns>
|
||||||
private int GetValue(BaseItem x)
|
private int GetValue(BaseItem x)
|
||||||
{
|
{
|
||||||
var userdata = UserDataRepository.GetUserData(User.Id, x.GetUserDataKey());
|
return x.IsPlayed(User) ? 1 : 0;
|
||||||
|
|
||||||
if (userdata == null)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return userdata.Played ? 1 : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -90,14 +83,7 @@ namespace MediaBrowser.Server.Implementations.Sorting
|
||||||
/// <returns>DateTime.</returns>
|
/// <returns>DateTime.</returns>
|
||||||
private int GetValue(BaseItem x)
|
private int GetValue(BaseItem x)
|
||||||
{
|
{
|
||||||
var userdata = UserDataRepository.GetUserData(User.Id, x.GetUserDataKey());
|
return x.IsPlayed(User) ? 0 : 1;
|
||||||
|
|
||||||
if (userdata == null)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return userdata.Played ? 0 : 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user