diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Collections/CollectionManager.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Collections/CollectionManager.cs | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs index 9fee27db9..faf73c059 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs @@ -6,7 +6,6 @@ using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Logging; -using MoreLinq; using System; using System.Collections.Generic; using System.IO; @@ -41,6 +40,14 @@ namespace MediaBrowser.Server.Implementations.Collections .FirstOrDefault(); } + public IEnumerable<BoxSet> GetCollections(User user) + { + var folder = GetCollectionsFolder(user.Id.ToString("N")); + return folder == null ? + new List<BoxSet>() : + folder.GetChildren(user, true).OfType<BoxSet>(); + } + public async Task<BoxSet> CreateCollection(CollectionCreationOptions options) { var name = options.Name; @@ -69,7 +76,6 @@ namespace MediaBrowser.Server.Implementations.Collections { Name = name, Parent = parentFolder, - DisplayMediaType = "Collection", Path = path, IsLocked = options.IsLocked, ProviderIds = options.ProviderIds, @@ -168,24 +174,13 @@ namespace MediaBrowser.Server.Implementations.Collections } list.Add(LinkedChild.Create(item)); - - var supportsGrouping = item as ISupportsBoxSetGrouping; - - if (supportsGrouping != null) - { - var boxsetIdList = supportsGrouping.BoxSetIdList.ToList(); - if (!boxsetIdList.Contains(collectionId)) - { - boxsetIdList.Add(collectionId); - } - supportsGrouping.BoxSetIdList = boxsetIdList; - } } collection.LinkedChildren.AddRange(list); - await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); + collection.UpdateRatingToContent(); + await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false); if (fireEvent) @@ -228,15 +223,6 @@ namespace MediaBrowser.Server.Implementations.Collections { itemList.Add(childItem); } - - var supportsGrouping = childItem as ISupportsBoxSetGrouping; - - if (supportsGrouping != null) - { - var boxsetIdList = supportsGrouping.BoxSetIdList.ToList(); - boxsetIdList.Remove(collectionId); - supportsGrouping.BoxSetIdList = boxsetIdList; - } } var shortcutFiles = Directory @@ -258,7 +244,7 @@ namespace MediaBrowser.Server.Implementations.Collections { foreach (var file in shortcutFilesToDelete) { - File.Delete(file); + _fileSystem.DeleteFile(file); } foreach (var child in list) @@ -274,8 +260,9 @@ namespace MediaBrowser.Server.Implementations.Collections } } - await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); + collection.UpdateRatingToContent(); + await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false); EventHelper.FireEventIfNotNull(ItemsRemovedFromCollection, this, new CollectionModifiedEventArgs @@ -288,29 +275,41 @@ namespace MediaBrowser.Server.Implementations.Collections public IEnumerable<BaseItem> CollapseItemsWithinBoxSets(IEnumerable<BaseItem> items, User user) { - var itemsToCollapse = new List<ISupportsBoxSetGrouping>(); - var boxsets = new List<BaseItem>(); + var results = new Dictionary<Guid, BaseItem>(); - var list = items.ToList(); + var allBoxsets = GetCollections(user).ToList(); - foreach (var item in list.OfType<ISupportsBoxSetGrouping>()) + foreach (var item in items) { - var currentBoxSets = item.BoxSetIdList - .Select(i => _libraryManager.GetItemById(i)) - .Where(i => i != null && i.IsVisible(user)) - .ToList(); + var grouping = item as ISupportsBoxSetGrouping; - if (currentBoxSets.Count > 0) + if (grouping == null) + { + results[item.Id] = item; + } + else { - itemsToCollapse.Add(item); - boxsets.AddRange(currentBoxSets); + var itemId = item.Id; + + var currentBoxSets = allBoxsets + .Where(i => i.GetLinkedChildren().Any(j => j.Id == itemId)) + .ToList(); + + if (currentBoxSets.Count > 0) + { + foreach (var boxset in currentBoxSets) + { + results[boxset.Id] = boxset; + } + } + else + { + results[item.Id] = item; + } } } - return list - .Except(itemsToCollapse.Cast<BaseItem>()) - .Concat(boxsets) - .DistinctBy(i => i.Id); + return results.Values; } } } |
