| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | #pragma warning disable CS1591 |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Linq; |
| | 8 | | using System.Text.Json.Serialization; |
| | 9 | | using System.Threading; |
| | 10 | | using System.Threading.Tasks; |
| | 11 | | using Jellyfin.Database.Implementations.Entities; |
| | 12 | | using MediaBrowser.Controller.Providers; |
| | 13 | | using MediaBrowser.Model.Library; |
| | 14 | | using MediaBrowser.Model.Querying; |
| | 15 | |
|
| | 16 | | namespace MediaBrowser.Controller.Entities |
| | 17 | | { |
| | 18 | | /// <summary> |
| | 19 | | /// Special class used for User Roots. Children contain actual ones defined for this user |
| | 20 | | /// PLUS the virtual folders from the physical root (added by plug-ins). |
| | 21 | | /// </summary> |
| | 22 | | public class UserRootFolder : Folder |
| | 23 | | { |
| 43 | 24 | | private readonly Lock _childIdsLock = new(); |
| | 25 | | private List<Guid> _childrenIds = null; |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Initializes a new instance of the <see cref="UserRootFolder"/> class. |
| | 29 | | /// </summary> |
| 43 | 30 | | public UserRootFolder() |
| | 31 | | { |
| 43 | 32 | | IsRoot = true; |
| 43 | 33 | | } |
| | 34 | |
|
| | 35 | | [JsonIgnore] |
| 6 | 36 | | public override bool SupportsInheritedParentImages => false; |
| | 37 | |
|
| | 38 | | [JsonIgnore] |
| 0 | 39 | | public override bool SupportsPlayedStatus => false; |
| | 40 | |
|
| | 41 | | [JsonIgnore] |
| 45 | 42 | | protected override bool SupportsShortcutChildren => true; |
| | 43 | |
|
| | 44 | | [JsonIgnore] |
| 0 | 45 | | public override bool IsPreSorted => true; |
| | 46 | |
|
| | 47 | | private void ClearCache() |
| 57 | 48 | | { |
| | 49 | | lock (_childIdsLock) |
| | 50 | | { |
| 57 | 51 | | _childrenIds = null; |
| 57 | 52 | | } |
| 57 | 53 | | } |
| | 54 | |
|
| | 55 | | protected override IReadOnlyList<BaseItem> LoadChildren() |
| 747 | 56 | | { |
| | 57 | | lock (_childIdsLock) |
| | 58 | | { |
| 747 | 59 | | if (_childrenIds is null) |
| | 60 | | { |
| 64 | 61 | | var list = base.LoadChildren(); |
| 64 | 62 | | _childrenIds = list.Select(i => i.Id).ToList(); |
| 64 | 63 | | return list; |
| | 64 | | } |
| | 65 | |
|
| 683 | 66 | | return _childrenIds.Select(LibraryManager.GetItemById).Where(i => i is not null).ToList(); |
| | 67 | | } |
| 747 | 68 | | } |
| | 69 | |
|
| | 70 | | protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query) |
| | 71 | | { |
| 0 | 72 | | if (query.Recursive) |
| | 73 | | { |
| 0 | 74 | | return QueryRecursive(query); |
| | 75 | | } |
| | 76 | |
|
| 0 | 77 | | var result = UserViewManager.GetUserViews(new UserViewQuery |
| 0 | 78 | | { |
| 0 | 79 | | User = query.User, |
| 0 | 80 | | PresetViews = query.PresetViews |
| 0 | 81 | | }); |
| | 82 | |
|
| 0 | 83 | | return UserViewBuilder.SortAndPage(result, null, query, LibraryManager, true); |
| | 84 | | } |
| | 85 | |
|
| | 86 | | public override int GetChildCount(User user) |
| | 87 | | { |
| 6 | 88 | | return GetChildren(user, true).Count; |
| | 89 | | } |
| | 90 | |
|
| | 91 | | protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user) |
| | 92 | | { |
| 10 | 93 | | var list = base.GetEligibleChildrenForRecursiveChildren(user).ToList(); |
| 10 | 94 | | list.AddRange(LibraryManager.RootFolder.VirtualChildren); |
| | 95 | |
|
| 10 | 96 | | return list; |
| | 97 | | } |
| | 98 | |
|
| | 99 | | public override bool BeforeMetadataRefresh(bool replaceAllMetadata) |
| | 100 | | { |
| 15 | 101 | | ClearCache(); |
| 15 | 102 | | var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata); |
| | 103 | |
|
| 15 | 104 | | if (string.Equals("default", Name, StringComparison.OrdinalIgnoreCase)) |
| | 105 | | { |
| 10 | 106 | | Name = "Media Folders"; |
| 10 | 107 | | hasChanges = true; |
| | 108 | | } |
| | 109 | |
|
| 15 | 110 | | return hasChanges; |
| | 111 | | } |
| | 112 | |
|
| | 113 | | protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService) |
| | 114 | | { |
| 14 | 115 | | ClearCache(); |
| | 116 | |
|
| 14 | 117 | | return base.GetNonCachedChildren(directoryService); |
| | 118 | | } |
| | 119 | |
|
| | 120 | | protected override async Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshC |
| | 121 | | { |
| | 122 | | ClearCache(); |
| | 123 | |
|
| | 124 | | await base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, allowRemoveRoot, refreshOptio |
| | 125 | | .ConfigureAwait(false); |
| | 126 | |
|
| | 127 | | ClearCache(); |
| | 128 | |
|
| | 129 | | // Not the best way to handle this, but it solves an issue |
| | 130 | | // CollectionFolders aren't always getting saved after changes |
| | 131 | | // This means that grabbing the item by Id may end up returning the old one |
| | 132 | | // Fix is in two places - make sure the folder gets saved |
| | 133 | | // And here to remedy it for affected users. |
| | 134 | | // In theory this can be removed eventually. |
| | 135 | | foreach (var item in Children) |
| | 136 | | { |
| | 137 | | LibraryManager.RegisterItem(item); |
| | 138 | | } |
| | 139 | | } |
| | 140 | | } |
| | 141 | | } |