2
0

UserRootFolder.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using MediaBrowser.Controller.Providers;
  2. using MediaBrowser.Model.Dto;
  3. using MediaBrowser.Model.Library;
  4. using MediaBrowser.Model.Querying;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. namespace MediaBrowser.Controller.Entities
  11. {
  12. /// <summary>
  13. /// Special class used for User Roots. Children contain actual ones defined for this user
  14. /// PLUS the virtual folders from the physical root (added by plug-ins).
  15. /// </summary>
  16. public class UserRootFolder : Folder
  17. {
  18. public override async Task<QueryResult<BaseItem>> GetUserItems(UserItemsQuery query)
  19. {
  20. var result = await UserViewManager.GetUserViews(new UserViewQuery
  21. {
  22. UserId = query.User.Id.ToString("N")
  23. }, CancellationToken.None).ConfigureAwait(false);
  24. return SortAndFilter(result, query);
  25. }
  26. public override bool IsPreSorted
  27. {
  28. get
  29. {
  30. return true;
  31. }
  32. }
  33. /// <summary>
  34. /// Get the children of this folder from the actual file system
  35. /// </summary>
  36. /// <returns>IEnumerable{BaseItem}.</returns>
  37. protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
  38. {
  39. return base.GetNonCachedChildren(directoryService).Concat(LibraryManager.RootFolder.VirtualChildren);
  40. }
  41. public override bool BeforeMetadataRefresh()
  42. {
  43. var hasChanges = base.BeforeMetadataRefresh();
  44. if (string.Equals("default", Name, StringComparison.OrdinalIgnoreCase))
  45. {
  46. Name = "Media Folders";
  47. hasChanges = true;
  48. }
  49. return hasChanges;
  50. }
  51. protected override async Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
  52. {
  53. await base.ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService)
  54. .ConfigureAwait(false);
  55. // Not the best way to handle this, but it solves an issue
  56. // CollectionFolders aren't always getting saved after changes
  57. // This means that grabbing the item by Id may end up returning the old one
  58. // Fix is in two places - make sure the folder gets saved
  59. // And here to remedy it for affected users.
  60. // In theory this can be removed eventually.
  61. foreach (var item in Children)
  62. {
  63. LibraryManager.RegisterItem(item);
  64. }
  65. }
  66. public override void FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, User user)
  67. {
  68. // Nothing meaninful here and will only waste resources
  69. }
  70. }
  71. }