jellyfin/MediaBrowser.Controller/Entities/UserRootFolder.cs

111 lines
3.8 KiB
C#
Raw Normal View History

2015-08-14 18:44:30 -07:00
using System.Runtime.Serialization;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Library;
using MediaBrowser.Model.Querying;
2014-03-05 22:17:13 -07:00
using System;
2014-02-10 13:11:46 -07:00
using System.Collections.Generic;
using System.Linq;
2014-06-03 20:34:36 -07:00
using System.Threading;
using System.Threading.Tasks;
2013-02-20 18:33:05 -07: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
{
2014-10-06 16:58:46 -07:00
public override async Task<QueryResult<BaseItem>> GetItems(InternalItemsQuery query)
{
2014-10-06 16:58:46 -07:00
if (query.Recursive)
{
2016-03-19 23:46:51 -07:00
return QueryRecursive(query);
2014-10-06 16:58:46 -07:00
}
var result = await UserViewManager.GetUserViews(new UserViewQuery
{
2016-03-01 11:42:39 -07:00
UserId = query.User.Id.ToString("N"),
PresetViews = query.PresetViews
}, CancellationToken.None).ConfigureAwait(false);
2016-03-19 23:46:51 -07:00
var user = query.User;
Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
2015-01-24 23:34:50 -07:00
return PostFilterAndSort(result.Where(filter), query);
}
2015-08-14 18:44:30 -07:00
[IgnoreDataMember]
protected override bool SupportsShortcutChildren
{
get
{
return true;
}
}
[IgnoreDataMember]
2014-09-06 16:06:14 -07:00
public override bool IsPreSorted
{
get
{
return true;
}
}
2015-10-30 09:40:47 -07:00
protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
{
2015-11-02 21:34:47 -07:00
var list = base.GetEligibleChildrenForRecursiveChildren(user).ToList();
list.AddRange(LibraryManager.RootFolder.VirtualChildren);
return list;
2015-10-30 09:40:47 -07:00
}
2013-02-20 18:33:05 -07:00
/// <summary>
/// Get the children of this folder from the actual file system
/// </summary>
/// <returns>IEnumerable{BaseItem}.</returns>
2014-02-10 11:39:41 -07:00
protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
2013-02-20 18:33:05 -07:00
{
2015-10-30 09:40:47 -07:00
return base.GetNonCachedChildren(directoryService);
2013-02-20 18:33:05 -07:00
}
2014-02-10 13:11:46 -07:00
2014-02-12 22:11:54 -07:00
public override bool BeforeMetadataRefresh()
2014-02-10 13:11:46 -07:00
{
2014-02-12 22:11:54 -07:00
var hasChanges = base.BeforeMetadataRefresh();
2014-02-10 13:11:46 -07:00
2014-03-05 22:17:13 -07:00
if (string.Equals("default", Name, StringComparison.OrdinalIgnoreCase))
2014-02-10 13:11:46 -07:00
{
2014-02-20 22:04:11 -07:00
Name = "Media Folders";
2014-02-12 22:11:54 -07:00
hasChanges = true;
2014-02-10 13:11:46 -07:00
}
2014-02-12 22:11:54 -07:00
return hasChanges;
2014-02-10 13:11:46 -07:00
}
2014-06-03 20:34:36 -07:00
protected override async Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
{
await base.ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService)
.ConfigureAwait(false);
// 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);
}
}
public override void FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, User user)
{
// Nothing meaninful here and will only waste resources
}
2013-02-20 18:33:05 -07:00
}
}