Optimize Guid comparisons

* Use Guid.Equals(Guid) instead of the == override
* Ban the usage of Guid.Equals(Object) to prevent accidental boxing
* Compare to default(Guid) instead of Guid.Empty
This commit is contained in:
Bond_009 2022-02-21 14:15:09 +01:00
parent bbac59c6d6
commit f50a250cd9
66 changed files with 355 additions and 326 deletions

View File

@ -1 +1,4 @@
P:System.Threading.Tasks.Task`1.Result P:System.Threading.Tasks.Task`1.Result
M:System.Guid.op_Equality(System.Guid,System.Guid)
M:System.Guid.op_Inequality(System.Guid,System.Guid)
M:System.Guid.Equals(System.Object)

View File

@ -160,7 +160,7 @@ namespace Emby.Dlna.Didl
else else
{ {
var parent = item.DisplayParentId; var parent = item.DisplayParentId;
if (!parent.Equals(Guid.Empty)) if (!parent.Equals(default))
{ {
writer.WriteAttributeString("parentID", GetClientId(parent, null)); writer.WriteAttributeString("parentID", GetClientId(parent, null));
} }
@ -657,7 +657,7 @@ namespace Emby.Dlna.Didl
else else
{ {
var parent = folder.DisplayParentId; var parent = folder.DisplayParentId;
if (parent.Equals(Guid.Empty)) if (parent.Equals(default))
{ {
writer.WriteAttributeString("parentID", "0"); writer.WriteAttributeString("parentID", "0");
} }

View File

@ -174,7 +174,7 @@ namespace Emby.Dlna.PlayTo
await _sessionManager.OnPlaybackStart(newItemProgress).ConfigureAwait(false); await _sessionManager.OnPlaybackStart(newItemProgress).ConfigureAwait(false);
// Send a message to the DLNA device to notify what is the next track in the playlist. // Send a message to the DLNA device to notify what is the next track in the playlist.
var currentItemIndex = _playlist.FindIndex(item => item.StreamInfo.ItemId == streamInfo.ItemId); var currentItemIndex = _playlist.FindIndex(item => item.StreamInfo.ItemId.Equals(streamInfo.ItemId));
if (currentItemIndex >= 0) if (currentItemIndex >= 0)
{ {
_currentPlaylistIndex = currentItemIndex; _currentPlaylistIndex = currentItemIndex;
@ -349,7 +349,9 @@ namespace Emby.Dlna.PlayTo
{ {
_logger.LogDebug("{0} - Received PlayRequest: {1}", _session.DeviceName, command.PlayCommand); _logger.LogDebug("{0} - Received PlayRequest: {1}", _session.DeviceName, command.PlayCommand);
var user = command.ControllingUserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(command.ControllingUserId); var user = command.ControllingUserId.Equals(default)
? null :
_userManager.GetUserById(command.ControllingUserId);
var items = new List<BaseItem>(); var items = new List<BaseItem>();
foreach (var id in command.ItemIds) foreach (var id in command.ItemIds)
@ -392,7 +394,7 @@ namespace Emby.Dlna.PlayTo
_playlist.AddRange(playlist); _playlist.AddRange(playlist);
} }
if (!command.ControllingUserId.Equals(Guid.Empty)) if (!command.ControllingUserId.Equals(default))
{ {
_sessionManager.LogSessionActivity( _sessionManager.LogSessionActivity(
_session.Client, _session.Client,
@ -446,7 +448,9 @@ namespace Emby.Dlna.PlayTo
if (info.Item != null && !EnableClientSideSeek(info)) if (info.Item != null && !EnableClientSideSeek(info))
{ {
var user = !_session.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(_session.UserId) : null; var user = _session.UserId.Equals(default)
? null
: _userManager.GetUserById(_session.UserId);
var newItem = CreatePlaylistItem(info.Item, user, newPosition, info.MediaSourceId, info.AudioStreamIndex, info.SubtitleStreamIndex); var newItem = CreatePlaylistItem(info.Item, user, newPosition, info.MediaSourceId, info.AudioStreamIndex, info.SubtitleStreamIndex);
await _device.SetAvTransport(newItem.StreamUrl, GetDlnaHeaders(newItem), newItem.Didl, CancellationToken.None).ConfigureAwait(false); await _device.SetAvTransport(newItem.StreamUrl, GetDlnaHeaders(newItem), newItem.Didl, CancellationToken.None).ConfigureAwait(false);
@ -764,7 +768,9 @@ namespace Emby.Dlna.PlayTo
{ {
var newPosition = GetProgressPositionTicks(info) ?? 0; var newPosition = GetProgressPositionTicks(info) ?? 0;
var user = !_session.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(_session.UserId) : null; var user = _session.UserId.Equals(default)
? null
: _userManager.GetUserById(_session.UserId);
var newItem = CreatePlaylistItem(info.Item, user, newPosition, info.MediaSourceId, newIndex, info.SubtitleStreamIndex); var newItem = CreatePlaylistItem(info.Item, user, newPosition, info.MediaSourceId, newIndex, info.SubtitleStreamIndex);
await _device.SetAvTransport(newItem.StreamUrl, GetDlnaHeaders(newItem), newItem.Didl, CancellationToken.None).ConfigureAwait(false); await _device.SetAvTransport(newItem.StreamUrl, GetDlnaHeaders(newItem), newItem.Didl, CancellationToken.None).ConfigureAwait(false);
@ -793,7 +799,9 @@ namespace Emby.Dlna.PlayTo
{ {
var newPosition = GetProgressPositionTicks(info) ?? 0; var newPosition = GetProgressPositionTicks(info) ?? 0;
var user = !_session.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(_session.UserId) : null; var user = _session.UserId.Equals(default)
? null
: _userManager.GetUserById(_session.UserId);
var newItem = CreatePlaylistItem(info.Item, user, newPosition, info.MediaSourceId, info.AudioStreamIndex, newIndex); var newItem = CreatePlaylistItem(info.Item, user, newPosition, info.MediaSourceId, info.AudioStreamIndex, newIndex);
await _device.SetAvTransport(newItem.StreamUrl, GetDlnaHeaders(newItem), newItem.Didl, CancellationToken.None).ConfigureAwait(false); await _device.SetAvTransport(newItem.StreamUrl, GetDlnaHeaders(newItem), newItem.Didl, CancellationToken.None).ConfigureAwait(false);
@ -949,7 +957,7 @@ namespace Emby.Dlna.PlayTo
} }
} }
return Guid.Empty; return default;
} }
public static StreamParams ParseFromUrl(string url, ILibraryManager libraryManager, IMediaSourceManager mediaSourceManager) public static StreamParams ParseFromUrl(string url, ILibraryManager libraryManager, IMediaSourceManager mediaSourceManager)
@ -964,7 +972,7 @@ namespace Emby.Dlna.PlayTo
ItemId = GetItemId(url) ItemId = GetItemId(url)
}; };
if (request.ItemId.Equals(Guid.Empty)) if (request.ItemId.Equals(default))
{ {
return request; return request;
} }

View File

@ -112,7 +112,7 @@ namespace Emby.Notifications
var userId = e.Argument.UserId; var userId = e.Argument.UserId;
if (!userId.Equals(Guid.Empty) && !GetOptions().IsEnabledToMonitorUser(type, userId)) if (!userId.Equals(default) && !GetOptions().IsEnabledToMonitorUser(type, userId))
{ {
return; return;
} }

View File

@ -162,7 +162,7 @@ namespace Emby.Server.Implementations.Channels
/// <inheritdoc /> /// <inheritdoc />
public QueryResult<Channel> GetChannelsInternal(ChannelQuery query) public QueryResult<Channel> GetChannelsInternal(ChannelQuery query)
{ {
var user = query.UserId.Equals(Guid.Empty) var user = query.UserId.Equals(default)
? null ? null
: _userManager.GetUserById(query.UserId); : _userManager.GetUserById(query.UserId);
@ -274,7 +274,7 @@ namespace Emby.Server.Implementations.Channels
/// <inheritdoc /> /// <inheritdoc />
public QueryResult<BaseItemDto> GetChannels(ChannelQuery query) public QueryResult<BaseItemDto> GetChannels(ChannelQuery query)
{ {
var user = query.UserId.Equals(Guid.Empty) var user = query.UserId.Equals(default)
? null ? null
: _userManager.GetUserById(query.UserId); : _userManager.GetUserById(query.UserId);
@ -474,7 +474,7 @@ namespace Emby.Server.Implementations.Channels
item.ChannelId = id; item.ChannelId = id;
if (item.ParentId != parentFolderId) if (!item.ParentId.Equals(parentFolderId))
{ {
forceUpdate = true; forceUpdate = true;
} }
@ -715,7 +715,9 @@ namespace Emby.Server.Implementations.Channels
// Find the corresponding channel provider plugin // Find the corresponding channel provider plugin
var channelProvider = GetChannelProvider(channel); var channelProvider = GetChannelProvider(channel);
var parentItem = query.ParentId == Guid.Empty ? channel : _libraryManager.GetItemById(query.ParentId); var parentItem = query.ParentId.Equals(default)
? channel
: _libraryManager.GetItemById(query.ParentId);
var itemsResult = await GetChannelItems( var itemsResult = await GetChannelItems(
channelProvider, channelProvider,
@ -726,7 +728,7 @@ namespace Emby.Server.Implementations.Channels
cancellationToken) cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
if (query.ParentId == Guid.Empty) if (query.ParentId.Equals(default))
{ {
query.Parent = channel; query.Parent = channel;
} }

View File

@ -265,7 +265,7 @@ namespace Emby.Server.Implementations.Collections
{ {
var childItem = _libraryManager.GetItemById(guidId); var childItem = _libraryManager.GetItemById(guidId);
var child = collection.LinkedChildren.FirstOrDefault(i => (i.ItemId.HasValue && i.ItemId.Value == guidId) || (childItem != null && string.Equals(childItem.Path, i.Path, StringComparison.OrdinalIgnoreCase))); var child = collection.LinkedChildren.FirstOrDefault(i => (i.ItemId.HasValue && i.ItemId.Value.Equals(guidId)) || (childItem != null && string.Equals(childItem.Path, i.Path, StringComparison.OrdinalIgnoreCase)));
if (child == null) if (child == null)
{ {

View File

@ -1308,7 +1308,7 @@ namespace Emby.Server.Implementations.Dto
var allImages = parent.ImageInfos; var allImages = parent.ImageInfos;
if (logoLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Logo)) && dto.ParentLogoItemId == null) if (logoLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Logo)) && dto.ParentLogoItemId is null)
{ {
var image = allImages.FirstOrDefault(i => i.Type == ImageType.Logo); var image = allImages.FirstOrDefault(i => i.Type == ImageType.Logo);
@ -1319,7 +1319,7 @@ namespace Emby.Server.Implementations.Dto
} }
} }
if (artLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Art)) && dto.ParentArtItemId == null) if (artLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Art)) && dto.ParentArtItemId is null)
{ {
var image = allImages.FirstOrDefault(i => i.Type == ImageType.Art); var image = allImages.FirstOrDefault(i => i.Type == ImageType.Art);
@ -1330,7 +1330,7 @@ namespace Emby.Server.Implementations.Dto
} }
} }
if (thumbLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Thumb)) && (dto.ParentThumbItemId == null || parent is Series) && parent is not ICollectionFolder && parent is not UserView) if (thumbLimit > 0 && !(imageTags != null && imageTags.ContainsKey(ImageType.Thumb)) && (dto.ParentThumbItemId is null || parent is Series) && parent is not ICollectionFolder && parent is not UserView)
{ {
var image = allImages.FirstOrDefault(i => i.Type == ImageType.Thumb); var image = allImages.FirstOrDefault(i => i.Type == ImageType.Thumb);

View File

@ -326,7 +326,7 @@ namespace Emby.Server.Implementations.EntryPoints
{ {
var userIds = _sessionManager.Sessions var userIds = _sessionManager.Sessions
.Select(i => i.UserId) .Select(i => i.UserId)
.Where(i => !i.Equals(Guid.Empty)) .Where(i => !i.Equals(default))
.Distinct() .Distinct()
.ToArray(); .ToArray();

View File

@ -47,7 +47,9 @@ namespace Emby.Server.Implementations.HttpServer.Security
{ {
var session = await GetSession(requestContext).ConfigureAwait(false); var session = await GetSession(requestContext).ConfigureAwait(false);
return session.UserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(session.UserId); return session.UserId.Equals(default)
? null
: _userManager.GetUserById(session.UserId);
} }
public Task<User?> GetUser(object requestContext) public Task<User?> GetUser(object requestContext)

View File

@ -755,7 +755,7 @@ namespace Emby.Server.Implementations.Library
Path = path Path = path
}; };
if (folder.Id.Equals(Guid.Empty)) if (folder.Id.Equals(default))
{ {
if (string.IsNullOrEmpty(folder.Path)) if (string.IsNullOrEmpty(folder.Path))
{ {
@ -774,7 +774,7 @@ namespace Emby.Server.Implementations.Library
folder = dbItem; folder = dbItem;
} }
if (folder.ParentId != rootFolder.Id) if (!folder.ParentId.Equals(rootFolder.Id))
{ {
folder.ParentId = rootFolder.Id; folder.ParentId = rootFolder.Id;
folder.UpdateToRepositoryAsync(ItemUpdateType.MetadataImport, CancellationToken.None).GetAwaiter().GetResult(); folder.UpdateToRepositoryAsync(ItemUpdateType.MetadataImport, CancellationToken.None).GetAwaiter().GetResult();
@ -1252,7 +1252,7 @@ namespace Emby.Server.Implementations.Library
/// <exception cref="ArgumentNullException"><paramref name="id"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="id"/> is <c>null</c>.</exception>
public BaseItem GetItemById(Guid id) public BaseItem GetItemById(Guid id)
{ {
if (id == Guid.Empty) if (id.Equals(default))
{ {
throw new ArgumentException("Guid can't be empty", nameof(id)); throw new ArgumentException("Guid can't be empty", nameof(id));
} }
@ -1274,7 +1274,7 @@ namespace Emby.Server.Implementations.Library
public List<BaseItem> GetItemList(InternalItemsQuery query, bool allowExternalContent) public List<BaseItem> GetItemList(InternalItemsQuery query, bool allowExternalContent)
{ {
if (query.Recursive && query.ParentId != Guid.Empty) if (query.Recursive && !query.ParentId.Equals(default))
{ {
var parent = GetItemById(query.ParentId); var parent = GetItemById(query.ParentId);
if (parent != null) if (parent != null)
@ -1298,7 +1298,7 @@ namespace Emby.Server.Implementations.Library
public int GetCount(InternalItemsQuery query) public int GetCount(InternalItemsQuery query)
{ {
if (query.Recursive && !query.ParentId.Equals(Guid.Empty)) if (query.Recursive && !query.ParentId.Equals(default))
{ {
var parent = GetItemById(query.ParentId); var parent = GetItemById(query.ParentId);
if (parent != null) if (parent != null)
@ -1456,7 +1456,7 @@ namespace Emby.Server.Implementations.Library
public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query) public QueryResult<BaseItem> GetItemsResult(InternalItemsQuery query)
{ {
if (query.Recursive && !query.ParentId.Equals(Guid.Empty)) if (query.Recursive && !query.ParentId.Equals(default))
{ {
var parent = GetItemById(query.ParentId); var parent = GetItemById(query.ParentId);
if (parent != null) if (parent != null)
@ -1512,7 +1512,7 @@ namespace Emby.Server.Implementations.Library
private void AddUserToQuery(InternalItemsQuery query, User user, bool allowExternalContent = true) private void AddUserToQuery(InternalItemsQuery query, User user, bool allowExternalContent = true)
{ {
if (query.AncestorIds.Length == 0 && if (query.AncestorIds.Length == 0 &&
query.ParentId.Equals(Guid.Empty) && query.ParentId.Equals(default) &&
query.ChannelIds.Count == 0 && query.ChannelIds.Count == 0 &&
query.TopParentIds.Length == 0 && query.TopParentIds.Length == 0 &&
string.IsNullOrEmpty(query.AncestorWithPresentationUniqueKey) && string.IsNullOrEmpty(query.AncestorWithPresentationUniqueKey) &&
@ -1540,7 +1540,7 @@ namespace Emby.Server.Implementations.Library
} }
// Translate view into folders // Translate view into folders
if (!view.DisplayParentId.Equals(Guid.Empty)) if (!view.DisplayParentId.Equals(default))
{ {
var displayParent = GetItemById(view.DisplayParentId); var displayParent = GetItemById(view.DisplayParentId);
if (displayParent != null) if (displayParent != null)
@ -1551,7 +1551,7 @@ namespace Emby.Server.Implementations.Library
return Array.Empty<Guid>(); return Array.Empty<Guid>();
} }
if (!view.ParentId.Equals(Guid.Empty)) if (!view.ParentId.Equals(default))
{ {
var displayParent = GetItemById(view.ParentId); var displayParent = GetItemById(view.ParentId);
if (displayParent != null) if (displayParent != null)
@ -2153,7 +2153,7 @@ namespace Emby.Server.Implementations.Library
return null; return null;
} }
while (!item.ParentId.Equals(Guid.Empty)) while (!item.ParentId.Equals(default))
{ {
var parent = item.GetParent(); var parent = item.GetParent();
if (parent == null || parent is AggregateFolder) if (parent == null || parent is AggregateFolder)
@ -2231,7 +2231,9 @@ namespace Emby.Server.Implementations.Library
string viewType, string viewType,
string sortName) string sortName)
{ {
var parentIdString = parentId.Equals(Guid.Empty) ? null : parentId.ToString("N", CultureInfo.InvariantCulture); var parentIdString = parentId.Equals(default)
? null
: parentId.ToString("N", CultureInfo.InvariantCulture);
var idValues = "38_namedview_" + name + user.Id.ToString("N", CultureInfo.InvariantCulture) + (parentIdString ?? string.Empty) + (viewType ?? string.Empty); var idValues = "38_namedview_" + name + user.Id.ToString("N", CultureInfo.InvariantCulture) + (parentIdString ?? string.Empty) + (viewType ?? string.Empty);
var id = GetNewItemId(idValues, typeof(UserView)); var id = GetNewItemId(idValues, typeof(UserView));
@ -2265,7 +2267,7 @@ namespace Emby.Server.Implementations.Library
var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval; var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval;
if (!refresh && !item.DisplayParentId.Equals(Guid.Empty)) if (!refresh && !item.DisplayParentId.Equals(default))
{ {
var displayParent = GetItemById(item.DisplayParentId); var displayParent = GetItemById(item.DisplayParentId);
refresh = displayParent != null && displayParent.DateLastSaved > item.DateLastRefreshed; refresh = displayParent != null && displayParent.DateLastSaved > item.DateLastRefreshed;
@ -2332,7 +2334,7 @@ namespace Emby.Server.Implementations.Library
var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval; var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval;
if (!refresh && !item.DisplayParentId.Equals(Guid.Empty)) if (!refresh && !item.DisplayParentId.Equals(default))
{ {
var displayParent = GetItemById(item.DisplayParentId); var displayParent = GetItemById(item.DisplayParentId);
refresh = displayParent != null && displayParent.DateLastSaved > item.DateLastRefreshed; refresh = displayParent != null && displayParent.DateLastSaved > item.DateLastRefreshed;
@ -2365,7 +2367,9 @@ namespace Emby.Server.Implementations.Library
throw new ArgumentNullException(nameof(name)); throw new ArgumentNullException(nameof(name));
} }
var parentIdString = parentId.Equals(Guid.Empty) ? null : parentId.ToString("N", CultureInfo.InvariantCulture); var parentIdString = parentId.Equals(default)
? null
: parentId.ToString("N", CultureInfo.InvariantCulture);
var idValues = "37_namedview_" + name + (parentIdString ?? string.Empty) + (viewType ?? string.Empty); var idValues = "37_namedview_" + name + (parentIdString ?? string.Empty) + (viewType ?? string.Empty);
if (!string.IsNullOrEmpty(uniqueId)) if (!string.IsNullOrEmpty(uniqueId))
{ {
@ -2409,7 +2413,7 @@ namespace Emby.Server.Implementations.Library
var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval; var refresh = isNew || DateTime.UtcNow - item.DateLastRefreshed >= _viewRefreshInterval;
if (!refresh && !item.DisplayParentId.Equals(Guid.Empty)) if (!refresh && !item.DisplayParentId.Equals(default))
{ {
var displayParent = GetItemById(item.DisplayParentId); var displayParent = GetItemById(item.DisplayParentId);
refresh = displayParent != null && displayParent.DateLastSaved > item.DateLastRefreshed; refresh = displayParent != null && displayParent.DateLastSaved > item.DateLastRefreshed;

View File

@ -514,10 +514,10 @@ namespace Emby.Server.Implementations.Library
_logger.LogInformation("Live stream opened: {@MediaSource}", mediaSource); _logger.LogInformation("Live stream opened: {@MediaSource}", mediaSource);
var clone = JsonSerializer.Deserialize<MediaSourceInfo>(json, _jsonOptions); var clone = JsonSerializer.Deserialize<MediaSourceInfo>(json, _jsonOptions);
if (!request.UserId.Equals(Guid.Empty)) if (!request.UserId.Equals(default))
{ {
var user = _userManager.GetUserById(request.UserId); var user = _userManager.GetUserById(request.UserId);
var item = request.ItemId.Equals(Guid.Empty) var item = request.ItemId.Equals(default)
? null ? null
: _libraryManager.GetItemById(request.ItemId); : _libraryManager.GetItemById(request.ItemId);
SetDefaultAudioAndSubtitleStreamIndexes(item, clone, user); SetDefaultAudioAndSubtitleStreamIndexes(item, clone, user);

View File

@ -80,7 +80,7 @@ namespace Emby.Server.Implementations.Library
{ {
return Guid.Empty; return Guid.Empty;
} }
}).Where(i => !i.Equals(Guid.Empty)).ToArray(); }).Where(i => !i.Equals(default)).ToArray();
return GetInstantMixFromGenreIds(genreIds, user, dtoOptions); return GetInstantMixFromGenreIds(genreIds, user, dtoOptions);
} }

View File

@ -30,7 +30,7 @@ namespace Emby.Server.Implementations.Library
public QueryResult<SearchHintInfo> GetSearchHints(SearchQuery query) public QueryResult<SearchHintInfo> GetSearchHints(SearchQuery query)
{ {
User user = null; User user = null;
if (query.UserId != Guid.Empty) if (!query.UserId.Equals(default))
{ {
user = _userManager.GetUserById(query.UserId); user = _userManager.GetUserById(query.UserId);
} }
@ -168,10 +168,10 @@ namespace Emby.Server.Implementations.Library
{ {
Fields = new ItemFields[] Fields = new ItemFields[]
{ {
ItemFields.AirTime, ItemFields.AirTime,
ItemFields.DateCreated, ItemFields.DateCreated,
ItemFields.ChannelInfo, ItemFields.ChannelInfo,
ItemFields.ParentId ItemFields.ParentId
} }
} }
}; };
@ -180,12 +180,12 @@ namespace Emby.Server.Implementations.Library
if (searchQuery.IncludeItemTypes.Length == 1 && searchQuery.IncludeItemTypes[0] == BaseItemKind.MusicArtist) if (searchQuery.IncludeItemTypes.Length == 1 && searchQuery.IncludeItemTypes[0] == BaseItemKind.MusicArtist)
{ {
if (!searchQuery.ParentId.Equals(Guid.Empty)) if (!searchQuery.ParentId.Equals(default))
{ {
searchQuery.AncestorIds = new[] { searchQuery.ParentId }; searchQuery.AncestorIds = new[] { searchQuery.ParentId };
searchQuery.ParentId = Guid.Empty;
} }
searchQuery.ParentId = Guid.Empty;
searchQuery.IncludeItemsByName = true; searchQuery.IncludeItemsByName = true;
searchQuery.IncludeItemTypes = Array.Empty<BaseItemKind>(); searchQuery.IncludeItemTypes = Array.Empty<BaseItemKind>();
mediaItems = _libraryManager.GetAllArtists(searchQuery).Items.Select(i => i.Item).ToList(); mediaItems = _libraryManager.GetAllArtists(searchQuery).Items.Select(i => i.Item).ToList();

View File

@ -142,7 +142,7 @@ namespace Emby.Server.Implementations.Library
if (index == -1 if (index == -1
&& i is UserView view && i is UserView view
&& view.DisplayParentId != Guid.Empty) && !view.DisplayParentId.Equals(default))
{ {
index = Array.IndexOf(orders, view.DisplayParentId); index = Array.IndexOf(orders, view.DisplayParentId);
} }
@ -214,7 +214,7 @@ namespace Emby.Server.Implementations.Library
} }
else else
{ {
var current = list.FirstOrDefault(i => i.Item1 != null && i.Item1.Id == container.Id); var current = list.FirstOrDefault(i => i.Item1 != null && i.Item1.Id.Equals(container.Id));
if (current != null) if (current != null)
{ {
@ -244,7 +244,7 @@ namespace Emby.Server.Implementations.Library
var parents = new List<BaseItem>(); var parents = new List<BaseItem>();
if (!parentId.Equals(Guid.Empty)) if (!parentId.Equals(default))
{ {
var parentItem = _libraryManager.GetItemById(parentId); var parentItem = _libraryManager.GetItemById(parentId);
if (parentItem is Channel) if (parentItem is Channel)

View File

@ -2024,7 +2024,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
await writer.WriteElementStringAsync(null, "genre", null, genre).ConfigureAwait(false); await writer.WriteElementStringAsync(null, "genre", null, genre).ConfigureAwait(false);
} }
var people = item.Id.Equals(Guid.Empty) ? new List<PersonInfo>() : _libraryManager.GetPeople(item); var people = item.Id.Equals(default) ? new List<PersonInfo>() : _libraryManager.GetPeople(item);
var directors = people var directors = people
.Where(i => IsPersonType(i, PersonType.Director)) .Where(i => IsPersonType(i, PersonType.Director))
@ -2382,7 +2382,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{ {
string channelId = seriesTimer.RecordAnyChannel ? null : seriesTimer.ChannelId; string channelId = seriesTimer.RecordAnyChannel ? null : seriesTimer.ChannelId;
if (string.IsNullOrWhiteSpace(channelId) && !parent.ChannelId.Equals(Guid.Empty)) if (string.IsNullOrWhiteSpace(channelId) && !parent.ChannelId.Equals(default))
{ {
if (!tempChannelCache.TryGetValue(parent.ChannelId, out LiveTvChannel channel)) if (!tempChannelCache.TryGetValue(parent.ChannelId, out LiveTvChannel channel))
{ {
@ -2441,7 +2441,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{ {
string channelId = null; string channelId = null;
if (!programInfo.ChannelId.Equals(Guid.Empty)) if (!programInfo.ChannelId.Equals(default))
{ {
if (!tempChannelCache.TryGetValue(programInfo.ChannelId, out LiveTvChannel channel)) if (!tempChannelCache.TryGetValue(programInfo.ChannelId, out LiveTvChannel channel))
{ {

View File

@ -456,7 +456,7 @@ namespace Emby.Server.Implementations.LiveTv
info.Id = timer.ExternalId; info.Id = timer.ExternalId;
} }
if (!dto.ChannelId.Equals(Guid.Empty) && string.IsNullOrEmpty(info.ChannelId)) if (!dto.ChannelId.Equals(default) && string.IsNullOrEmpty(info.ChannelId))
{ {
var channel = _libraryManager.GetItemById(dto.ChannelId); var channel = _libraryManager.GetItemById(dto.ChannelId);
@ -522,7 +522,7 @@ namespace Emby.Server.Implementations.LiveTv
info.Id = timer.ExternalId; info.Id = timer.ExternalId;
} }
if (!dto.ChannelId.Equals(Guid.Empty) && string.IsNullOrEmpty(info.ChannelId)) if (!dto.ChannelId.Equals(default) && string.IsNullOrEmpty(info.ChannelId))
{ {
var channel = _libraryManager.GetItemById(dto.ChannelId); var channel = _libraryManager.GetItemById(dto.ChannelId);

View File

@ -176,7 +176,9 @@ namespace Emby.Server.Implementations.LiveTv
public QueryResult<BaseItem> GetInternalChannels(LiveTvChannelQuery query, DtoOptions dtoOptions, CancellationToken cancellationToken) public QueryResult<BaseItem> GetInternalChannels(LiveTvChannelQuery query, DtoOptions dtoOptions, CancellationToken cancellationToken)
{ {
var user = query.UserId == Guid.Empty ? null : _userManager.GetUserById(query.UserId); var user = query.UserId.Equals(default)
? null
: _userManager.GetUserById(query.UserId);
var topFolder = GetInternalLiveTvFolder(cancellationToken); var topFolder = GetInternalLiveTvFolder(cancellationToken);
@ -1268,7 +1270,7 @@ namespace Emby.Server.Implementations.LiveTv
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
if (itemId.Equals(Guid.Empty)) if (itemId.Equals(default))
{ {
// Somehow some invalid data got into the db. It probably predates the boundary checking // Somehow some invalid data got into the db. It probably predates the boundary checking
continue; continue;
@ -1528,7 +1530,9 @@ namespace Emby.Server.Implementations.LiveTv
public QueryResult<BaseItemDto> GetRecordings(RecordingQuery query, DtoOptions options) public QueryResult<BaseItemDto> GetRecordings(RecordingQuery query, DtoOptions options)
{ {
var user = query.UserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(query.UserId); var user = query.UserId.Equals(default)
? null
: _userManager.GetUserById(query.UserId);
RemoveFields(options); RemoveFields(options);
@ -1587,7 +1591,7 @@ namespace Emby.Server.Implementations.LiveTv
if (!string.IsNullOrEmpty(query.ChannelId)) if (!string.IsNullOrEmpty(query.ChannelId))
{ {
var guid = new Guid(query.ChannelId); var guid = new Guid(query.ChannelId);
timers = timers.Where(i => guid == _tvDtoService.GetInternalChannelId(i.Item2.Name, i.Item1.ChannelId)); timers = timers.Where(i => _tvDtoService.GetInternalChannelId(i.Item2.Name, i.Item1.ChannelId).Equals(guid));
} }
if (!string.IsNullOrEmpty(query.SeriesTimerId)) if (!string.IsNullOrEmpty(query.SeriesTimerId))
@ -1595,7 +1599,7 @@ namespace Emby.Server.Implementations.LiveTv
var guid = new Guid(query.SeriesTimerId); var guid = new Guid(query.SeriesTimerId);
timers = timers timers = timers
.Where(i => _tvDtoService.GetInternalSeriesTimerId(i.Item1.SeriesTimerId) == guid); .Where(i => _tvDtoService.GetInternalSeriesTimerId(i.Item1.SeriesTimerId).Equals(guid));
} }
if (!string.IsNullOrEmpty(query.Id)) if (!string.IsNullOrEmpty(query.Id))
@ -1657,7 +1661,7 @@ namespace Emby.Server.Implementations.LiveTv
if (!string.IsNullOrEmpty(query.ChannelId)) if (!string.IsNullOrEmpty(query.ChannelId))
{ {
var guid = new Guid(query.ChannelId); var guid = new Guid(query.ChannelId);
timers = timers.Where(i => guid == _tvDtoService.GetInternalChannelId(i.Item2.Name, i.Item1.ChannelId)); timers = timers.Where(i => _tvDtoService.GetInternalChannelId(i.Item2.Name, i.Item1.ChannelId).Equals(guid));
} }
if (!string.IsNullOrEmpty(query.SeriesTimerId)) if (!string.IsNullOrEmpty(query.SeriesTimerId))
@ -1665,7 +1669,7 @@ namespace Emby.Server.Implementations.LiveTv
var guid = new Guid(query.SeriesTimerId); var guid = new Guid(query.SeriesTimerId);
timers = timers timers = timers
.Where(i => _tvDtoService.GetInternalSeriesTimerId(i.Item1.SeriesTimerId) == guid); .Where(i => _tvDtoService.GetInternalSeriesTimerId(i.Item1.SeriesTimerId).Equals(guid));
} }
if (!string.IsNullOrEmpty(query.Id)) if (!string.IsNullOrEmpty(query.Id))

View File

@ -139,7 +139,9 @@ namespace Emby.Server.Implementations.Playlists
{ {
new Share new Share
{ {
UserId = options.UserId.Equals(Guid.Empty) ? null : options.UserId.ToString("N", CultureInfo.InvariantCulture), UserId = options.UserId.Equals(default)
? null
: options.UserId.ToString("N", CultureInfo.InvariantCulture),
CanEdit = true CanEdit = true
} }
} }
@ -188,7 +190,7 @@ namespace Emby.Server.Implementations.Playlists
public Task AddToPlaylistAsync(Guid playlistId, IReadOnlyCollection<Guid> itemIds, Guid userId) public Task AddToPlaylistAsync(Guid playlistId, IReadOnlyCollection<Guid> itemIds, Guid userId)
{ {
var user = userId.Equals(Guid.Empty) ? null : _userManager.GetUserById(userId); var user = userId.Equals(default) ? null : _userManager.GetUserById(userId);
return AddToPlaylistInternal(playlistId, itemIds, user, new DtoOptions(false) return AddToPlaylistInternal(playlistId, itemIds, user, new DtoOptions(false)
{ {

View File

@ -483,7 +483,7 @@ namespace Emby.Server.Implementations.Plugins
var pluginStr = instance.Version.ToString(); var pluginStr = instance.Version.ToString();
bool changed = false; bool changed = false;
if (string.Equals(manifest.Version, pluginStr, StringComparison.Ordinal) if (string.Equals(manifest.Version, pluginStr, StringComparison.Ordinal)
|| manifest.Id != instance.Id) || !manifest.Id.Equals(instance.Id))
{ {
// If a plugin without a manifest failed to load due to an external issue (eg config), // If a plugin without a manifest failed to load due to an external issue (eg config),
// this updates the manifest to the actual plugin values. // this updates the manifest to the actual plugin values.

View File

@ -373,7 +373,7 @@ namespace Emby.Server.Implementations.Session
info.MediaSourceId = info.ItemId.ToString("N", CultureInfo.InvariantCulture); info.MediaSourceId = info.ItemId.ToString("N", CultureInfo.InvariantCulture);
} }
if (!info.ItemId.Equals(Guid.Empty) && info.Item == null && libraryItem != null) if (!info.ItemId.Equals(default) && info.Item == null && libraryItem != null)
{ {
var current = session.NowPlayingItem; var current = session.NowPlayingItem;
@ -553,22 +553,24 @@ namespace Emby.Server.Implementations.Session
{ {
var users = new List<User>(); var users = new List<User>();
if (session.UserId != Guid.Empty) if (session.UserId.Equals(default))
{ {
var user = _userManager.GetUserById(session.UserId); return users;
if (user == null)
{
throw new InvalidOperationException("User not found");
}
users.Add(user);
users.AddRange(session.AdditionalUsers
.Select(i => _userManager.GetUserById(i.UserId))
.Where(i => i != null));
} }
var user = _userManager.GetUserById(session.UserId);
if (user == null)
{
throw new InvalidOperationException("User not found");
}
users.Add(user);
users.AddRange(session.AdditionalUsers
.Select(i => _userManager.GetUserById(i.UserId))
.Where(i => i != null));
return users; return users;
} }
@ -660,7 +662,7 @@ namespace Emby.Server.Implementations.Session
var session = GetSession(info.SessionId); var session = GetSession(info.SessionId);
var libraryItem = info.ItemId == Guid.Empty var libraryItem = info.ItemId.Equals(default)
? null ? null
: GetNowPlayingItem(session, info.ItemId); : GetNowPlayingItem(session, info.ItemId);
@ -755,7 +757,7 @@ namespace Emby.Server.Implementations.Session
var session = GetSession(info.SessionId); var session = GetSession(info.SessionId);
var libraryItem = info.ItemId.Equals(Guid.Empty) var libraryItem = info.ItemId.Equals(default)
? null ? null
: GetNowPlayingItem(session, info.ItemId); : GetNowPlayingItem(session, info.ItemId);
@ -892,7 +894,7 @@ namespace Emby.Server.Implementations.Session
session.StopAutomaticProgress(); session.StopAutomaticProgress();
var libraryItem = info.ItemId.Equals(Guid.Empty) var libraryItem = info.ItemId.Equals(default)
? null ? null
: GetNowPlayingItem(session, info.ItemId); : GetNowPlayingItem(session, info.ItemId);
@ -902,7 +904,7 @@ namespace Emby.Server.Implementations.Session
info.MediaSourceId = info.ItemId.ToString("N", CultureInfo.InvariantCulture); info.MediaSourceId = info.ItemId.ToString("N", CultureInfo.InvariantCulture);
} }
if (!info.ItemId.Equals(Guid.Empty) && info.Item == null && libraryItem != null) if (!info.ItemId.Equals(default) && info.Item == null && libraryItem != null)
{ {
var current = session.NowPlayingItem; var current = session.NowPlayingItem;
@ -1122,7 +1124,7 @@ namespace Emby.Server.Implementations.Session
var session = GetSessionToRemoteControl(sessionId); var session = GetSessionToRemoteControl(sessionId);
var user = session.UserId == Guid.Empty ? null : _userManager.GetUserById(session.UserId); var user = session.UserId.Equals(default) ? null : _userManager.GetUserById(session.UserId);
List<BaseItem> items; List<BaseItem> items;
@ -1177,7 +1179,7 @@ namespace Emby.Server.Implementations.Session
EnableImages = false EnableImages = false
}) })
.Where(i => !i.IsVirtualItem) .Where(i => !i.IsVirtualItem)
.SkipWhile(i => i.Id != episode.Id) .SkipWhile(i => !i.Id.Equals(episode.Id))
.ToList(); .ToList();
if (episodes.Count > 0) if (episodes.Count > 0)
@ -1191,7 +1193,7 @@ namespace Emby.Server.Implementations.Session
{ {
var controllingSession = GetSession(controllingSessionId); var controllingSession = GetSession(controllingSessionId);
AssertCanControl(session, controllingSession); AssertCanControl(session, controllingSession);
if (!controllingSession.UserId.Equals(Guid.Empty)) if (!controllingSession.UserId.Equals(default))
{ {
command.ControllingUserId = controllingSession.UserId; command.ControllingUserId = controllingSession.UserId;
} }
@ -1310,7 +1312,7 @@ namespace Emby.Server.Implementations.Session
{ {
var controllingSession = GetSession(controllingSessionId); var controllingSession = GetSession(controllingSessionId);
AssertCanControl(session, controllingSession); AssertCanControl(session, controllingSession);
if (!controllingSession.UserId.Equals(Guid.Empty)) if (!controllingSession.UserId.Equals(default))
{ {
command.ControllingUserId = controllingSession.UserId.ToString("N", CultureInfo.InvariantCulture); command.ControllingUserId = controllingSession.UserId.ToString("N", CultureInfo.InvariantCulture);
} }
@ -1383,12 +1385,12 @@ namespace Emby.Server.Implementations.Session
var session = GetSession(sessionId); var session = GetSession(sessionId);
if (session.UserId == userId) if (session.UserId.Equals(userId))
{ {
throw new ArgumentException("The requested user is already the primary user of the session."); throw new ArgumentException("The requested user is already the primary user of the session.");
} }
if (session.AdditionalUsers.All(i => i.UserId != userId)) if (session.AdditionalUsers.All(i => !i.UserId.Equals(userId)))
{ {
var user = _userManager.GetUserById(userId); var user = _userManager.GetUserById(userId);
@ -1458,7 +1460,7 @@ namespace Emby.Server.Implementations.Session
CheckDisposed(); CheckDisposed();
User user = null; User user = null;
if (request.UserId != Guid.Empty) if (!request.UserId.Equals(default))
{ {
user = _userManager.GetUserById(request.UserId); user = _userManager.GetUserById(request.UserId);
} }
@ -1787,7 +1789,7 @@ namespace Emby.Server.Implementations.Session
throw new ArgumentNullException(nameof(info)); throw new ArgumentNullException(nameof(info));
} }
var user = info.UserId == Guid.Empty var user = info.UserId.Equals(default)
? null ? null
: _userManager.GetUserById(info.UserId); : _userManager.GetUserById(info.UserId);

View File

@ -553,7 +553,7 @@ namespace Emby.Server.Implementations.SyncPlay
if (playingItemRemoved) if (playingItemRemoved)
{ {
var itemId = PlayQueue.GetPlayingItemId(); var itemId = PlayQueue.GetPlayingItemId();
if (!itemId.Equals(Guid.Empty)) if (!itemId.Equals(default))
{ {
var item = _libraryManager.GetItemById(itemId); var item = _libraryManager.GetItemById(itemId);
RunTimeTicks = item.RunTimeTicks ?? 0; RunTimeTicks = item.RunTimeTicks ?? 0;

View File

@ -271,7 +271,7 @@ namespace Emby.Server.Implementations.TV
.Cast<Episode>(); .Cast<Episode>();
if (lastWatchedEpisode != null) if (lastWatchedEpisode != null)
{ {
sortedConsideredEpisodes = sortedConsideredEpisodes.SkipWhile(episode => episode.Id != lastWatchedEpisode.Id).Skip(1); sortedConsideredEpisodes = sortedConsideredEpisodes.SkipWhile(episode => !episode.Id.Equals(lastWatchedEpisode.Id)).Skip(1);
} }
nextEpisode = sortedConsideredEpisodes.FirstOrDefault(); nextEpisode = sortedConsideredEpisodes.FirstOrDefault();

View File

@ -227,9 +227,9 @@ namespace Emby.Server.Implementations.Updates
availablePackages = availablePackages.Where(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); availablePackages = availablePackages.Where(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
} }
if (id != default) if (!id.Equals(default))
{ {
availablePackages = availablePackages.Where(x => x.Id == id); availablePackages = availablePackages.Where(x => x.Id.Equals(id));
} }
if (specificVersion != null) if (specificVersion != null)
@ -399,7 +399,7 @@ namespace Emby.Server.Implementations.Updates
{ {
lock (_currentInstallationsLock) lock (_currentInstallationsLock)
{ {
var install = _currentInstallations.Find(x => x.Info.Id == id); var install = _currentInstallations.Find(x => x.Info.Id.Equals(id));
if (install == default((InstallationInfo, CancellationTokenSource))) if (install == default((InstallationInfo, CancellationTokenSource)))
{ {
return false; return false;
@ -498,7 +498,7 @@ namespace Emby.Server.Implementations.Updates
var compatibleVersions = GetCompatibleVersions(pluginCatalog, plugin.Name, plugin.Id, minVersion: plugin.Version); var compatibleVersions = GetCompatibleVersions(pluginCatalog, plugin.Name, plugin.Id, minVersion: plugin.Version);
var version = compatibleVersions.FirstOrDefault(y => y.Version > plugin.Version); var version = compatibleVersions.FirstOrDefault(y => y.Version > plugin.Version);
if (version != null && CompletedInstallations.All(x => x.Id != version.Id)) if (version != null && CompletedInstallations.All(x => !x.Id.Equals(version.Id)))
{ {
yield return version; yield return version;
} }

View File

@ -126,7 +126,7 @@ namespace Jellyfin.Api.Controllers
User? user = null; User? user = null;
BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId); BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId);
if (userId.HasValue && !userId.Equals(Guid.Empty)) if (userId.HasValue && !userId.Equals(default))
{ {
user = _userManager.GetUserById(userId.Value); user = _userManager.GetUserById(userId.Value);
} }
@ -329,7 +329,7 @@ namespace Jellyfin.Api.Controllers
User? user = null; User? user = null;
BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId); BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId);
if (userId.HasValue && !userId.Equals(Guid.Empty)) if (userId.HasValue && !userId.Equals(default))
{ {
user = _userManager.GetUserById(userId.Value); user = _userManager.GetUserById(userId.Value);
} }
@ -467,7 +467,7 @@ namespace Jellyfin.Api.Controllers
var item = _libraryManager.GetArtist(name, dtoOptions); var item = _libraryManager.GetArtist(name, dtoOptions);
if (userId.HasValue && !userId.Equals(Guid.Empty)) if (userId.HasValue && !userId.Value.Equals(default))
{ {
var user = _userManager.GetUserById(userId.Value); var user = _userManager.GetUserById(userId.Value);

View File

@ -125,9 +125,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] sortBy, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] sortBy,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var query = new InternalItemsQuery(user) var query = new InternalItemsQuery(user)
{ {
@ -199,9 +199,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] channelIds) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] Guid[] channelIds)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var query = new InternalItemsQuery(user) var query = new InternalItemsQuery(user)
{ {

View File

@ -52,9 +52,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaTypes)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
BaseItem? item = null; BaseItem? item = null;
if (includeItemTypes.Length != 1 if (includeItemTypes.Length != 1
@ -144,9 +144,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery] bool? isSeries, [FromQuery] bool? isSeries,
[FromQuery] bool? recursive) [FromQuery] bool? recursive)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
BaseItem? parentItem = null; BaseItem? parentItem = null;
if (includeItemTypes.Length == 1 if (includeItemTypes.Length == 1

View File

@ -95,7 +95,9 @@ namespace Jellyfin.Api.Controllers
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, false, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, false, imageTypeLimit, enableImageTypes);
User? user = userId.HasValue && userId != Guid.Empty ? _userManager.GetUserById(userId.Value) : null; User? user = userId is null || userId.Value.Equals(default)
? null
: _userManager.GetUserById(userId.Value);
var parentItem = _libraryManager.GetParentItem(parentId, userId); var parentItem = _libraryManager.GetParentItem(parentId, userId);
@ -157,29 +159,26 @@ namespace Jellyfin.Api.Controllers
var dtoOptions = new DtoOptions() var dtoOptions = new DtoOptions()
.AddClientFields(Request); .AddClientFields(Request);
Genre item = new Genre(); Genre? item;
if (genreName.IndexOf(BaseItem.SlugChar, StringComparison.OrdinalIgnoreCase) != -1) if (genreName.Contains(BaseItem.SlugChar, StringComparison.OrdinalIgnoreCase))
{ {
var result = GetItemFromSlugName<Genre>(_libraryManager, genreName, dtoOptions, BaseItemKind.Genre); item = GetItemFromSlugName<Genre>(_libraryManager, genreName, dtoOptions, BaseItemKind.Genre);
if (result != null)
{
item = result;
}
} }
else else
{ {
item = _libraryManager.GetGenre(genreName); item = _libraryManager.GetGenre(genreName);
} }
if (userId.HasValue && !userId.Equals(Guid.Empty)) item ??= new Genre();
{
var user = _userManager.GetUserById(userId.Value);
return _dtoService.GetBaseItemDto(item, dtoOptions, user); if (userId is null || userId.Value.Equals(default))
{
return _dtoService.GetBaseItemDto(item, dtoOptions);
} }
return _dtoService.GetBaseItemDto(item, dtoOptions); var user = _userManager.GetUserById(userId.Value);
return _dtoService.GetBaseItemDto(item, dtoOptions, user);
} }
private T? GetItemFromSlugName<T>(ILibraryManager libraryManager, string name, DtoOptions dtoOptions, BaseItemKind baseItemKind) private T? GetItemFromSlugName<T>(ILibraryManager libraryManager, string name, DtoOptions dtoOptions, BaseItemKind baseItemKind)

View File

@ -75,9 +75,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
{ {
var item = _libraryManager.GetItemById(id); var item = _libraryManager.GetItemById(id);
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var dtoOptions = new DtoOptions { Fields = fields } var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
@ -111,9 +111,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
{ {
var album = _libraryManager.GetItemById(id); var album = _libraryManager.GetItemById(id);
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var dtoOptions = new DtoOptions { Fields = fields } var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
@ -147,9 +147,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
{ {
var playlist = (Playlist)_libraryManager.GetItemById(id); var playlist = (Playlist)_libraryManager.GetItemById(id);
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var dtoOptions = new DtoOptions { Fields = fields } var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
@ -182,9 +182,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery] int? imageTypeLimit, [FromQuery] int? imageTypeLimit,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var dtoOptions = new DtoOptions { Fields = fields } var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
@ -218,9 +218,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
{ {
var item = _libraryManager.GetItemById(id); var item = _libraryManager.GetItemById(id);
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var dtoOptions = new DtoOptions { Fields = fields } var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
@ -254,9 +254,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
{ {
var item = _libraryManager.GetItemById(id); var item = _libraryManager.GetItemById(id);
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var dtoOptions = new DtoOptions { Fields = fields } var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
@ -327,9 +327,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
{ {
var item = _libraryManager.GetItemById(id); var item = _libraryManager.GetItemById(id);
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var dtoOptions = new DtoOptions { Fields = fields } var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);

View File

@ -228,7 +228,7 @@ namespace Jellyfin.Api.Controllers
[FromQuery] bool enableTotalRecordCount = true, [FromQuery] bool enableTotalRecordCount = true,
[FromQuery] bool? enableImages = true) [FromQuery] bool? enableImages = true)
{ {
var user = userId == Guid.Empty ? null : _userManager.GetUserById(userId); var user = userId.Equals(default) ? null : _userManager.GetUserById(userId);
var dtoOptions = new DtoOptions { Fields = fields } var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
@ -799,7 +799,7 @@ namespace Jellyfin.Api.Controllers
var ancestorIds = Array.Empty<Guid>(); var ancestorIds = Array.Empty<Guid>();
var excludeFolderIds = user.GetPreferenceValues<Guid>(PreferenceKind.LatestItemExcludes); var excludeFolderIds = user.GetPreferenceValues<Guid>(PreferenceKind.LatestItemExcludes);
if (parentIdGuid.Equals(Guid.Empty) && excludeFolderIds.Length > 0) if (parentIdGuid.Equals(default) && excludeFolderIds.Length > 0)
{ {
ancestorIds = _libraryManager.GetUserRootFolder().GetChildren(user, true) ancestorIds = _libraryManager.GetUserRootFolder().GetChildren(user, true)
.Where(i => i is Folder) .Where(i => i is Folder)
@ -812,7 +812,7 @@ namespace Jellyfin.Api.Controllers
if (excludeActiveSessions) if (excludeActiveSessions)
{ {
excludeItemIds = _sessionManager.Sessions excludeItemIds = _sessionManager.Sessions
.Where(s => s.UserId == userId && s.NowPlayingItem != null) .Where(s => s.UserId.Equals(userId) && s.NowPlayingItem != null)
.Select(s => s.NowPlayingItem.Id) .Select(s => s.NowPlayingItem.Id)
.ToArray(); .ToArray();
} }

View File

@ -149,14 +149,14 @@ namespace Jellyfin.Api.Controllers
[FromQuery] Guid? userId, [FromQuery] Guid? userId,
[FromQuery] bool inheritFromParent = false) [FromQuery] bool inheritFromParent = false)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var item = itemId.Equals(Guid.Empty) var item = itemId.Equals(default)
? (!userId.Equals(Guid.Empty) ? (userId is null || userId.Value.Equals(default)
? _libraryManager.GetUserRootFolder() ? _libraryManager.RootFolder
: _libraryManager.RootFolder) : _libraryManager.GetUserRootFolder())
: _libraryManager.GetItemById(itemId); : _libraryManager.GetItemById(itemId);
if (item == null) if (item == null)
@ -215,14 +215,14 @@ namespace Jellyfin.Api.Controllers
[FromQuery] Guid? userId, [FromQuery] Guid? userId,
[FromQuery] bool inheritFromParent = false) [FromQuery] bool inheritFromParent = false)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var item = itemId.Equals(Guid.Empty) var item = itemId.Equals(default)
? (!userId.Equals(Guid.Empty) ? (userId is null || userId.Value.Equals(default)
? _libraryManager.GetUserRootFolder() ? _libraryManager.RootFolder
: _libraryManager.RootFolder) : _libraryManager.GetUserRootFolder())
: _libraryManager.GetItemById(itemId); : _libraryManager.GetItemById(itemId);
if (item == null) if (item == null)
@ -407,9 +407,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery] Guid? userId, [FromQuery] Guid? userId,
[FromQuery] bool? isFavorite) [FromQuery] bool? isFavorite)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var counts = new ItemCounts var counts = new ItemCounts
{ {
@ -449,9 +449,9 @@ namespace Jellyfin.Api.Controllers
var baseItemDtos = new List<BaseItemDto>(); var baseItemDtos = new List<BaseItemDto>();
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var dtoOptions = new DtoOptions().AddClientFields(Request); var dtoOptions = new DtoOptions().AddClientFields(Request);
BaseItem? parent = item.GetParent(); BaseItem? parent = item.GetParent();
@ -689,10 +689,10 @@ namespace Jellyfin.Api.Controllers
[FromQuery] int? limit, [FromQuery] int? limit,
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields) [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields)
{ {
var item = itemId.Equals(Guid.Empty) var item = itemId.Equals(default)
? (!userId.Equals(Guid.Empty) ? (userId is null || userId.Value.Equals(default)
? _libraryManager.GetUserRootFolder() ? _libraryManager.RootFolder
: _libraryManager.RootFolder) : _libraryManager.GetUserRootFolder())
: _libraryManager.GetItemById(itemId); : _libraryManager.GetItemById(itemId);
if (item is Episode || (item is IItemByName && item is not MusicArtist)) if (item is Episode || (item is IItemByName && item is not MusicArtist))
@ -700,9 +700,9 @@ namespace Jellyfin.Api.Controllers
return new QueryResult<BaseItemDto>(); return new QueryResult<BaseItemDto>();
} }
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var dtoOptions = new DtoOptions { Fields = fields } var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(Request); .AddClientFields(Request);

View File

@ -180,9 +180,9 @@ namespace Jellyfin.Api.Controllers
dtoOptions, dtoOptions,
CancellationToken.None); CancellationToken.None);
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var fieldsList = dtoOptions.Fields.ToList(); var fieldsList = dtoOptions.Fields.ToList();
fieldsList.Remove(ItemFields.CanDelete); fieldsList.Remove(ItemFields.CanDelete);
@ -211,10 +211,10 @@ namespace Jellyfin.Api.Controllers
[Authorize(Policy = Policies.DefaultAuthorization)] [Authorize(Policy = Policies.DefaultAuthorization)]
public ActionResult<BaseItemDto> GetChannel([FromRoute, Required] Guid channelId, [FromQuery] Guid? userId) public ActionResult<BaseItemDto> GetChannel([FromRoute, Required] Guid channelId, [FromQuery] Guid? userId)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var item = channelId.Equals(Guid.Empty) var item = channelId.Equals(default)
? _libraryManager.GetUserRootFolder() ? _libraryManager.GetUserRootFolder()
: _libraryManager.GetItemById(channelId); : _libraryManager.GetItemById(channelId);
@ -382,9 +382,9 @@ namespace Jellyfin.Api.Controllers
[Authorize(Policy = Policies.DefaultAuthorization)] [Authorize(Policy = Policies.DefaultAuthorization)]
public ActionResult<QueryResult<BaseItemDto>> GetRecordingFolders([FromQuery] Guid? userId) public ActionResult<QueryResult<BaseItemDto>> GetRecordingFolders([FromQuery] Guid? userId)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var folders = _liveTvManager.GetRecordingFolders(user); var folders = _liveTvManager.GetRecordingFolders(user);
var returnArray = _dtoService.GetBaseItemDtos(folders, new DtoOptions(), user); var returnArray = _dtoService.GetBaseItemDtos(folders, new DtoOptions(), user);
@ -404,10 +404,10 @@ namespace Jellyfin.Api.Controllers
[Authorize(Policy = Policies.DefaultAuthorization)] [Authorize(Policy = Policies.DefaultAuthorization)]
public ActionResult<BaseItemDto> GetRecording([FromRoute, Required] Guid recordingId, [FromQuery] Guid? userId) public ActionResult<BaseItemDto> GetRecording([FromRoute, Required] Guid recordingId, [FromQuery] Guid? userId)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var item = recordingId.Equals(Guid.Empty) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(recordingId); var item = recordingId.Equals(default) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(recordingId);
var dtoOptions = new DtoOptions() var dtoOptions = new DtoOptions()
.AddClientFields(Request); .AddClientFields(Request);
@ -561,9 +561,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
[FromQuery] bool enableTotalRecordCount = true) [FromQuery] bool enableTotalRecordCount = true)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var query = new InternalItemsQuery(user) var query = new InternalItemsQuery(user)
{ {
@ -588,7 +588,7 @@ namespace Jellyfin.Api.Controllers
GenreIds = genreIds GenreIds = genreIds
}; };
if (librarySeriesId != null && !librarySeriesId.Equals(Guid.Empty)) if (librarySeriesId.HasValue && !librarySeriesId.Equals(default))
{ {
query.IsSeries = true; query.IsSeries = true;
@ -617,7 +617,7 @@ namespace Jellyfin.Api.Controllers
[Authorize(Policy = Policies.DefaultAuthorization)] [Authorize(Policy = Policies.DefaultAuthorization)]
public async Task<ActionResult<QueryResult<BaseItemDto>>> GetPrograms([FromBody] GetProgramsDto body) public async Task<ActionResult<QueryResult<BaseItemDto>>> GetPrograms([FromBody] GetProgramsDto body)
{ {
var user = body.UserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(body.UserId); var user = body.UserId.Equals(default) ? null : _userManager.GetUserById(body.UserId);
var query = new InternalItemsQuery(user) var query = new InternalItemsQuery(user)
{ {
@ -642,7 +642,7 @@ namespace Jellyfin.Api.Controllers
GenreIds = body.GenreIds GenreIds = body.GenreIds
}; };
if (!body.LibrarySeriesId.Equals(Guid.Empty)) if (!body.LibrarySeriesId.Equals(default))
{ {
query.IsSeries = true; query.IsSeries = true;
@ -700,9 +700,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery] bool? enableUserData, [FromQuery] bool? enableUserData,
[FromQuery] bool enableTotalRecordCount = true) [FromQuery] bool enableTotalRecordCount = true)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var query = new InternalItemsQuery(user) var query = new InternalItemsQuery(user)
{ {
@ -738,9 +738,9 @@ namespace Jellyfin.Api.Controllers
[FromRoute, Required] string programId, [FromRoute, Required] string programId,
[FromQuery] Guid? userId) [FromQuery] Guid? userId)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
return await _liveTvManager.GetProgram(programId, CancellationToken.None, user).ConfigureAwait(false); return await _liveTvManager.GetProgram(programId, CancellationToken.None, user).ConfigureAwait(false);
} }

View File

@ -68,9 +68,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery] int categoryLimit = 5, [FromQuery] int categoryLimit = 5,
[FromQuery] int itemLimit = 8) [FromQuery] int itemLimit = 8)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var dtoOptions = new DtoOptions { Fields = fields } var dtoOptions = new DtoOptions { Fields = fields }
.AddClientFields(Request); .AddClientFields(Request);

View File

@ -95,7 +95,9 @@ namespace Jellyfin.Api.Controllers
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, false, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, false, imageTypeLimit, enableImageTypes);
User? user = userId.HasValue && userId != Guid.Empty ? _userManager.GetUserById(userId.Value) : null; User? user = userId is null || userId.Value.Equals(default)
? null
: _userManager.GetUserById(userId.Value);
var parentItem = _libraryManager.GetParentItem(parentId, userId); var parentItem = _libraryManager.GetParentItem(parentId, userId);
@ -156,7 +158,7 @@ namespace Jellyfin.Api.Controllers
item = _libraryManager.GetMusicGenre(genreName); item = _libraryManager.GetMusicGenre(genreName);
} }
if (userId.HasValue && !userId.Equals(Guid.Empty)) if (userId.HasValue && !userId.Value.Equals(default))
{ {
var user = _userManager.GetUserById(userId.Value); var user = _userManager.GetUserById(userId.Value);

View File

@ -82,12 +82,9 @@ namespace Jellyfin.Api.Controllers
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
User? user = null; User? user = userId is null || userId.Value.Equals(default)
? null
if (userId.HasValue && !userId.Equals(Guid.Empty)) : _userManager.GetUserById(userId.Value);
{
user = _userManager.GetUserById(userId.Value);
}
var isFavoriteInFilters = filters.Any(f => f == ItemFilter.IsFavorite); var isFavoriteInFilters = filters.Any(f => f == ItemFilter.IsFavorite);
var peopleItems = _libraryManager.GetPeopleItems(new InternalPeopleQuery( var peopleItems = _libraryManager.GetPeopleItems(new InternalPeopleQuery(
@ -127,7 +124,7 @@ namespace Jellyfin.Api.Controllers
return NotFound(); return NotFound();
} }
if (userId.HasValue && !userId.Equals(Guid.Empty)) if (userId.HasValue && !userId.Value.Equals(default))
{ {
var user = _userManager.GetUserById(userId.Value); var user = _userManager.GetUserById(userId.Value);
return _dtoService.GetBaseItemDto(item, dtoOptions, user); return _dtoService.GetBaseItemDto(item, dtoOptions, user);

View File

@ -181,7 +181,9 @@ namespace Jellyfin.Api.Controllers
return NotFound(); return NotFound();
} }
var user = !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId) : null; var user = userId.Equals(default)
? null
: _userManager.GetUserById(userId);
var items = playlist.GetManageableItems().ToArray(); var items = playlist.GetManageableItems().ToArray();

View File

@ -205,7 +205,7 @@ namespace Jellyfin.Api.Controllers
break; break;
} }
if (!item.ChannelId.Equals(Guid.Empty)) if (!item.ChannelId.Equals(default))
{ {
var channel = _libraryManager.GetItemById(item.ChannelId); var channel = _libraryManager.GetItemById(item.ChannelId);
result.ChannelName = channel?.Name; result.ChannelName = channel?.Name;

View File

@ -74,7 +74,7 @@ namespace Jellyfin.Api.Controllers
result = result.Where(i => string.Equals(i.DeviceId, deviceId, StringComparison.OrdinalIgnoreCase)); result = result.Where(i => string.Equals(i.DeviceId, deviceId, StringComparison.OrdinalIgnoreCase));
} }
if (controllableByUserId.HasValue && !controllableByUserId.Equals(Guid.Empty)) if (controllableByUserId.HasValue && !controllableByUserId.Equals(default))
{ {
result = result.Where(i => i.SupportsRemoteControl); result = result.Where(i => i.SupportsRemoteControl);
@ -82,12 +82,12 @@ namespace Jellyfin.Api.Controllers
if (!user.HasPermission(PermissionKind.EnableRemoteControlOfOtherUsers)) if (!user.HasPermission(PermissionKind.EnableRemoteControlOfOtherUsers))
{ {
result = result.Where(i => i.UserId.Equals(Guid.Empty) || i.ContainsUser(controllableByUserId.Value)); result = result.Where(i => i.UserId.Equals(default) || i.ContainsUser(controllableByUserId.Value));
} }
if (!user.HasPermission(PermissionKind.EnableSharedDeviceControl)) if (!user.HasPermission(PermissionKind.EnableSharedDeviceControl))
{ {
result = result.Where(i => !i.UserId.Equals(Guid.Empty)); result = result.Where(i => !i.UserId.Equals(default));
} }
if (activeWithinSeconds.HasValue && activeWithinSeconds.Value > 0) if (activeWithinSeconds.HasValue && activeWithinSeconds.Value > 0)

View File

@ -91,7 +91,9 @@ namespace Jellyfin.Api.Controllers
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
User? user = userId.HasValue && userId != Guid.Empty ? _userManager.GetUserById(userId.Value) : null; User? user = userId is null || userId.Value.Equals(default)
? null
: _userManager.GetUserById(userId.Value);
var parentItem = _libraryManager.GetParentItem(parentId, userId); var parentItem = _libraryManager.GetParentItem(parentId, userId);
@ -141,7 +143,7 @@ namespace Jellyfin.Api.Controllers
var dtoOptions = new DtoOptions().AddClientFields(Request); var dtoOptions = new DtoOptions().AddClientFields(Request);
var item = _libraryManager.GetStudio(name); var item = _libraryManager.GetStudio(name);
if (userId.HasValue && !userId.Equals(Guid.Empty)) if (userId.HasValue && !userId.Equals(default))
{ {
var user = _userManager.GetUserById(userId.Value); var user = _userManager.GetUserById(userId.Value);

View File

@ -63,7 +63,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery] int? limit, [FromQuery] int? limit,
[FromQuery] bool enableTotalRecordCount = false) [FromQuery] bool enableTotalRecordCount = false)
{ {
var user = !userId.Equals(Guid.Empty) ? _userManager.GetUserById(userId) : null; var user = userId.Equals(default)
? null
: _userManager.GetUserById(userId);
var dtoOptions = new DtoOptions().AddClientFields(Request); var dtoOptions = new DtoOptions().AddClientFields(Request);
var result = _libraryManager.GetItemsResult(new InternalItemsQuery(user) var result = _libraryManager.GetItemsResult(new InternalItemsQuery(user)

View File

@ -107,9 +107,9 @@ namespace Jellyfin.Api.Controllers
}, },
options); options);
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var returnItems = _dtoService.GetBaseItemDtos(result.Items, options, user); var returnItems = _dtoService.GetBaseItemDtos(result.Items, options, user);
@ -145,9 +145,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes,
[FromQuery] bool? enableUserData) [FromQuery] bool? enableUserData)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var minPremiereDate = DateTime.UtcNow.Date.AddDays(-1); var minPremiereDate = DateTime.UtcNow.Date.AddDays(-1);
@ -216,9 +216,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery] bool? enableUserData, [FromQuery] bool? enableUserData,
[FromQuery] string? sortBy) [FromQuery] string? sortBy)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
List<BaseItem> episodes; List<BaseItem> episodes;
@ -332,9 +332,9 @@ namespace Jellyfin.Api.Controllers
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes, [FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes,
[FromQuery] bool? enableUserData) [FromQuery] bool? enableUserData)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
if (_libraryManager.GetItemById(seriesId) is not Series series) if (_libraryManager.GetItemById(seriesId) is not Series series)
{ {

View File

@ -534,7 +534,7 @@ namespace Jellyfin.Api.Controllers
public ActionResult<UserDto> GetCurrentUser() public ActionResult<UserDto> GetCurrentUser()
{ {
var userId = ClaimHelpers.GetUserId(Request.HttpContext.User); var userId = ClaimHelpers.GetUserId(Request.HttpContext.User);
if (userId == null) if (userId is null)
{ {
return BadRequest(); return BadRequest();
} }

View File

@ -76,7 +76,7 @@ namespace Jellyfin.Api.Controllers
{ {
var user = _userManager.GetUserById(userId); var user = _userManager.GetUserById(userId);
var item = itemId.Equals(Guid.Empty) var item = itemId.Equals(default)
? _libraryManager.GetUserRootFolder() ? _libraryManager.GetUserRootFolder()
: _libraryManager.GetItemById(itemId); : _libraryManager.GetItemById(itemId);
@ -116,7 +116,7 @@ namespace Jellyfin.Api.Controllers
{ {
var user = _userManager.GetUserById(userId); var user = _userManager.GetUserById(userId);
var item = itemId.Equals(Guid.Empty) var item = itemId.Equals(default)
? _libraryManager.GetUserRootFolder() ? _libraryManager.GetUserRootFolder()
: _libraryManager.GetItemById(itemId); : _libraryManager.GetItemById(itemId);
@ -197,7 +197,7 @@ namespace Jellyfin.Api.Controllers
{ {
var user = _userManager.GetUserById(userId); var user = _userManager.GetUserById(userId);
var item = itemId.Equals(Guid.Empty) var item = itemId.Equals(default)
? _libraryManager.GetUserRootFolder() ? _libraryManager.GetUserRootFolder()
: _libraryManager.GetItemById(itemId); : _libraryManager.GetItemById(itemId);
@ -227,7 +227,7 @@ namespace Jellyfin.Api.Controllers
{ {
var user = _userManager.GetUserById(userId); var user = _userManager.GetUserById(userId);
var item = itemId.Equals(Guid.Empty) var item = itemId.Equals(default)
? _libraryManager.GetUserRootFolder() ? _libraryManager.GetUserRootFolder()
: _libraryManager.GetItemById(itemId); : _libraryManager.GetItemById(itemId);
@ -347,7 +347,7 @@ namespace Jellyfin.Api.Controllers
{ {
var user = _userManager.GetUserById(userId); var user = _userManager.GetUserById(userId);
var item = itemId.Equals(Guid.Empty) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(itemId); var item = itemId.Equals(default) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(itemId);
// Get the user data for this item // Get the user data for this item
var data = _userDataRepository.GetUserData(user, item); var data = _userDataRepository.GetUserData(user, item);
@ -370,7 +370,7 @@ namespace Jellyfin.Api.Controllers
{ {
var user = _userManager.GetUserById(userId); var user = _userManager.GetUserById(userId);
var item = itemId.Equals(Guid.Empty) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(itemId); var item = itemId.Equals(default) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(itemId);
// Get the user data for this item // Get the user data for this item
var data = _userDataRepository.GetUserData(user, item); var data = _userDataRepository.GetUserData(user, item);

View File

@ -109,14 +109,14 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult<QueryResult<BaseItemDto>> GetAdditionalPart([FromRoute, Required] Guid itemId, [FromQuery] Guid? userId) public ActionResult<QueryResult<BaseItemDto>> GetAdditionalPart([FromRoute, Required] Guid itemId, [FromQuery] Guid? userId)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var item = itemId.Equals(Guid.Empty) var item = itemId.Equals(default)
? (!userId.Equals(Guid.Empty) ? (userId is null || userId.Value.Equals(default)
? _libraryManager.GetUserRootFolder() ? _libraryManager.RootFolder
: _libraryManager.RootFolder) : _libraryManager.GetUserRootFolder())
: _libraryManager.GetItemById(itemId); : _libraryManager.GetItemById(itemId);
var dtoOptions = new DtoOptions(); var dtoOptions = new DtoOptions();
@ -221,7 +221,7 @@ namespace Jellyfin.Api.Controllers
var alternateVersionsOfPrimary = primaryVersion.LinkedAlternateVersions.ToList(); var alternateVersionsOfPrimary = primaryVersion.LinkedAlternateVersions.ToList();
foreach (var item in items.Where(i => i.Id != primaryVersion.Id)) foreach (var item in items.Where(i => !i.Id.Equals(primaryVersion.Id)))
{ {
item.SetPrimaryVersionId(primaryVersion.Id.ToString("N", CultureInfo.InvariantCulture)); item.SetPrimaryVersionId(primaryVersion.Id.ToString("N", CultureInfo.InvariantCulture));

View File

@ -90,16 +90,11 @@ namespace Jellyfin.Api.Controllers
.AddClientFields(Request) .AddClientFields(Request)
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes); .AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
User? user = null; User? user = userId is null || userId.Value.Equals(default)
? null
: _userManager.GetUserById(userId.Value);
BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId); BaseItem parentItem = _libraryManager.GetParentItem(parentId, userId);
if (userId.HasValue && !userId.Equals(Guid.Empty))
{
user = _userManager.GetUserById(userId.Value);
}
IList<BaseItem> items;
var query = new InternalItemsQuery(user) var query = new InternalItemsQuery(user)
{ {
ExcludeItemTypes = excludeItemTypes, ExcludeItemTypes = excludeItemTypes,
@ -110,17 +105,18 @@ namespace Jellyfin.Api.Controllers
bool Filter(BaseItem i) => FilterItem(i, excludeItemTypes, includeItemTypes, mediaTypes); bool Filter(BaseItem i) => FilterItem(i, excludeItemTypes, includeItemTypes, mediaTypes);
IList<BaseItem> items;
if (parentItem.IsFolder) if (parentItem.IsFolder)
{ {
var folder = (Folder)parentItem; var folder = (Folder)parentItem;
if (!userId.Equals(Guid.Empty)) if (userId.Equals(default))
{ {
items = recursive ? folder.GetRecursiveChildren(user, query).ToList() : folder.GetChildren(user, true).Where(Filter).ToList(); items = recursive ? folder.GetRecursiveChildren(Filter) : folder.Children.Where(Filter).ToList();
} }
else else
{ {
items = recursive ? folder.GetRecursiveChildren(Filter) : folder.Children.Where(Filter).ToList(); items = recursive ? folder.GetRecursiveChildren(user, query).ToList() : folder.GetChildren(user, true).Where(Filter).ToList();
} }
} }
else else
@ -185,7 +181,7 @@ namespace Jellyfin.Api.Controllers
var dtoOptions = new DtoOptions() var dtoOptions = new DtoOptions()
.AddClientFields(Request); .AddClientFields(Request);
if (userId.HasValue && !userId.Equals(Guid.Empty)) if (userId.HasValue && !userId.Value.Equals(default))
{ {
var user = _userManager.GetUserById(userId.Value); var user = _userManager.GetUserById(userId.Value);
return _dtoService.GetBaseItemDto(item, dtoOptions, user); return _dtoService.GetBaseItemDto(item, dtoOptions, user);

View File

@ -89,9 +89,9 @@ namespace Jellyfin.Api.Helpers
string? mediaSourceId = null, string? mediaSourceId = null,
string? liveStreamId = null) string? liveStreamId = null)
{ {
var user = userId.HasValue && !userId.Equals(Guid.Empty) var user = userId is null || userId.Value.Equals(default)
? _userManager.GetUserById(userId.Value) ? null
: null; : _userManager.GetUserById(userId.Value);
var item = _libraryManager.GetItemById(id); var item = _libraryManager.GetItemById(id);
var result = new PlaybackInfoResponse(); var result = new PlaybackInfoResponse();

View File

@ -102,7 +102,7 @@ namespace Jellyfin.Api.Helpers
}; };
var auth = await authorizationContext.GetAuthorizationInfo(httpRequest).ConfigureAwait(false); var auth = await authorizationContext.GetAuthorizationInfo(httpRequest).ConfigureAwait(false);
if (!auth.UserId.Equals(Guid.Empty)) if (!auth.UserId.Equals(default))
{ {
state.User = userManager.GetUserById(auth.UserId); state.User = userManager.GetUserById(auth.UserId);
} }
@ -151,7 +151,7 @@ namespace Jellyfin.Api.Helpers
? mediaSources[0] ? mediaSources[0]
: mediaSources.Find(i => string.Equals(i.Id, streamingRequest.MediaSourceId, StringComparison.Ordinal)); : mediaSources.Find(i => string.Equals(i.Id, streamingRequest.MediaSourceId, StringComparison.Ordinal));
if (mediaSource == null && Guid.Parse(streamingRequest.MediaSourceId) == streamingRequest.Id) if (mediaSource == null && Guid.Parse(streamingRequest.MediaSourceId).Equals(streamingRequest.Id))
{ {
mediaSource = mediaSources[0]; mediaSource = mediaSources[0];
} }

View File

@ -56,7 +56,7 @@ namespace Jellyfin.Server.Implementations.Activity
if (query.HasUserId.HasValue) if (query.HasUserId.HasValue)
{ {
entries = entries.Where(entry => entry.UserId != Guid.Empty == query.HasUserId.Value ); entries = entries.Where(entry => (!entry.UserId.Equals(default)) == query.HasUserId.Value);
} }
return new QueryResult<ActivityLogEntry>( return new QueryResult<ActivityLogEntry>(

View File

@ -120,7 +120,7 @@ namespace Jellyfin.Server.Implementations.Devices
if (query.UserId.HasValue) if (query.UserId.HasValue)
{ {
devices = devices.Where(device => device.UserId == query.UserId.Value); devices = devices.Where(device => device.UserId.Equals(query.UserId.Value));
} }
if (query.DeviceId != null) if (query.DeviceId != null)

View File

@ -32,7 +32,7 @@ namespace Jellyfin.Server.Implementations.Users
var prefs = _dbContext.DisplayPreferences var prefs = _dbContext.DisplayPreferences
.Include(pref => pref.HomeSections) .Include(pref => pref.HomeSections)
.FirstOrDefault(pref => .FirstOrDefault(pref =>
pref.UserId == userId && string.Equals(pref.Client, client) && pref.ItemId == itemId); pref.UserId.Equals(userId) && string.Equals(pref.Client, client) && pref.ItemId.Equals(itemId));
if (prefs == null) if (prefs == null)
{ {
@ -47,7 +47,7 @@ namespace Jellyfin.Server.Implementations.Users
public ItemDisplayPreferences GetItemDisplayPreferences(Guid userId, Guid itemId, string client) public ItemDisplayPreferences GetItemDisplayPreferences(Guid userId, Guid itemId, string client)
{ {
var prefs = _dbContext.ItemDisplayPreferences var prefs = _dbContext.ItemDisplayPreferences
.FirstOrDefault(pref => pref.UserId == userId && pref.ItemId == itemId && string.Equals(pref.Client, client)); .FirstOrDefault(pref => pref.UserId.Equals(userId) && pref.ItemId.Equals(itemId) && string.Equals(pref.Client, client));
if (prefs == null) if (prefs == null)
{ {
@ -63,7 +63,7 @@ namespace Jellyfin.Server.Implementations.Users
{ {
return _dbContext.ItemDisplayPreferences return _dbContext.ItemDisplayPreferences
.AsQueryable() .AsQueryable()
.Where(prefs => prefs.UserId == userId && prefs.ItemId != Guid.Empty && string.Equals(prefs.Client, client)) .Where(prefs => prefs.UserId.Equals(userId) && !prefs.ItemId.Equals(default) && string.Equals(prefs.Client, client))
.ToList(); .ToList();
} }
@ -72,8 +72,8 @@ namespace Jellyfin.Server.Implementations.Users
{ {
return _dbContext.CustomItemDisplayPreferences return _dbContext.CustomItemDisplayPreferences
.AsQueryable() .AsQueryable()
.Where(prefs => prefs.UserId == userId .Where(prefs => prefs.UserId.Equals(userId)
&& prefs.ItemId == itemId && prefs.ItemId.Equals(itemId)
&& string.Equals(prefs.Client, client)) && string.Equals(prefs.Client, client))
.ToDictionary(prefs => prefs.Key, prefs => prefs.Value); .ToDictionary(prefs => prefs.Key, prefs => prefs.Value);
} }
@ -83,8 +83,8 @@ namespace Jellyfin.Server.Implementations.Users
{ {
var existingPrefs = _dbContext.CustomItemDisplayPreferences var existingPrefs = _dbContext.CustomItemDisplayPreferences
.AsQueryable() .AsQueryable()
.Where(prefs => prefs.UserId == userId .Where(prefs => prefs.UserId.Equals(userId)
&& prefs.ItemId == itemId && prefs.ItemId.Equals(itemId)
&& string.Equals(prefs.Client, client)); && string.Equals(prefs.Client, client));
_dbContext.CustomItemDisplayPreferences.RemoveRange(existingPrefs); _dbContext.CustomItemDisplayPreferences.RemoveRange(existingPrefs);

View File

@ -107,7 +107,7 @@ namespace Jellyfin.Server.Implementations.Users
/// <inheritdoc/> /// <inheritdoc/>
public User? GetUserById(Guid id) public User? GetUserById(Guid id)
{ {
if (id == Guid.Empty) if (id.Equals(default))
{ {
throw new ArgumentException("Guid can't be empty", nameof(id)); throw new ArgumentException("Guid can't be empty", nameof(id));
} }
@ -146,8 +146,7 @@ namespace Jellyfin.Server.Implementations.Users
if (await dbContext.Users if (await dbContext.Users
.AsQueryable() .AsQueryable()
.Where(u => u.Username == newName && u.Id != user.Id) .AnyAsync(u => u.Username == newName && !u.Id.Equals(user.Id))
.AnyAsync()
.ConfigureAwait(false)) .ConfigureAwait(false))
{ {
throw new ArgumentException(string.Format( throw new ArgumentException(string.Format(
@ -597,7 +596,7 @@ namespace Jellyfin.Server.Implementations.Users
.Include(u => u.Preferences) .Include(u => u.Preferences)
.Include(u => u.AccessSchedules) .Include(u => u.AccessSchedules)
.Include(u => u.ProfileImage) .Include(u => u.ProfileImage)
.FirstOrDefault(u => u.Id == userId) .FirstOrDefault(u => u.Id.Equals(userId))
?? throw new ArgumentException("No user exists with given Id!"); ?? throw new ArgumentException("No user exists with given Id!");
user.SubtitleMode = config.SubtitleMode; user.SubtitleMode = config.SubtitleMode;
@ -631,7 +630,7 @@ namespace Jellyfin.Server.Implementations.Users
.Include(u => u.Preferences) .Include(u => u.Preferences)
.Include(u => u.AccessSchedules) .Include(u => u.AccessSchedules)
.Include(u => u.ProfileImage) .Include(u => u.ProfileImage)
.FirstOrDefault(u => u.Id == userId) .FirstOrDefault(u => u.Id.Equals(userId))
?? throw new ArgumentException("No user exists with given Id!"); ?? throw new ArgumentException("No user exists with given Id!");
// The default number of login attempts is 3, but for some god forsaken reason it's sent to the server as "0" // The default number of login attempts is 3, but for some god forsaken reason it's sent to the server as "0"

View File

@ -187,14 +187,14 @@ namespace MediaBrowser.Controller.Entities
/// <exception cref="ArgumentNullException">The id is empty.</exception> /// <exception cref="ArgumentNullException">The id is empty.</exception>
public BaseItem FindVirtualChild(Guid id) public BaseItem FindVirtualChild(Guid id)
{ {
if (id.Equals(Guid.Empty)) if (id.Equals(default))
{ {
throw new ArgumentNullException(nameof(id)); throw new ArgumentNullException(nameof(id));
} }
foreach (var child in _virtualChildren) foreach (var child in _virtualChildren)
{ {
if (child.Id == id) if (child.Id.Equals(id))
{ {
return child; return child;
} }

View File

@ -24,7 +24,7 @@ namespace MediaBrowser.Controller.Entities.Audio
public class MusicArtist : Folder, IItemByName, IHasMusicGenres, IHasDualAccess, IHasLookupInfo<ArtistInfo> public class MusicArtist : Folder, IItemByName, IHasMusicGenres, IHasDualAccess, IHasLookupInfo<ArtistInfo>
{ {
[JsonIgnore] [JsonIgnore]
public bool IsAccessedByName => ParentId.Equals(Guid.Empty); public bool IsAccessedByName => ParentId.Equals(default);
[JsonIgnore] [JsonIgnore]
public override bool IsFolder => !IsAccessedByName; public override bool IsFolder => !IsAccessedByName;

View File

@ -231,7 +231,7 @@ namespace MediaBrowser.Controller.Entities
{ {
get get
{ {
if (!ChannelId.Equals(Guid.Empty)) if (!ChannelId.Equals(default))
{ {
return SourceType.Channel; return SourceType.Channel;
} }
@ -521,7 +521,7 @@ namespace MediaBrowser.Controller.Entities
get get
{ {
var id = DisplayParentId; var id = DisplayParentId;
if (id.Equals(Guid.Empty)) if (id.Equals(default))
{ {
return null; return null;
} }
@ -737,7 +737,7 @@ namespace MediaBrowser.Controller.Entities
public virtual bool StopRefreshIfLocalMetadataFound => true; public virtual bool StopRefreshIfLocalMetadataFound => true;
[JsonIgnore] [JsonIgnore]
protected virtual bool SupportsOwnedItems => !ParentId.Equals(Guid.Empty) && IsFileProtocol; protected virtual bool SupportsOwnedItems => !ParentId.Equals(default) && IsFileProtocol;
[JsonIgnore] [JsonIgnore]
public virtual bool SupportsPeople => false; public virtual bool SupportsPeople => false;
@ -848,7 +848,7 @@ namespace MediaBrowser.Controller.Entities
public BaseItem GetOwner() public BaseItem GetOwner()
{ {
var ownerId = OwnerId; var ownerId = OwnerId;
return ownerId.Equals(Guid.Empty) ? null : LibraryManager.GetItemById(ownerId); return ownerId.Equals(default) ? null : LibraryManager.GetItemById(ownerId);
} }
public bool CanDelete(User user, List<Folder> allCollectionFolders) public bool CanDelete(User user, List<Folder> allCollectionFolders)
@ -984,12 +984,12 @@ namespace MediaBrowser.Controller.Entities
public BaseItem GetParent() public BaseItem GetParent()
{ {
var parentId = ParentId; var parentId = ParentId;
if (!parentId.Equals(Guid.Empty)) if (parentId.Equals(default))
{ {
return LibraryManager.GetItemById(parentId); return null;
} }
return null; return LibraryManager.GetItemById(parentId);
} }
public IEnumerable<BaseItem> GetParents() public IEnumerable<BaseItem> GetParents()
@ -1397,7 +1397,7 @@ namespace MediaBrowser.Controller.Entities
var tasks = extras.Select(i => var tasks = extras.Select(i =>
{ {
var subOptions = new MetadataRefreshOptions(options); var subOptions = new MetadataRefreshOptions(options);
if (i.OwnerId != ownerId || i.ParentId != Guid.Empty) if (!i.OwnerId.Equals(ownerId) || !i.ParentId.Equals(default))
{ {
i.OwnerId = ownerId; i.OwnerId = ownerId;
i.ParentId = Guid.Empty; i.ParentId = Guid.Empty;
@ -1736,7 +1736,7 @@ namespace MediaBrowser.Controller.Entities
// First get using the cached Id // First get using the cached Id
if (info.ItemId.HasValue) if (info.ItemId.HasValue)
{ {
if (info.ItemId.Value.Equals(Guid.Empty)) if (info.ItemId.Value.Equals(default))
{ {
return null; return null;
} }
@ -2657,7 +2657,7 @@ namespace MediaBrowser.Controller.Entities
} }
/// <inheritdoc /> /// <inheritdoc />
public bool Equals(BaseItem other) => Id == other?.Id; public bool Equals(BaseItem other) => other is not null && other.Id.Equals(Id);
/// <inheritdoc /> /// <inheritdoc />
public override int GetHashCode() => HashCode.Combine(Id); public override int GetHashCode() => HashCode.Combine(Id);

View File

@ -213,7 +213,7 @@ namespace MediaBrowser.Controller.Entities
{ {
item.SetParent(this); item.SetParent(this);
if (item.Id.Equals(Guid.Empty)) if (item.Id.Equals(default))
{ {
item.Id = LibraryManager.GetNewItemId(item.Path, item.GetType()); item.Id = LibraryManager.GetNewItemId(item.Path, item.GetType());
} }
@ -730,7 +730,9 @@ namespace MediaBrowser.Controller.Entities
return PostFilterAndSort(items, query, true); return PostFilterAndSort(items, query, true);
} }
if (this is not UserRootFolder && this is not AggregateFolder && query.ParentId == Guid.Empty) if (this is not UserRootFolder
&& this is not AggregateFolder
&& query.ParentId.Equals(default))
{ {
query.Parent = this; query.Parent = this;
} }
@ -1492,7 +1494,7 @@ namespace MediaBrowser.Controller.Entities
{ {
if (i.ItemId.HasValue) if (i.ItemId.HasValue)
{ {
if (i.ItemId.Value == itemId) if (i.ItemId.Value.Equals(itemId))
{ {
return true; return true;
} }
@ -1502,7 +1504,7 @@ namespace MediaBrowser.Controller.Entities
var child = GetLinkedChild(i); var child = GetLinkedChild(i);
if (child != null && child.Id == itemId) if (child != null && child.Id.Equals(itemId))
{ {
return true; return true;
} }

View File

@ -74,12 +74,12 @@ namespace MediaBrowser.Controller.Entities.TV
get get
{ {
var seriesId = SeriesId; var seriesId = SeriesId;
if (seriesId.Equals(Guid.Empty)) if (seriesId.Equals(default))
{ {
seriesId = FindSeriesId(); seriesId = FindSeriesId();
} }
return !seriesId.Equals(Guid.Empty) ? (LibraryManager.GetItemById(seriesId) as Series) : null; return seriesId.Equals(default) ? null : (LibraryManager.GetItemById(seriesId) as Series);
} }
} }
@ -89,12 +89,12 @@ namespace MediaBrowser.Controller.Entities.TV
get get
{ {
var seasonId = SeasonId; var seasonId = SeasonId;
if (seasonId.Equals(Guid.Empty)) if (seasonId.Equals(default))
{ {
seasonId = FindSeasonId(); seasonId = FindSeasonId();
} }
return !seasonId.Equals(Guid.Empty) ? (LibraryManager.GetItemById(seasonId) as Season) : null; return seasonId.Equals(default) ? null : (LibraryManager.GetItemById(seasonId) as Season);
} }
} }
@ -271,7 +271,7 @@ namespace MediaBrowser.Controller.Entities.TV
var seasonId = SeasonId; var seasonId = SeasonId;
if (!seasonId.Equals(Guid.Empty) && !list.Contains(seasonId)) if (!seasonId.Equals(default) && !list.Contains(seasonId))
{ {
list.Add(seasonId); list.Add(seasonId);
} }

View File

@ -48,12 +48,12 @@ namespace MediaBrowser.Controller.Entities.TV
get get
{ {
var seriesId = SeriesId; var seriesId = SeriesId;
if (seriesId == Guid.Empty) if (seriesId.Equals(default))
{ {
seriesId = FindSeriesId(); seriesId = FindSeriesId();
} }
return seriesId == Guid.Empty ? null : (LibraryManager.GetItemById(seriesId) as Series); return seriesId.Equals(default) ? null : (LibraryManager.GetItemById(seriesId) as Series);
} }
} }

View File

@ -69,11 +69,11 @@ namespace MediaBrowser.Controller.Entities
/// <inheritdoc /> /// <inheritdoc />
public override IEnumerable<Guid> GetIdsForAncestorQuery() public override IEnumerable<Guid> GetIdsForAncestorQuery()
{ {
if (!DisplayParentId.Equals(Guid.Empty)) if (!DisplayParentId.Equals(default))
{ {
yield return DisplayParentId; yield return DisplayParentId;
} }
else if (!ParentId.Equals(Guid.Empty)) else if (!ParentId.Equals(default))
{ {
yield return ParentId; yield return ParentId;
} }
@ -94,11 +94,11 @@ namespace MediaBrowser.Controller.Entities
{ {
var parent = this as Folder; var parent = this as Folder;
if (!DisplayParentId.Equals(Guid.Empty)) if (!DisplayParentId.Equals(default))
{ {
parent = LibraryManager.GetItemById(DisplayParentId) as Folder ?? parent; parent = LibraryManager.GetItemById(DisplayParentId) as Folder ?? parent;
} }
else if (!ParentId.Equals(Guid.Empty)) else if (!ParentId.Equals(default))
{ {
parent = LibraryManager.GetItemById(ParentId) as Folder ?? parent; parent = LibraryManager.GetItemById(ParentId) as Folder ?? parent;
} }

View File

@ -988,7 +988,7 @@ namespace MediaBrowser.Controller.Entities
public static IEnumerable<BaseItem> FilterForAdjacency(List<BaseItem> list, string adjacentToId) public static IEnumerable<BaseItem> FilterForAdjacency(List<BaseItem> list, string adjacentToId)
{ {
var adjacentToIdGuid = new Guid(adjacentToId); var adjacentToIdGuid = new Guid(adjacentToId);
var adjacentToItem = list.FirstOrDefault(i => i.Id == adjacentToIdGuid); var adjacentToItem = list.FirstOrDefault(i => i.Id.Equals(adjacentToIdGuid));
var index = list.IndexOf(adjacentToItem); var index = list.IndexOf(adjacentToItem);
@ -1005,7 +1005,7 @@ namespace MediaBrowser.Controller.Entities
nextId = list[index + 1].Id; nextId = list[index + 1].Id;
} }
return list.Where(i => i.Id == previousId || i.Id == nextId || i.Id == adjacentToIdGuid); return list.Where(i => i.Id.Equals(previousId) || i.Id.Equals(nextId) || i.Id.Equals(adjacentToIdGuid));
} }
} }
} }

View File

@ -455,7 +455,7 @@ namespace MediaBrowser.Controller.Entities
foreach (var child in LinkedAlternateVersions) foreach (var child in LinkedAlternateVersions)
{ {
// Reset the cached value // Reset the cached value
if (child.ItemId.HasValue && child.ItemId.Value.Equals(Guid.Empty)) if (child.ItemId.HasValue && child.ItemId.Value.Equals(default))
{ {
child.ItemId = null; child.ItemId = null;
} }

View File

@ -233,7 +233,7 @@ namespace MediaBrowser.Controller.Playlists
return base.IsVisible(user); return base.IsVisible(user);
} }
if (user.Id == OwnerUserId) if (user.Id.Equals(OwnerUserId))
{ {
return true; return true;
} }
@ -244,8 +244,8 @@ namespace MediaBrowser.Controller.Playlists
return base.IsVisible(user); return base.IsVisible(user);
} }
var userId = user.Id.ToString("N", CultureInfo.InvariantCulture); var userId = user.Id;
return shares.Any(share => string.Equals(share.UserId, userId, StringComparison.OrdinalIgnoreCase)); return shares.Any(share => Guid.TryParse(share.UserId, out var id) && id.Equals(userId));
} }
public override bool IsVisibleStandalone(User user) public override bool IsVisibleStandalone(User user)

View File

@ -1444,7 +1444,7 @@ namespace MediaBrowser.Model.Dlna
private static void ValidateAudioInput(AudioOptions options) private static void ValidateAudioInput(AudioOptions options)
{ {
if (options.ItemId.Equals(Guid.Empty)) if (options.ItemId.Equals(default))
{ {
throw new ArgumentException("ItemId is required"); throw new ArgumentException("ItemId is required");
} }

View File

@ -412,7 +412,7 @@ namespace MediaBrowser.Providers.Manager
} }
// If this restriction is ever lifted, movie xml providers will have to be updated to prevent owned items like trailers from reading those files // If this restriction is ever lifted, movie xml providers will have to be updated to prevent owned items like trailers from reading those files
if (!item.OwnerId.Equals(Guid.Empty)) if (!item.OwnerId.Equals(default))
{ {
if (provider is ILocalMetadataProvider || provider is IRemoteMetadataProvider) if (provider is ILocalMetadataProvider || provider is IRemoteMetadataProvider)
{ {
@ -781,7 +781,7 @@ namespace MediaBrowser.Providers.Manager
{ {
BaseItem referenceItem = null; BaseItem referenceItem = null;
if (!searchInfo.ItemId.Equals(Guid.Empty)) if (!searchInfo.ItemId.Equals(default))
{ {
referenceItem = _libraryManager.GetItemById(searchInfo.ItemId); referenceItem = _libraryManager.GetItemById(searchInfo.ItemId);
} }

View File

@ -16,14 +16,15 @@ namespace Jellyfin.Extensions.Json.Converters
/// <inheritdoc /> /// <inheritdoc />
public override void Write(Utf8JsonWriter writer, Guid? value, JsonSerializerOptions options) public override void Write(Utf8JsonWriter writer, Guid? value, JsonSerializerOptions options)
{ {
if (value == Guid.Empty) // null got handled higher up the call stack
var val = value!.Value;
if (val.Equals(default))
{ {
writer.WriteNullValue(); writer.WriteNullValue();
} }
else else
{ {
// null got handled higher up the call stack JsonGuidConverter.WriteInternal(writer, val);
JsonGuidConverter.WriteInternal(writer, value!.Value);
} }
} }
} }

View File

@ -148,7 +148,7 @@ namespace Jellyfin.Providers.Tests.MediaInfo
var mediaSourceManager = new Mock<IMediaSourceManager>(MockBehavior.Strict); var mediaSourceManager = new Mock<IMediaSourceManager>(MockBehavior.Strict);
mediaSourceManager.Setup(i => i.GetMediaAttachments(item.Id)) mediaSourceManager.Setup(i => i.GetMediaAttachments(item.Id))
.Returns(mediaAttachments); .Returns(mediaAttachments);
mediaSourceManager.Setup(i => i.GetMediaStreams(It.Is<MediaStreamQuery>(q => q.ItemId == item.Id && q.Type == MediaStreamType.EmbeddedImage))) mediaSourceManager.Setup(i => i.GetMediaStreams(It.Is<MediaStreamQuery>(q => q.ItemId.Equals(item.Id) && q.Type == MediaStreamType.EmbeddedImage)))
.Returns(mediaStreams); .Returns(mediaStreams);
return mediaSourceManager.Object; return mediaSourceManager.Object;
} }

View File

@ -116,9 +116,9 @@ namespace Jellyfin.Providers.Tests.MediaInfo
} }
var mediaSourceManager = new Mock<IMediaSourceManager>(MockBehavior.Strict); var mediaSourceManager = new Mock<IMediaSourceManager>(MockBehavior.Strict);
mediaSourceManager.Setup(i => i.GetMediaStreams(It.Is<MediaStreamQuery>(q => q.ItemId == item.Id && q.Index == item.DefaultVideoStreamIndex))) mediaSourceManager.Setup(i => i.GetMediaStreams(It.Is<MediaStreamQuery>(q => q.ItemId.Equals(item.Id) && q.Index == item.DefaultVideoStreamIndex)))
.Returns(defaultStreamList); .Returns(defaultStreamList);
mediaSourceManager.Setup(i => i.GetMediaStreams(It.Is<MediaStreamQuery>(q => q.ItemId == item.Id && q.Type == MediaStreamType.Video))) mediaSourceManager.Setup(i => i.GetMediaStreams(It.Is<MediaStreamQuery>(q => q.ItemId.Equals(item.Id) && q.Type == MediaStreamType.Video)))
.Returns(mediaStreams); .Returns(mediaStreams);
return mediaSourceManager.Object; return mediaSourceManager.Object;
} }

View File

@ -130,7 +130,7 @@ namespace Jellyfin.Server.Integration.Tests.Controllers
var users = await JsonSerializer.DeserializeAsync<UserDto[]>( var users = await JsonSerializer.DeserializeAsync<UserDto[]>(
await client.GetStreamAsync("Users").ConfigureAwait(false), _jsonOpions).ConfigureAwait(false); await client.GetStreamAsync("Users").ConfigureAwait(false), _jsonOpions).ConfigureAwait(false);
var user = users!.First(x => x.Id == _testUserId); var user = users!.First(x => x.Id.Equals(_testUserId));
Assert.True(user.HasPassword); Assert.True(user.HasPassword);
Assert.True(user.HasConfiguredPassword); Assert.True(user.HasConfiguredPassword);
} }
@ -153,7 +153,7 @@ namespace Jellyfin.Server.Integration.Tests.Controllers
var users = await JsonSerializer.DeserializeAsync<UserDto[]>( var users = await JsonSerializer.DeserializeAsync<UserDto[]>(
await client.GetStreamAsync("Users").ConfigureAwait(false), _jsonOpions).ConfigureAwait(false); await client.GetStreamAsync("Users").ConfigureAwait(false), _jsonOpions).ConfigureAwait(false);
var user = users!.First(x => x.Id == _testUserId); var user = users!.First(x => x.Id.Equals(_testUserId));
Assert.False(user.HasPassword); Assert.False(user.HasPassword);
Assert.False(user.HasConfiguredPassword); Assert.False(user.HasConfiguredPassword);
} }