mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 17:14:42 +01:00
added new parent methods
This commit is contained in:
@@ -30,7 +30,7 @@ namespace MediaBrowser.Controller.Entities.Audio
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parents.OfType<MusicArtist>().FirstOrDefault();
|
||||
return GetParents().OfType<MusicArtist>().FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace MediaBrowser.Controller.Entities.Audio
|
||||
|
||||
id.AlbumArtists = AlbumArtists;
|
||||
|
||||
var artist = Parents.OfType<MusicArtist>().FirstOrDefault();
|
||||
var artist = GetParents().OfType<MusicArtist>().FirstOrDefault();
|
||||
|
||||
if (artist != null)
|
||||
{
|
||||
|
||||
@@ -214,11 +214,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsHiddenFromUser(User user)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public virtual bool IsOwnedItem
|
||||
{
|
||||
@@ -519,15 +514,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
[IgnoreDataMember]
|
||||
public Folder Parent
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ParentId != Guid.Empty)
|
||||
{
|
||||
return LibraryManager.GetItemById(ParentId) as Folder;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
get { return GetParent() as Folder; }
|
||||
set
|
||||
{
|
||||
|
||||
@@ -542,16 +529,28 @@ namespace MediaBrowser.Controller.Entities
|
||||
[IgnoreDataMember]
|
||||
public IEnumerable<Folder> Parents
|
||||
{
|
||||
get
|
||||
get { return GetParents().OfType<Folder>(); }
|
||||
}
|
||||
|
||||
public BaseItem GetParent()
|
||||
{
|
||||
if (ParentId != Guid.Empty)
|
||||
{
|
||||
var parent = Parent;
|
||||
return LibraryManager.GetItemById(ParentId);
|
||||
}
|
||||
|
||||
while (parent != null)
|
||||
{
|
||||
yield return parent;
|
||||
return null;
|
||||
}
|
||||
|
||||
parent = parent.Parent;
|
||||
}
|
||||
public IEnumerable<BaseItem> GetParents()
|
||||
{
|
||||
var parent = GetParent();
|
||||
|
||||
while (parent != null)
|
||||
{
|
||||
yield return parent;
|
||||
|
||||
parent = parent.GetParent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -563,13 +562,13 @@ namespace MediaBrowser.Controller.Entities
|
||||
public T FindParent<T>()
|
||||
where T : Folder
|
||||
{
|
||||
return Parents.OfType<T>().FirstOrDefault();
|
||||
return GetParents().OfType<T>().FirstOrDefault();
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public virtual BaseItem DisplayParent
|
||||
{
|
||||
get { return Parent; }
|
||||
get { return GetParent(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -869,7 +868,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
[IgnoreDataMember]
|
||||
protected virtual bool SupportsOwnedItems
|
||||
{
|
||||
get { return IsFolder || Parent != null; }
|
||||
get { return IsFolder || GetParent() != null; }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
@@ -894,7 +893,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
var localTrailersChanged = false;
|
||||
|
||||
if (LocationType == LocationType.FileSystem && Parent != null)
|
||||
if (LocationType == LocationType.FileSystem && GetParent() != null)
|
||||
{
|
||||
var hasThemeMedia = this as IHasThemeMedia;
|
||||
if (hasThemeMedia != null)
|
||||
@@ -1056,7 +1055,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
if (string.IsNullOrWhiteSpace(lang))
|
||||
{
|
||||
lang = Parents
|
||||
lang = GetParents()
|
||||
.Select(i => i.PreferredMetadataLanguage)
|
||||
.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
|
||||
}
|
||||
@@ -1086,7 +1085,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
if (string.IsNullOrWhiteSpace(lang))
|
||||
{
|
||||
lang = Parents
|
||||
lang = GetParents()
|
||||
.Select(i => i.PreferredMetadataCountryCode)
|
||||
.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
|
||||
}
|
||||
@@ -1276,14 +1275,14 @@ namespace MediaBrowser.Controller.Entities
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Parents.Any(i => !i.IsVisible(user)))
|
||||
if (GetParents().Any(i => !i.IsVisible(user)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (checkFolders)
|
||||
{
|
||||
var topParent = Parents.LastOrDefault() ?? this;
|
||||
var topParent = GetParents().LastOrDefault() ?? this;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(topParent.Path))
|
||||
{
|
||||
@@ -1937,7 +1936,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
public virtual IEnumerable<Guid> GetAncestorIds()
|
||||
{
|
||||
return Parents.Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id));
|
||||
return GetParents().Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id));
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
if (string.IsNullOrEmpty(SeriesName))
|
||||
{
|
||||
info.SeriesName = Parents.Select(i => i.Name).FirstOrDefault();
|
||||
info.SeriesName = GetParents().Select(i => i.Name).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -825,19 +825,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
return UserViewBuilder.PostFilterAndSort(items, this, null, query, LibraryManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets allowed children of an item
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="includeLinkedChildren">if set to <c>true</c> [include linked children].</param>
|
||||
/// <returns>IEnumerable{BaseItem}.</returns>
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
public virtual IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
|
||||
{
|
||||
return GetChildren(user, includeLinkedChildren, false);
|
||||
}
|
||||
|
||||
internal IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren, bool includeHidden)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
@@ -849,7 +837,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
var result = new Dictionary<Guid, BaseItem>();
|
||||
|
||||
AddChildren(user, includeLinkedChildren, result, includeHidden, false, null);
|
||||
AddChildren(user, includeLinkedChildren, result, false, null);
|
||||
|
||||
return result.Values;
|
||||
}
|
||||
@@ -865,29 +853,25 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="includeLinkedChildren">if set to <c>true</c> [include linked children].</param>
|
||||
/// <param name="result">The result.</param>
|
||||
/// <param name="includeHidden">if set to <c>true</c> [include hidden].</param>
|
||||
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
||||
/// <param name="filter">The filter.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
private void AddChildren(User user, bool includeLinkedChildren, Dictionary<Guid, BaseItem> result, bool includeHidden, bool recursive, Func<BaseItem, bool> filter)
|
||||
private void AddChildren(User user, bool includeLinkedChildren, Dictionary<Guid, BaseItem> result, bool recursive, Func<BaseItem, bool> filter)
|
||||
{
|
||||
foreach (var child in GetEligibleChildrenForRecursiveChildren(user))
|
||||
{
|
||||
if (child.IsVisible(user))
|
||||
{
|
||||
if (includeHidden || !child.IsHiddenFromUser(user))
|
||||
if (filter == null || filter(child))
|
||||
{
|
||||
if (filter == null || filter(child))
|
||||
{
|
||||
result[child.Id] = child;
|
||||
}
|
||||
result[child.Id] = child;
|
||||
}
|
||||
|
||||
if (recursive && child.IsFolder)
|
||||
{
|
||||
var folder = (Folder)child;
|
||||
|
||||
folder.AddChildren(user, includeLinkedChildren, result, includeHidden, true, filter);
|
||||
folder.AddChildren(user, includeLinkedChildren, result, true, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -928,7 +912,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
var result = new Dictionary<Guid, BaseItem>();
|
||||
|
||||
AddChildren(user, true, result, false, true, filter);
|
||||
AddChildren(user, true, result, true, filter);
|
||||
|
||||
return result.Values;
|
||||
}
|
||||
|
||||
18
MediaBrowser.Controller/Entities/IHiddenFromDisplay.cs
Normal file
18
MediaBrowser.Controller/Entities/IHiddenFromDisplay.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
public interface IHiddenFromDisplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the specified user is hidden.
|
||||
/// </summary>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <returns><c>true</c> if the specified user is hidden; otherwise, <c>false</c>.</returns>
|
||||
bool IsHiddenFromUser(User user);
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ namespace MediaBrowser.Controller.Entities.Movies
|
||||
|
||||
// Must have a parent to have special features
|
||||
// In other words, it must be part of the Parent/Child tree
|
||||
if (LocationType == LocationType.FileSystem && Parent != null && !IsInMixedFolder)
|
||||
if (LocationType == LocationType.FileSystem && GetParent() != null && !IsInMixedFolder)
|
||||
{
|
||||
var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parents.OfType<PhotoAlbum>().FirstOrDefault();
|
||||
return GetParents().OfType<PhotoAlbum>().FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
{
|
||||
get
|
||||
{
|
||||
return Season ?? Parent;
|
||||
return Season ?? GetParent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
[IgnoreDataMember]
|
||||
public override BaseItem DisplayParent
|
||||
{
|
||||
get { return Series ?? Parent; }
|
||||
get { return Series ?? GetParent(); }
|
||||
}
|
||||
|
||||
// Genre, Rating and Stuido will all be the same
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
get
|
||||
{
|
||||
// Local trailers are not part of children
|
||||
return Parent == null;
|
||||
return GetParent() == null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
list.Add(ParentId);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(Id);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -125,10 +129,14 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
var standaloneTypes = new List<string>
|
||||
{
|
||||
CollectionType.Playlists,
|
||||
CollectionType.BoxSets
|
||||
CollectionType.Playlists
|
||||
};
|
||||
|
||||
if (!ConfigurationManager.Configuration.EnableSharedCollectionViewImage)
|
||||
{
|
||||
standaloneTypes.Add(CollectionType.BoxSets);
|
||||
}
|
||||
|
||||
var collectionFolder = folder as ICollectionFolder;
|
||||
|
||||
if (collectionFolder == null)
|
||||
|
||||
@@ -1073,7 +1073,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
if (query.IsInBoxSet.HasValue)
|
||||
{
|
||||
var val = query.IsInBoxSet.Value;
|
||||
if (item.Parents.OfType<BoxSet>().Any() != val)
|
||||
if (item.GetParents().OfType<BoxSet>().Any() != val)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -1511,7 +1511,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
.Where(i => !UserView.IsExcludedFromGrouping(i));
|
||||
}
|
||||
return user.RootFolder
|
||||
.GetChildren(user, true, true)
|
||||
.GetChildren(user, true)
|
||||
.OfType<Folder>()
|
||||
.Where(i => user.IsFolderGrouped(i.Id) && !UserView.IsExcludedFromGrouping(i));
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
// Must have a parent to have additional parts or alternate versions
|
||||
// In other words, it must be part of the Parent/Child tree
|
||||
// The additional parts won't have additional parts themselves
|
||||
if (LocationType == LocationType.FileSystem && Parent != null)
|
||||
if (LocationType == LocationType.FileSystem && GetParent() != null)
|
||||
{
|
||||
if (!IsStacked)
|
||||
{
|
||||
|
||||
@@ -548,10 +548,9 @@ namespace MediaBrowser.Controller.Library
|
||||
/// Gets the items.
|
||||
/// </summary>
|
||||
/// <param name="query">The query.</param>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <param name="parentIds">The parent ids.</param>
|
||||
/// <returns>List<BaseItem>.</returns>
|
||||
IEnumerable<BaseItem> GetItems(InternalItemsQuery query, User user, IEnumerable<string> parentIds);
|
||||
IEnumerable<BaseItem> GetItems(InternalItemsQuery query, IEnumerable<string> parentIds);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the items result.
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace MediaBrowser.Controller.Library
|
||||
// Not officially supported but in some cases we can handle it.
|
||||
if (item == null)
|
||||
{
|
||||
item = parent.Parents.OfType<T>().FirstOrDefault();
|
||||
item = parent.GetParents().OfType<T>().FirstOrDefault();
|
||||
}
|
||||
|
||||
return item != null;
|
||||
|
||||
@@ -162,6 +162,7 @@
|
||||
<Compile Include="Entities\IHasThemeMedia.cs" />
|
||||
<Compile Include="Entities\IHasTrailers.cs" />
|
||||
<Compile Include="Entities\IHasUserData.cs" />
|
||||
<Compile Include="Entities\IHiddenFromDisplay.cs" />
|
||||
<Compile Include="Entities\IItemByName.cs" />
|
||||
<Compile Include="Entities\ILibraryItem.cs" />
|
||||
<Compile Include="Entities\ImageSourceInfo.cs" />
|
||||
|
||||
Reference in New Issue
Block a user