jellyfin-server/MediaBrowser.Controller/Entities/UserView.cs

188 lines
5.8 KiB
C#
Raw Normal View History

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