#nullable disable
#pragma warning disable CS1591
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Controller.TV;
using MediaBrowser.Model.Querying;
namespace MediaBrowser.Controller.Entities
{
public class UserView : Folder, IHasCollectionType
{
private static readonly CollectionType?[] _viewTypesEligibleForGrouping =
{
Jellyfin.Data.Enums.CollectionType.Movies,
Jellyfin.Data.Enums.CollectionType.TvShows,
null
};
private static readonly CollectionType?[] _originalFolderViewTypes =
{
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
};
public static ITVSeriesManager TVSeriesManager { get; set; }
///
/// Gets or sets the view type.
///
public CollectionType? ViewType { get; set; }
///
/// Gets or sets the display parent id.
///
public new Guid DisplayParentId { get; set; }
///
/// Gets or sets the user id.
///
public Guid? UserId { get; set; }
///
[JsonIgnore]
public CollectionType? CollectionType => ViewType;
///
[JsonIgnore]
public override bool SupportsInheritedParentImages => false;
///
[JsonIgnore]
public override bool SupportsPlayedStatus => false;
///
[JsonIgnore]
public override bool SupportsPeople => false;
///
public override IEnumerable GetIdsForAncestorQuery()
{
if (!DisplayParentId.Equals(default))
{
yield return DisplayParentId;
}
else if (!ParentId.Equals(default))
{
yield return ParentId;
}
else
{
yield return Id;
}
}
///
public override int GetChildCount(User user)
{
return GetChildren(user, true).Count;
}
///
protected override QueryResult GetItemsInternal(InternalItemsQuery query)
{
var parent = this as Folder;
if (!DisplayParentId.Equals(default))
{
parent = LibraryManager.GetItemById(DisplayParentId) as Folder ?? parent;
}
else if (!ParentId.Equals(default))
{
parent = LibraryManager.GetItemById(ParentId) as Folder ?? parent;
}
return new UserViewBuilder(UserViewManager, LibraryManager, Logger, UserDataManager, TVSeriesManager)
.GetUserItems(parent, this, CollectionType, query);
}
///
public override List GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
{
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;
}
///
public override IEnumerable GetRecursiveChildren(User user, InternalItemsQuery query)
{
query.SetUser(user);
query.Recursive = true;
query.EnableTotalRecordCount = false;
query.ForceDirect = true;
return GetItemList(query);
}
///
protected override IEnumerable GetEligibleChildrenForRecursiveChildren(User user)
{
return GetChildren(user, false);
}
public static bool IsUserSpecific(Folder folder)
{
if (folder is not ICollectionFolder collectionFolder)
{
return false;
}
if (folder is ISupportsUserSpecificView supportsUserSpecific
&& supportsUserSpecific.EnableUserSpecificView)
{
return true;
}
return collectionFolder.CollectionType == Jellyfin.Data.Enums.CollectionType.Playlists;
}
public static bool IsEligibleForGrouping(Folder folder)
{
return folder is ICollectionFolder collectionFolder
&& IsEligibleForGrouping(collectionFolder.CollectionType);
}
public static bool IsEligibleForGrouping(CollectionType? viewType)
{
return _viewTypesEligibleForGrouping.Contains(viewType);
}
public static bool EnableOriginalFolder(CollectionType? viewType)
{
return _originalFolderViewTypes.Contains(viewType);
}
protected override Task ValidateChildrenInternal(IProgress progress, bool recursive, bool refreshChildMetadata, Providers.MetadataRefreshOptions refreshOptions, Providers.IDirectoryService directoryService, System.Threading.CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
}