2021-05-06 22:39:20 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-08-22 19:56:24 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2019-10-15 15:49:49 +00:00
|
|
|
using System.Text.Json.Serialization;
|
2018-12-27 23:27:57 +00:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-05-20 17:07:53 +00:00
|
|
|
using Jellyfin.Data.Entities;
|
2019-01-13 19:25:32 +00:00
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Library;
|
|
|
|
using MediaBrowser.Model.Querying;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Entities
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Special class used for User Roots. Children contain actual ones defined for this user
|
|
|
|
/// PLUS the virtual folders from the physical root (added by plug-ins).
|
|
|
|
/// </summary>
|
|
|
|
public class UserRootFolder : Folder
|
|
|
|
{
|
|
|
|
private readonly object _childIdsLock = new object();
|
2021-08-14 03:34:36 +00:00
|
|
|
private List<Guid> _childrenIds = null;
|
|
|
|
|
2021-09-09 13:59:13 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="UserRootFolder"/> class.
|
|
|
|
/// </summary>
|
|
|
|
public UserRootFolder()
|
|
|
|
{
|
|
|
|
IsRoot = true;
|
|
|
|
}
|
|
|
|
|
2021-08-14 03:34:36 +00:00
|
|
|
[JsonIgnore]
|
|
|
|
public override bool SupportsInheritedParentImages => false;
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
public override bool SupportsPlayedStatus => false;
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
protected override bool SupportsShortcutChildren => true;
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
public override bool IsPreSorted => true;
|
|
|
|
|
|
|
|
private void ClearCache()
|
|
|
|
{
|
|
|
|
lock (_childIdsLock)
|
|
|
|
{
|
|
|
|
_childrenIds = null;
|
|
|
|
}
|
|
|
|
}
|
2021-05-13 13:32:02 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
protected override List<BaseItem> LoadChildren()
|
|
|
|
{
|
|
|
|
lock (_childIdsLock)
|
|
|
|
{
|
2022-12-05 14:00:20 +00:00
|
|
|
if (_childrenIds is null)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
var list = base.LoadChildren();
|
|
|
|
_childrenIds = list.Select(i => i.Id).ToList();
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2022-12-05 14:01:13 +00:00
|
|
|
return _childrenIds.Select(LibraryManager.GetItemById).Where(i => i is not null).ToList();
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query)
|
|
|
|
{
|
|
|
|
if (query.Recursive)
|
|
|
|
{
|
|
|
|
return QueryRecursive(query);
|
|
|
|
}
|
|
|
|
|
|
|
|
var result = UserViewManager.GetUserViews(new UserViewQuery
|
|
|
|
{
|
|
|
|
UserId = query.User.Id,
|
|
|
|
PresetViews = query.PresetViews
|
|
|
|
});
|
|
|
|
|
2020-01-24 05:43:28 +00:00
|
|
|
return UserViewBuilder.SortAndPage(result, null, query, LibraryManager, true);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
public override int GetChildCount(User user)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
return GetChildren(user, true).Count;
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:07:53 +00:00
|
|
|
protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
var list = base.GetEligibleChildrenForRecursiveChildren(user).ToList();
|
|
|
|
list.AddRange(LibraryManager.RootFolder.VirtualChildren);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2021-05-13 13:32:02 +00:00
|
|
|
public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
ClearCache();
|
2021-05-13 13:32:02 +00:00
|
|
|
var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
if (string.Equals("default", Name, StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
Name = "Media Folders";
|
|
|
|
hasChanges = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasChanges;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
|
|
|
|
{
|
|
|
|
ClearCache();
|
|
|
|
|
|
|
|
return base.GetNonCachedChildren(directoryService);
|
|
|
|
}
|
|
|
|
|
2021-06-06 15:16:41 +00:00
|
|
|
protected override async Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
ClearCache();
|
|
|
|
|
2021-06-06 15:16:41 +00:00
|
|
|
await base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, refreshOptions, directoryService, cancellationToken)
|
2018-12-27 23:27:57 +00:00
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
ClearCache();
|
|
|
|
|
|
|
|
// Not the best way to handle this, but it solves an issue
|
|
|
|
// CollectionFolders aren't always getting saved after changes
|
|
|
|
// This means that grabbing the item by Id may end up returning the old one
|
|
|
|
// Fix is in two places - make sure the folder gets saved
|
|
|
|
// And here to remedy it for affected users.
|
|
|
|
// In theory this can be removed eventually.
|
|
|
|
foreach (var item in Children)
|
|
|
|
{
|
|
|
|
LibraryManager.RegisterItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|