UserView.cs 5.8 KB

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