Use helper function to compare guid (#10825)

This commit is contained in:
Cody Robibero
2024-01-17 08:51:39 -07:00
committed by GitHub
parent 484ccf7f28
commit e7b8d45bbb
58 changed files with 249 additions and 184 deletions

View File

@@ -0,0 +1,26 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace Jellyfin.Extensions;
/// <summary>
/// Guid specific extensions.
/// </summary>
public static class GuidExtensions
{
/// <summary>
/// Determine whether the guid is default.
/// </summary>
/// <param name="guid">The guid.</param>
/// <returns>Whether the guid is the default value.</returns>
public static bool IsEmpty(this Guid guid)
=> guid.Equals(default);
/// <summary>
/// Determine whether the guid is null or default.
/// </summary>
/// <param name="guid">The guid.</param>
/// <returns>Whether the guid is null or the default valueF.</returns>
public static bool IsNullOrEmpty([NotNullWhen(false)] this Guid? guid)
=> guid is null || guid.Value.IsEmpty();
}

View File

@@ -18,7 +18,7 @@ namespace Jellyfin.Extensions.Json.Converters
{
// null got handled higher up the call stack
var val = value!.Value;
if (val.Equals(default))
if (val.IsEmpty())
{
writer.WriteNullValue();
}

View File

@@ -150,7 +150,7 @@ namespace Jellyfin.LiveTv.Channels
/// <inheritdoc />
public async Task<QueryResult<Channel>> GetChannelsInternalAsync(ChannelQuery query)
{
var user = query.UserId.Equals(default)
var user = query.UserId.IsEmpty()
? null
: _userManager.GetUserById(query.UserId);
@@ -263,7 +263,7 @@ namespace Jellyfin.LiveTv.Channels
/// <inheritdoc />
public async Task<QueryResult<BaseItemDto>> GetChannelsAsync(ChannelQuery query)
{
var user = query.UserId.Equals(default)
var user = query.UserId.IsEmpty()
? null
: _userManager.GetUserById(query.UserId);
@@ -695,7 +695,7 @@ namespace Jellyfin.LiveTv.Channels
// Find the corresponding channel provider plugin
var channelProvider = GetChannelProvider(channel);
var parentItem = query.ParentId.Equals(default)
var parentItem = query.ParentId.IsEmpty()
? channel
: _libraryManager.GetItemById(query.ParentId);
@@ -708,7 +708,7 @@ namespace Jellyfin.LiveTv.Channels
cancellationToken)
.ConfigureAwait(false);
if (query.ParentId.Equals(default))
if (query.ParentId.IsEmpty())
{
query.Parent = channel;
}

View File

@@ -1992,7 +1992,7 @@ namespace Jellyfin.LiveTv.EmbyTV
await writer.WriteElementStringAsync(null, "genre", null, genre).ConfigureAwait(false);
}
var people = item.Id.Equals(default) ? new List<PersonInfo>() : _libraryManager.GetPeople(item);
var people = item.Id.IsEmpty() ? new List<PersonInfo>() : _libraryManager.GetPeople(item);
var directors = people
.Where(i => i.IsType(PersonKind.Director))
@@ -2317,7 +2317,7 @@ namespace Jellyfin.LiveTv.EmbyTV
{
string channelId = seriesTimer.RecordAnyChannel ? null : seriesTimer.ChannelId;
if (string.IsNullOrWhiteSpace(channelId) && !parent.ChannelId.Equals(default))
if (string.IsNullOrWhiteSpace(channelId) && !parent.ChannelId.IsEmpty())
{
if (!tempChannelCache.TryGetValue(parent.ChannelId, out LiveTvChannel channel))
{
@@ -2376,7 +2376,7 @@ namespace Jellyfin.LiveTv.EmbyTV
{
string channelId = null;
if (!programInfo.ChannelId.Equals(default))
if (!programInfo.ChannelId.IsEmpty())
{
if (!tempChannelCache.TryGetValue(programInfo.ChannelId, out LiveTvChannel channel))
{

View File

@@ -8,6 +8,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Common;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Drawing;
@@ -456,7 +457,7 @@ namespace Jellyfin.LiveTv
info.Id = timer.ExternalId;
}
if (!dto.ChannelId.Equals(default) && string.IsNullOrEmpty(info.ChannelId))
if (!dto.ChannelId.IsEmpty() && string.IsNullOrEmpty(info.ChannelId))
{
var channel = _libraryManager.GetItemById(dto.ChannelId);
@@ -522,7 +523,7 @@ namespace Jellyfin.LiveTv
info.Id = timer.ExternalId;
}
if (!dto.ChannelId.Equals(default) && string.IsNullOrEmpty(info.ChannelId))
if (!dto.ChannelId.IsEmpty() && string.IsNullOrEmpty(info.ChannelId))
{
var channel = _libraryManager.GetItemById(dto.ChannelId);

View File

@@ -12,6 +12,7 @@ using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using Jellyfin.Data.Events;
using Jellyfin.Extensions;
using Jellyfin.LiveTv.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Progress;
@@ -150,7 +151,7 @@ namespace Jellyfin.LiveTv
public QueryResult<BaseItem> GetInternalChannels(LiveTvChannelQuery query, DtoOptions dtoOptions, CancellationToken cancellationToken)
{
var user = query.UserId.Equals(default)
var user = query.UserId.IsEmpty()
? null
: _userManager.GetUserById(query.UserId);
@@ -1245,7 +1246,7 @@ namespace Jellyfin.LiveTv
{
cancellationToken.ThrowIfCancellationRequested();
if (itemId.Equals(default))
if (itemId.IsEmpty())
{
// Somehow some invalid data got into the db. It probably predates the boundary checking
continue;
@@ -1504,7 +1505,7 @@ namespace Jellyfin.LiveTv
public async Task<QueryResult<BaseItemDto>> GetRecordingsAsync(RecordingQuery query, DtoOptions options)
{
var user = query.UserId.Equals(default)
var user = query.UserId.IsEmpty()
? null
: _userManager.GetUserById(query.UserId);