jellyfin/MediaBrowser.Controller/Entities/UserView.cs

179 lines
5.6 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
using System;
2018-12-27 16:27:57 -07:00
using System.Collections.Generic;
using System.Linq;
2019-10-15 08:49:49 -07:00
using System.Text.Json.Serialization;
2018-12-27 16:27:57 -07:00
using System.Threading.Tasks;
2020-05-20 10:07:53 -07:00
using Jellyfin.Data.Entities;
using MediaBrowser.Controller.TV;
using MediaBrowser.Model.Querying;
2018-12-27 16:27:57 -07:00
namespace MediaBrowser.Controller.Entities
{
public class UserView : Folder, IHasCollectionType
{
/// <inheritdoc />
2018-12-27 16:27:57 -07:00
public string ViewType { get; set; }
/// <inheritdoc />
2018-12-27 14:43:48 -07:00
public new Guid DisplayParentId { get; set; }
2018-12-27 16:27:57 -07:00
/// <inheritdoc />
2018-12-27 16:27:57 -07:00
public Guid? UserId { get; set; }
public static ITVSeriesManager TVSeriesManager;
/// <inheritdoc />
2019-10-15 08:49:49 -07:00
[JsonIgnore]
public string CollectionType => ViewType;
2018-12-27 16:27:57 -07:00
/// <inheritdoc />
2018-12-27 16:27:57 -07:00
public override IEnumerable<Guid> GetIdsForAncestorQuery()
{
if (!DisplayParentId.Equals(Guid.Empty))
{
yield return DisplayParentId;
2018-12-27 16:27:57 -07:00
}
else if (!ParentId.Equals(Guid.Empty))
{
yield return ParentId;
2018-12-27 16:27:57 -07:00
}
else
{
yield return Id;
2018-12-27 16:27:57 -07:00
}
}
2019-10-15 08:49:49 -07:00
[JsonIgnore]
public override bool SupportsInheritedParentImages => false;
2018-12-27 16:27:57 -07:00
2019-10-15 08:49:49 -07:00
[JsonIgnore]
public override bool SupportsPlayedStatus => false;
2018-12-27 16:27:57 -07:00
2020-05-20 10:07:53 -07:00
public override int GetChildCount(User user)
2018-12-27 16:27:57 -07:00
{
return GetChildren(user, true).Count;
}
protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query)
{
var parent = this as Folder;
if (!DisplayParentId.Equals(Guid.Empty))
{
parent = LibraryManager.GetItemById(DisplayParentId) as Folder ?? parent;
}
else if (!ParentId.Equals(Guid.Empty))
{
parent = LibraryManager.GetItemById(ParentId) as Folder ?? parent;
}
return new UserViewBuilder(UserViewManager, LibraryManager, Logger, UserDataManager, TVSeriesManager, ConfigurationManager)
2018-12-27 16:27:57 -07:00
.GetUserItems(parent, this, CollectionType, query);
}
2020-05-20 10:07:53 -07:00
public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
2018-12-27 16:27:57 -07:00
{
if (query == null)
{
query = new InternalItemsQuery(user);
}
query.EnableTotalRecordCount = false;
var result = GetItemList(query);
return result.ToList();
}
public override bool CanDelete()
{
return false;
}
public override bool IsSaveLocalMetadataEnabled()
{
return true;
}
2020-05-20 10:07:53 -07:00
public override IEnumerable<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
2018-12-27 16:27:57 -07:00
{
query.SetUser(user);
query.Recursive = true;
query.EnableTotalRecordCount = false;
query.ForceDirect = true;
return GetItemList(query);
}
2020-05-20 10:07:53 -07:00
protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
2018-12-27 16:27:57 -07:00
{
return GetChildren(user, false);
}
private static string[] UserSpecificViewTypes = new string[]
{
2020-05-20 10:07:53 -07:00
Model.Entities.CollectionType.Playlists
2018-12-27 16:27:57 -07:00
};
public static bool IsUserSpecific(Folder folder)
{
var collectionFolder = folder as ICollectionFolder;
if (collectionFolder == null)
{
return false;
}
var supportsUserSpecific = folder as ISupportsUserSpecificView;
if (supportsUserSpecific != null && supportsUserSpecific.EnableUserSpecificView)
{
return true;
}
return UserSpecificViewTypes.Contains(collectionFolder.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
}
public static bool IsEligibleForGrouping(Folder folder)
{
2018-12-27 14:43:48 -07:00
return folder is ICollectionFolder collectionFolder
&& IsEligibleForGrouping(collectionFolder.CollectionType);
2018-12-27 16:27:57 -07:00
}
private static string[] ViewTypesEligibleForGrouping = new string[]
{
2020-05-20 10:07:53 -07:00
Model.Entities.CollectionType.Movies,
Model.Entities.CollectionType.TvShows,
2018-12-27 16:27:57 -07:00
string.Empty
};
public static bool IsEligibleForGrouping(string viewType)
{
return ViewTypesEligibleForGrouping.Contains(viewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
}
private static string[] OriginalFolderViewTypes = new string[]
{
2020-05-20 10:07:53 -07:00
Model.Entities.CollectionType.Books,
Model.Entities.CollectionType.MusicVideos,
Model.Entities.CollectionType.HomeVideos,
Model.Entities.CollectionType.Photos,
Model.Entities.CollectionType.Music,
Model.Entities.CollectionType.BoxSets
2018-12-27 16:27:57 -07:00
};
public static bool EnableOriginalFolder(string viewType)
{
return OriginalFolderViewTypes.Contains(viewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
}
protected override Task ValidateChildrenInternal(IProgress<double> progress, System.Threading.CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, Providers.MetadataRefreshOptions refreshOptions, Providers.IDirectoryService directoryService)
{
2018-12-27 14:43:48 -07:00
return Task.CompletedTask;
2018-12-27 16:27:57 -07:00
}
2019-10-15 08:49:49 -07:00
[JsonIgnore]
public override bool SupportsPeople => false;
2018-12-27 16:27:57 -07:00
}
}