mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-17 07:36:37 +00:00
Code Clean up: Convert to null-coalescing operator ?? (#5845)
Co-authored-by: Cody Robibero <cody@robibe.ro> Co-authored-by: Patrick Barron <18354464+barronpm@users.noreply.github.com>
This commit is contained in:
@@ -335,10 +335,7 @@ namespace Emby.Server.Implementations
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_deviceId == null)
|
||||
{
|
||||
_deviceId = new DeviceId(ApplicationPaths, LoggerFactory);
|
||||
}
|
||||
_deviceId ??= new DeviceId(ApplicationPaths, LoggerFactory);
|
||||
|
||||
return _deviceId.Value;
|
||||
}
|
||||
@@ -370,10 +367,7 @@ namespace Emby.Server.Implementations
|
||||
/// <returns>System.Object.</returns>
|
||||
protected object CreateInstanceSafe(Type type)
|
||||
{
|
||||
if (_creatingInstances == null)
|
||||
{
|
||||
_creatingInstances = new List<Type>();
|
||||
}
|
||||
_creatingInstances ??= new List<Type>();
|
||||
|
||||
if (_creatingInstances.IndexOf(type) != -1)
|
||||
{
|
||||
|
||||
@@ -665,10 +665,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
var tag = GetImageCacheTag(item, image);
|
||||
if (!string.IsNullOrEmpty(image.BlurHash))
|
||||
{
|
||||
if (dto.ImageBlurHashes == null)
|
||||
{
|
||||
dto.ImageBlurHashes = new Dictionary<ImageType, Dictionary<string, string>>();
|
||||
}
|
||||
dto.ImageBlurHashes ??= new Dictionary<ImageType, Dictionary<string, string>>();
|
||||
|
||||
if (!dto.ImageBlurHashes.ContainsKey(image.Type))
|
||||
{
|
||||
@@ -702,10 +699,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
|
||||
if (hashes.Count > 0)
|
||||
{
|
||||
if (dto.ImageBlurHashes == null)
|
||||
{
|
||||
dto.ImageBlurHashes = new Dictionary<ImageType, Dictionary<string, string>>();
|
||||
}
|
||||
dto.ImageBlurHashes ??= new Dictionary<ImageType, Dictionary<string, string>>();
|
||||
|
||||
dto.ImageBlurHashes[imageType] = hashes;
|
||||
}
|
||||
@@ -898,10 +892,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
dto.Taglines = new string[] { item.Tagline };
|
||||
}
|
||||
|
||||
if (dto.Taglines == null)
|
||||
{
|
||||
dto.Taglines = Array.Empty<string>();
|
||||
}
|
||||
dto.Taglines ??= Array.Empty<string>();
|
||||
}
|
||||
|
||||
dto.Type = item.GetBaseItemKind();
|
||||
|
||||
@@ -176,10 +176,7 @@ namespace Emby.Server.Implementations.Library
|
||||
{
|
||||
lock (_rootFolderSyncLock)
|
||||
{
|
||||
if (_rootFolder == null)
|
||||
{
|
||||
_rootFolder = CreateRootFolder();
|
||||
}
|
||||
_rootFolder ??= CreateRootFolder();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,14 +35,10 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
|
||||
return null;
|
||||
}
|
||||
|
||||
var season = parent as Season;
|
||||
|
||||
// Just in case the user decided to nest episodes.
|
||||
// Not officially supported but in some cases we can handle it.
|
||||
if (season == null)
|
||||
{
|
||||
season = parent.GetParents().OfType<Season>().FirstOrDefault();
|
||||
}
|
||||
|
||||
var season = parent as Season ?? parent.GetParents().OfType<Season>().FirstOrDefault();
|
||||
|
||||
// If the parent is a Season or Series and the parent is not an extras folder, then this is an Episode if the VideoResolver returns something
|
||||
// Also handle flat tv folders
|
||||
@@ -55,11 +51,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
|
||||
|
||||
if (episode != null)
|
||||
{
|
||||
var series = parent as Series;
|
||||
if (series == null)
|
||||
{
|
||||
series = parent.GetParents().OfType<Series>().FirstOrDefault();
|
||||
}
|
||||
var series = parent as Series ?? parent.GetParents().OfType<Series>().FirstOrDefault();
|
||||
|
||||
if (series != null)
|
||||
{
|
||||
|
||||
@@ -2237,14 +2237,10 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
||||
var enabledTimersForSeries = new List<TimerInfo>();
|
||||
foreach (var timer in allTimers)
|
||||
{
|
||||
var existingTimer = _timerProvider.GetTimer(timer.Id);
|
||||
|
||||
if (existingTimer == null)
|
||||
{
|
||||
existingTimer = string.IsNullOrWhiteSpace(timer.ProgramId)
|
||||
var existingTimer = _timerProvider.GetTimer(timer.Id)
|
||||
?? (string.IsNullOrWhiteSpace(timer.ProgramId)
|
||||
? null
|
||||
: _timerProvider.GetTimerByProgramId(timer.ProgramId);
|
||||
}
|
||||
: _timerProvider.GetTimerByProgramId(timer.ProgramId));
|
||||
|
||||
if (existingTimer == null)
|
||||
{
|
||||
|
||||
@@ -787,14 +787,11 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
||||
{
|
||||
var channelNumber = GetChannelNumber(channel);
|
||||
|
||||
var station = allStations.Find(item => string.Equals(item.stationID, channel.stationID, StringComparison.OrdinalIgnoreCase));
|
||||
if (station == null)
|
||||
{
|
||||
station = new ScheduleDirect.Station
|
||||
var station = allStations.Find(item => string.Equals(item.stationID, channel.stationID, StringComparison.OrdinalIgnoreCase))
|
||||
?? new ScheduleDirect.Station
|
||||
{
|
||||
stationID = channel.stationID
|
||||
};
|
||||
}
|
||||
|
||||
var channelInfo = new ChannelInfo
|
||||
{
|
||||
|
||||
@@ -987,10 +987,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
var externalProgramId = programTuple.Item2;
|
||||
string externalSeriesId = programTuple.Item3;
|
||||
|
||||
if (timerList == null)
|
||||
{
|
||||
timerList = (await GetTimersInternal(new TimerQuery(), cancellationToken).ConfigureAwait(false)).Items;
|
||||
}
|
||||
timerList ??= (await GetTimersInternal(new TimerQuery(), cancellationToken).ConfigureAwait(false)).Items;
|
||||
|
||||
var timer = timerList.FirstOrDefault(i => string.Equals(i.ProgramId, externalProgramId, StringComparison.OrdinalIgnoreCase));
|
||||
var foundSeriesTimer = false;
|
||||
@@ -1018,10 +1015,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
continue;
|
||||
}
|
||||
|
||||
if (seriesTimerList == null)
|
||||
{
|
||||
seriesTimerList = (await GetSeriesTimersInternal(new SeriesTimerQuery(), cancellationToken).ConfigureAwait(false)).Items;
|
||||
}
|
||||
seriesTimerList ??= (await GetSeriesTimersInternal(new SeriesTimerQuery(), cancellationToken).ConfigureAwait(false)).Items;
|
||||
|
||||
var seriesTimer = seriesTimerList.FirstOrDefault(i => string.Equals(i.SeriesId, externalSeriesId, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
@@ -1974,10 +1968,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
};
|
||||
}
|
||||
|
||||
if (service == null)
|
||||
{
|
||||
service = _services[0];
|
||||
}
|
||||
service ??= _services[0];
|
||||
|
||||
var info = await service.GetNewTimerDefaultsAsync(cancellationToken, programInfo).ConfigureAwait(false);
|
||||
|
||||
|
||||
@@ -421,10 +421,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
||||
|
||||
string audioCodec = channelInfo.AudioCodec;
|
||||
|
||||
if (!videoBitrate.HasValue)
|
||||
{
|
||||
videoBitrate = isHd ? 15000000 : 2000000;
|
||||
}
|
||||
videoBitrate ??= isHd ? 15000000 : 2000000;
|
||||
|
||||
int? audioBitrate = isHd ? 448000 : 192000;
|
||||
|
||||
|
||||
@@ -44,12 +44,7 @@ namespace Emby.Server.Implementations.Plugins
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_httpClientFactory == null)
|
||||
{
|
||||
_httpClientFactory = _appHost.Resolve<IHttpClientFactory>();
|
||||
}
|
||||
|
||||
return _httpClientFactory;
|
||||
return _httpClientFactory ?? (_httpClientFactory = _appHost.Resolve<IHttpClientFactory>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,11 +271,7 @@ namespace Emby.Server.Implementations.Plugins
|
||||
// If no version is given, return the current instance.
|
||||
var plugins = _plugins.Where(p => p.Id.Equals(id)).ToList();
|
||||
|
||||
plugin = plugins.FirstOrDefault(p => p.Instance != null);
|
||||
if (plugin == null)
|
||||
{
|
||||
plugin = plugins.OrderByDescending(p => p.Version).FirstOrDefault();
|
||||
}
|
||||
plugin = plugins.FirstOrDefault(p => p.Instance != null) ?? plugins.OrderByDescending(p => p.Version).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -301,12 +301,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_id == null)
|
||||
{
|
||||
_id = ScheduledTask.GetType().FullName.GetMD5().ToString("N", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
return _id;
|
||||
return _id ??= ScheduledTask.GetType().FullName.GetMD5().ToString("N", CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1475,10 +1475,7 @@ namespace Emby.Server.Implementations.Session
|
||||
user = _userManager.GetUserById(request.UserId);
|
||||
}
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
user = _userManager.GetUserByName(request.Username);
|
||||
}
|
||||
user ??= _userManager.GetUserByName(request.Username);
|
||||
|
||||
if (enforcePassword)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user