2016-10-25 21:02:04 +02:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2015-08-15 03:44:30 +02:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-09-01 22:10:54 +02:00
|
|
|
|
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
|
|
|
|
|
{
|
2016-08-13 22:54:29 +02:00
|
|
|
|
private List<Guid> _childrenIds = null;
|
|
|
|
|
private readonly object _childIdsLock = new object();
|
2016-08-14 18:39:23 +02:00
|
|
|
|
protected override IEnumerable<BaseItem> LoadChildren()
|
|
|
|
|
{
|
|
|
|
|
lock (_childIdsLock)
|
|
|
|
|
{
|
|
|
|
|
if (_childrenIds == null)
|
|
|
|
|
{
|
|
|
|
|
var list = base.LoadChildren().ToList();
|
|
|
|
|
_childrenIds = list.Select(i => i.Id).ToList();
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2016-08-13 22:54:29 +02:00
|
|
|
|
|
2016-08-14 18:39:23 +02:00
|
|
|
|
return _childrenIds.Select(LibraryManager.GetItemById).Where(i => i != null).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-13 22:54:29 +02:00
|
|
|
|
|
2016-10-11 08:46:59 +02:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
public override bool SupportsPlayedStatus
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 02:22:59 +02:00
|
|
|
|
private void ClearCache()
|
2016-08-13 22:54:29 +02:00
|
|
|
|
{
|
|
|
|
|
lock (_childIdsLock)
|
|
|
|
|
{
|
|
|
|
|
_childrenIds = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:48:54 +02:00
|
|
|
|
protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query)
|
2014-09-01 22:10:54 +02:00
|
|
|
|
{
|
2014-10-07 01:58:46 +02:00
|
|
|
|
if (query.Recursive)
|
|
|
|
|
{
|
2016-03-20 07:46:51 +01:00
|
|
|
|
return QueryRecursive(query);
|
2014-10-07 01:58:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:48:54 +02:00
|
|
|
|
var result = UserViewManager.GetUserViews(new UserViewQuery
|
2014-09-01 22:10:54 +02:00
|
|
|
|
{
|
2016-03-01 19:42:39 +01:00
|
|
|
|
UserId = query.User.Id.ToString("N"),
|
|
|
|
|
PresetViews = query.PresetViews
|
2014-09-01 22:10:54 +02:00
|
|
|
|
|
2017-05-26 08:48:54 +02:00
|
|
|
|
}, CancellationToken.None).Result;
|
2014-09-01 22:10:54 +02:00
|
|
|
|
|
2016-03-20 07:46:51 +01:00
|
|
|
|
var user = query.User;
|
|
|
|
|
Func<BaseItem, bool> filter = i => UserViewBuilder.Filter(i, user, query, UserDataManager, LibraryManager);
|
2017-05-26 08:48:54 +02:00
|
|
|
|
|
2016-08-17 22:52:16 +02:00
|
|
|
|
return PostFilterAndSort(result.Where(filter), query, true, true);
|
2014-09-01 22:10:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-16 15:24:12 +02:00
|
|
|
|
public override int GetChildCount(User user)
|
|
|
|
|
{
|
|
|
|
|
return GetChildren(user, true).Count();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 03:44:30 +02:00
|
|
|
|
[IgnoreDataMember]
|
|
|
|
|
protected override bool SupportsShortcutChildren
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[IgnoreDataMember]
|
2014-09-07 01:06:14 +02:00
|
|
|
|
public override bool IsPreSorted
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-30 17:40:47 +01:00
|
|
|
|
protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
|
|
|
|
|
{
|
2015-11-03 05:34:47 +01:00
|
|
|
|
var list = base.GetEligibleChildrenForRecursiveChildren(user).ToList();
|
|
|
|
|
list.AddRange(LibraryManager.RootFolder.VirtualChildren);
|
|
|
|
|
|
|
|
|
|
return list;
|
2015-10-30 17:40:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-13 06:11:54 +01:00
|
|
|
|
public override bool BeforeMetadataRefresh()
|
2014-02-10 21:11:46 +01:00
|
|
|
|
{
|
2016-08-16 02:22:59 +02:00
|
|
|
|
ClearCache();
|
2016-08-13 22:54:29 +02: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
|
|
|
|
|
2016-08-16 02:22:59 +02:00
|
|
|
|
protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
|
|
|
|
|
{
|
|
|
|
|
ClearCache();
|
|
|
|
|
|
|
|
|
|
return base.GetNonCachedChildren(directoryService);
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2016-08-16 02:22:59 +02:00
|
|
|
|
ClearCache();
|
2016-08-13 22:54:29 +02:00
|
|
|
|
|
2014-06-04 05:34:36 +02:00
|
|
|
|
await base.ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
2016-08-16 02:22:59 +02:00
|
|
|
|
ClearCache();
|
|
|
|
|
|
2014-06-04 05:34:36 +02:00
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-21 02:33:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|