UserView.cs 5.7 KB

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