jellyfin/MediaBrowser.Controller/Entities/UserRootFolder.cs

83 lines
3 KiB
C#
Raw Normal View History

2014-06-07 21:46:24 +02:00
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Library;
using MediaBrowser.Model.Querying;
2014-03-06 06:17:13 +01:00
using System;
2014-02-10 21:11:46 +01:00
using System.Collections.Generic;
using System.Linq;
2014-06-04 05:34:36 +02:00
using System.Threading;
using System.Threading.Tasks;
2013-02-21 02:33:05 +01: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
{
public override async Task<QueryResult<BaseItem>> GetUserItems(UserItemsQuery query)
{
var result = await UserViewManager.GetUserViews(new UserViewQuery
{
UserId = query.User.Id.ToString("N")
}, CancellationToken.None).ConfigureAwait(false);
return SortAndFilter(result, query);
}
2014-09-07 01:06:14 +02:00
public override bool IsPreSorted
{
get
{
return true;
}
}
2013-02-21 02:33:05 +01:00
/// <summary>
/// Get the children of this folder from the actual file system
/// </summary>
/// <returns>IEnumerable{BaseItem}.</returns>
2014-02-10 19:39:41 +01:00
protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
2013-02-21 02:33:05 +01:00
{
2014-02-08 23:38:02 +01:00
return base.GetNonCachedChildren(directoryService).Concat(LibraryManager.RootFolder.VirtualChildren);
2013-02-21 02:33:05 +01:00
}
2014-02-10 21:11:46 +01:00
2014-02-13 06:11:54 +01:00
public override bool BeforeMetadataRefresh()
2014-02-10 21:11:46 +01:00
{
2014-02-13 06:11:54 +01:00
var hasChanges = base.BeforeMetadataRefresh();
2014-02-10 21:11:46 +01:00
2014-03-06 06:17:13 +01:00
if (string.Equals("default", Name, StringComparison.OrdinalIgnoreCase))
2014-02-10 21:11:46 +01:00
{
2014-02-21 06:04:11 +01:00
Name = "Media Folders";
2014-02-13 06:11:54 +01:00
hasChanges = true;
2014-02-10 21:11:46 +01:00
}
2014-02-13 06:11:54 +01:00
return hasChanges;
2014-02-10 21:11:46 +01:00
}
2014-06-04 05:34:36 +02: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-21 02:33:05 +01:00
}
}