Replace UserId with User in UserViewQuery

This commit is contained in:
Bond_009 2024-05-15 18:12:42 +02:00
parent c680dbb53e
commit 09f4477510
5 changed files with 13 additions and 19 deletions

View File

@ -1530,7 +1530,7 @@ namespace Emby.Server.Implementations.Library
{
var userViews = UserViewManager.GetUserViews(new UserViewQuery
{
UserId = user.Id,
User = user,
IncludeHidden = true,
IncludeExternalContent = allowExternalContent
});

View File

@ -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));
}

View File

@ -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<BaseItemDto>(dtos);

View File

@ -76,7 +76,7 @@ namespace MediaBrowser.Controller.Entities
var result = UserViewManager.GetUserViews(new UserViewQuery
{
UserId = query.User.Id,
User = query.User,
PresetViews = query.PresetViews
});

View File

@ -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
}
/// <summary>
/// Gets or sets the user identifier.
/// Gets or sets the user.
/// </summary>
/// <value>The user identifier.</value>
public Guid UserId { get; set; }
/// <value>The user.</value>
public required User User { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [include external content].