UserView.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text.Json.Serialization;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using Jellyfin.Data.Enums;
  10. using Jellyfin.Database.Implementations.Entities;
  11. using Jellyfin.Extensions;
  12. using MediaBrowser.Controller.Providers;
  13. using MediaBrowser.Controller.TV;
  14. using MediaBrowser.Model.Querying;
  15. namespace MediaBrowser.Controller.Entities
  16. {
  17. public class UserView : Folder, IHasCollectionType
  18. {
  19. private static readonly CollectionType?[] _viewTypesEligibleForGrouping =
  20. {
  21. Jellyfin.Data.Enums.CollectionType.movies,
  22. Jellyfin.Data.Enums.CollectionType.tvshows,
  23. null
  24. };
  25. private static readonly CollectionType?[] _originalFolderViewTypes =
  26. {
  27. Jellyfin.Data.Enums.CollectionType.books,
  28. Jellyfin.Data.Enums.CollectionType.musicvideos,
  29. Jellyfin.Data.Enums.CollectionType.homevideos,
  30. Jellyfin.Data.Enums.CollectionType.photos,
  31. Jellyfin.Data.Enums.CollectionType.music,
  32. Jellyfin.Data.Enums.CollectionType.boxsets
  33. };
  34. public static ITVSeriesManager TVSeriesManager { get; set; }
  35. /// <summary>
  36. /// Gets or sets the view type.
  37. /// </summary>
  38. public CollectionType? ViewType { get; set; }
  39. /// <summary>
  40. /// Gets or sets the display parent id.
  41. /// </summary>
  42. public new Guid DisplayParentId { get; set; }
  43. /// <summary>
  44. /// Gets or sets the user id.
  45. /// </summary>
  46. public Guid? UserId { get; set; }
  47. /// <inheritdoc />
  48. [JsonIgnore]
  49. public CollectionType? CollectionType => ViewType;
  50. /// <inheritdoc />
  51. [JsonIgnore]
  52. public override bool SupportsInheritedParentImages => false;
  53. /// <inheritdoc />
  54. [JsonIgnore]
  55. public override bool SupportsPlayedStatus => false;
  56. /// <inheritdoc />
  57. [JsonIgnore]
  58. public override bool SupportsPeople => false;
  59. /// <inheritdoc />
  60. public override IEnumerable<Guid> GetIdsForAncestorQuery()
  61. {
  62. if (!DisplayParentId.IsEmpty())
  63. {
  64. yield return DisplayParentId;
  65. }
  66. else if (!ParentId.IsEmpty())
  67. {
  68. yield return ParentId;
  69. }
  70. else
  71. {
  72. yield return Id;
  73. }
  74. }
  75. /// <inheritdoc />
  76. public override int GetChildCount(User user)
  77. {
  78. return GetChildren(user, true).Count;
  79. }
  80. /// <inheritdoc />
  81. protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query)
  82. {
  83. var parent = this as Folder;
  84. if (!DisplayParentId.IsEmpty())
  85. {
  86. parent = LibraryManager.GetItemById(DisplayParentId) as Folder ?? parent;
  87. }
  88. else if (!ParentId.IsEmpty())
  89. {
  90. parent = LibraryManager.GetItemById(ParentId) as Folder ?? parent;
  91. }
  92. return new UserViewBuilder(UserViewManager, LibraryManager, Logger, UserDataManager, TVSeriesManager)
  93. .GetUserItems(parent, this, CollectionType, query);
  94. }
  95. /// <inheritdoc />
  96. public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
  97. {
  98. query ??= new InternalItemsQuery(user);
  99. query.EnableTotalRecordCount = false;
  100. var result = GetItemList(query);
  101. return result.ToList();
  102. }
  103. /// <inheritdoc />
  104. public override bool CanDelete()
  105. {
  106. return false;
  107. }
  108. /// <inheritdoc />
  109. public override bool IsSaveLocalMetadataEnabled()
  110. {
  111. return true;
  112. }
  113. /// <inheritdoc />
  114. public override IReadOnlyList<BaseItem> GetRecursiveChildren(User user, InternalItemsQuery query)
  115. {
  116. query.SetUser(user);
  117. query.Recursive = true;
  118. query.EnableTotalRecordCount = false;
  119. query.ForceDirect = true;
  120. return GetItemList(query);
  121. }
  122. /// <inheritdoc />
  123. protected override IReadOnlyList<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
  124. {
  125. return GetChildren(user, false);
  126. }
  127. public static bool IsUserSpecific(Folder folder)
  128. {
  129. if (folder is not ICollectionFolder collectionFolder)
  130. {
  131. return false;
  132. }
  133. if (folder is ISupportsUserSpecificView supportsUserSpecific
  134. && supportsUserSpecific.EnableUserSpecificView)
  135. {
  136. return true;
  137. }
  138. return collectionFolder.CollectionType == Jellyfin.Data.Enums.CollectionType.playlists;
  139. }
  140. public static bool IsEligibleForGrouping(Folder folder)
  141. {
  142. return folder is ICollectionFolder collectionFolder
  143. && IsEligibleForGrouping(collectionFolder.CollectionType);
  144. }
  145. public static bool IsEligibleForGrouping(CollectionType? viewType)
  146. {
  147. return _viewTypesEligibleForGrouping.Contains(viewType);
  148. }
  149. public static bool EnableOriginalFolder(CollectionType? viewType)
  150. {
  151. return _originalFolderViewTypes.Contains(viewType);
  152. }
  153. protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
  154. {
  155. return Task.CompletedTask;
  156. }
  157. }
  158. }