From 09f447751044f961446aab6b7d825a241398933d Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 15 May 2024 18:12:42 +0200 Subject: [PATCH] Replace UserId with User in UserViewQuery --- .../Library/LibraryManager.cs | 2 +- .../Library/UserViewManager.cs | 15 ++++----------- Jellyfin.Api/Controllers/UserViewsController.cs | 6 +++--- .../Entities/UserRootFolder.cs | 2 +- MediaBrowser.Model/Library/UserViewQuery.cs | 7 ++++--- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index cbded1ec6..6d71e99a1 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -1530,7 +1530,7 @@ namespace Emby.Server.Implementations.Library { var userViews = UserViewManager.GetUserViews(new UserViewQuery { - UserId = user.Id, + User = user, IncludeHidden = true, IncludeExternalContent = allowExternalContent }); diff --git a/Emby.Server.Implementations/Library/UserViewManager.cs b/Emby.Server.Implementations/Library/UserViewManager.cs index 466f83360..e9cf47d46 100644 --- a/Emby.Server.Implementations/Library/UserViewManager.cs +++ b/Emby.Server.Implementations/Library/UserViewManager.cs @@ -16,7 +16,6 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.Channels; -using MediaBrowser.Model.Entities; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Library; using MediaBrowser.Model.Querying; @@ -27,17 +26,15 @@ namespace Emby.Server.Implementations.Library { private readonly ILibraryManager _libraryManager; private readonly ILocalizationManager _localizationManager; - private readonly IUserManager _userManager; private readonly IChannelManager _channelManager; private readonly ILiveTvManager _liveTvManager; private readonly IServerConfigurationManager _config; - public UserViewManager(ILibraryManager libraryManager, ILocalizationManager localizationManager, IUserManager userManager, IChannelManager channelManager, ILiveTvManager liveTvManager, IServerConfigurationManager config) + public UserViewManager(ILibraryManager libraryManager, ILocalizationManager localizationManager, IChannelManager channelManager, ILiveTvManager liveTvManager, IServerConfigurationManager config) { _libraryManager = libraryManager; _localizationManager = localizationManager; - _userManager = userManager; _channelManager = channelManager; _liveTvManager = liveTvManager; _config = config; @@ -45,11 +42,7 @@ namespace Emby.Server.Implementations.Library public Folder[] GetUserViews(UserViewQuery query) { - var user = _userManager.GetUserById(query.UserId); - if (user is null) - { - throw new ArgumentException("User id specified in the query does not exist.", nameof(query)); - } + var user = query.User; var folders = _libraryManager.GetUserRootFolder() .GetChildren(user, true) @@ -125,14 +118,14 @@ namespace Emby.Server.Implementations.Library { var channelResult = _channelManager.GetChannelsInternalAsync(new ChannelQuery { - UserId = query.UserId + UserId = user.Id }).GetAwaiter().GetResult(); var channels = channelResult.Items; list.AddRange(channels); - if (_liveTvManager.GetEnabledUsers().Select(i => i.Id).Contains(query.UserId)) + if (_liveTvManager.GetEnabledUsers().Select(i => i.Id).Contains(user.Id)) { list.Add(_liveTvManager.GetInternalLiveTvFolder(CancellationToken.None)); } diff --git a/Jellyfin.Api/Controllers/UserViewsController.cs b/Jellyfin.Api/Controllers/UserViewsController.cs index 01da50d02..e24f78a88 100644 --- a/Jellyfin.Api/Controllers/UserViewsController.cs +++ b/Jellyfin.Api/Controllers/UserViewsController.cs @@ -8,6 +8,7 @@ using Jellyfin.Api.Helpers; using Jellyfin.Api.ModelBinders; using Jellyfin.Api.Models.UserViewDtos; using Jellyfin.Data.Enums; +using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; @@ -69,8 +70,9 @@ public class UserViewsController : BaseJellyfinApiController [FromQuery] bool includeHidden = false) { userId = RequestHelpers.GetUserId(User, userId); + var user = _userManager.GetUserById(userId.Value) ?? throw new ResourceNotFoundException(); - var query = new UserViewQuery { UserId = userId.Value, IncludeHidden = includeHidden }; + var query = new UserViewQuery { User = user, IncludeHidden = includeHidden }; if (includeExternalContent.HasValue) { @@ -87,8 +89,6 @@ public class UserViewsController : BaseJellyfinApiController var dtoOptions = new DtoOptions().AddClientFields(User); dtoOptions.Fields = [..dtoOptions.Fields, ItemFields.PrimaryImageAspectRatio, ItemFields.DisplayPreferencesId]; - var user = _userManager.GetUserById(userId.Value); - var dtos = Array.ConvertAll(folders, i => _dtoService.GetBaseItemDto(i, dtoOptions, user)); return new QueryResult(dtos); diff --git a/MediaBrowser.Controller/Entities/UserRootFolder.cs b/MediaBrowser.Controller/Entities/UserRootFolder.cs index fc8a29763..a687adedd 100644 --- a/MediaBrowser.Controller/Entities/UserRootFolder.cs +++ b/MediaBrowser.Controller/Entities/UserRootFolder.cs @@ -76,7 +76,7 @@ namespace MediaBrowser.Controller.Entities var result = UserViewManager.GetUserViews(new UserViewQuery { - UserId = query.User.Id, + User = query.User, PresetViews = query.PresetViews }); diff --git a/MediaBrowser.Model/Library/UserViewQuery.cs b/MediaBrowser.Model/Library/UserViewQuery.cs index e20d6af49..643a1f9b1 100644 --- a/MediaBrowser.Model/Library/UserViewQuery.cs +++ b/MediaBrowser.Model/Library/UserViewQuery.cs @@ -1,6 +1,7 @@ #pragma warning disable CS1591 using System; +using Jellyfin.Data.Entities; using Jellyfin.Data.Enums; namespace MediaBrowser.Model.Library @@ -14,10 +15,10 @@ namespace MediaBrowser.Model.Library } /// - /// Gets or sets the user identifier. + /// Gets or sets the user. /// - /// The user identifier. - public Guid UserId { get; set; } + /// The user. + public required User User { get; set; } /// /// Gets or sets a value indicating whether [include external content].