jellyfin/MediaBrowser.Controller/Entities/UserView.cs

191 lines
5.7 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;
using System.Threading;
2018-12-27 23:27:57 +00:00
using System.Threading.Tasks;
2020-05-20 17:07:53 +00:00
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
2021-12-20 12:31:07 +00:00
using Jellyfin.Extensions;
using MediaBrowser.Controller.Providers;
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
{
private static readonly CollectionType?[] _viewTypesEligibleForGrouping =
2021-07-11 20:32:06 +00:00
{
Jellyfin.Data.Enums.CollectionType.movies,
Jellyfin.Data.Enums.CollectionType.tvshows,
null
2021-07-11 20:32:06 +00:00
};
private static readonly CollectionType?[] _originalFolderViewTypes =
2021-07-11 20:32:06 +00:00
{
Jellyfin.Data.Enums.CollectionType.books,
Jellyfin.Data.Enums.CollectionType.musicvideos,
Jellyfin.Data.Enums.CollectionType.homevideos,
Jellyfin.Data.Enums.CollectionType.photos,
Jellyfin.Data.Enums.CollectionType.music,
Jellyfin.Data.Enums.CollectionType.boxsets
2021-07-11 20:32:06 +00:00
};
public static ITVSeriesManager TVSeriesManager { get; set; }
/// <summary>
/// Gets or sets the view type.
/// </summary>
public CollectionType? 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 CollectionType? 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.IsEmpty())
2018-12-27 23:27:57 +00:00
{
yield return DisplayParentId;
2018-12-27 23:27:57 +00:00
}
else if (!ParentId.IsEmpty())
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.IsEmpty())
2018-12-27 23:27:57 +00:00
{
parent = LibraryManager.GetItemById(DisplayParentId) as Folder ?? parent;
}
else if (!ParentId.IsEmpty())
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;
}
return collectionFolder.CollectionType == Jellyfin.Data.Enums.CollectionType.playlists;
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(CollectionType? viewType)
2018-12-27 23:27:57 +00:00
{
return _viewTypesEligibleForGrouping.Contains(viewType);
2018-12-27 23:27:57 +00:00
}
public static bool EnableOriginalFolder(CollectionType? viewType)
2018-12-27 23:27:57 +00:00
{
return _originalFolderViewTypes.Contains(viewType);
2018-12-27 23:27:57 +00:00
}
protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, 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
}
}
}