UserView.cs 5.8 KB

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