From 8ca7a2358028e94ced8495415d849d52b22e0e83 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Thu, 25 Apr 2024 12:42:10 +0200 Subject: [PATCH] Enable nullable for DtoService and DtoOptions --- Emby.Server.Implementations/Dto/DtoService.cs | 62 ++++++++++--------- Jellyfin.Api/Extensions/DtoExtensions.cs | 2 - MediaBrowser.Controller/Dto/DtoOptions.cs | 2 - 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index 98eacb52b2..36872394c6 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -1,5 +1,3 @@ -#nullable disable - #pragma warning disable CS1591 using System; @@ -83,12 +81,12 @@ namespace Emby.Server.Implementations.Dto private ILiveTvManager LivetvManager => _livetvManagerFactory.Value; /// - public IReadOnlyList GetBaseItemDtos(IReadOnlyList items, DtoOptions options, User user = null, BaseItem owner = null) + public IReadOnlyList GetBaseItemDtos(IReadOnlyList items, DtoOptions options, User? user = null, BaseItem? owner = null) { var accessibleItems = user is null ? items : items.Where(x => x.IsVisible(user)).ToList(); var returnItems = new BaseItemDto[accessibleItems.Count]; - List<(BaseItem, BaseItemDto)> programTuples = null; - List<(BaseItemDto, LiveTvChannel)> channelTuples = null; + List<(BaseItem, BaseItemDto)>? programTuples = null; + List<(BaseItemDto, LiveTvChannel)>? channelTuples = null; for (int index = 0; index < accessibleItems.Count; index++) { @@ -137,7 +135,7 @@ namespace Emby.Server.Implementations.Dto return returnItems; } - public BaseItemDto GetBaseItemDto(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null) + public BaseItemDto GetBaseItemDto(BaseItem item, DtoOptions options, User? user = null, BaseItem? owner = null) { var dto = GetBaseItemDtoInternal(item, options, user, owner); if (item is LiveTvChannel tvChannel) @@ -167,7 +165,7 @@ namespace Emby.Server.Implementations.Dto return dto; } - private static IList GetTaggedItems(IItemByName byName, User user, DtoOptions options) + private static IList GetTaggedItems(IItemByName byName, User? user, DtoOptions options) { return byName.GetTaggedItems( new InternalItemsQuery(user) @@ -177,7 +175,7 @@ namespace Emby.Server.Implementations.Dto }); } - private BaseItemDto GetBaseItemDtoInternal(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null) + private BaseItemDto GetBaseItemDtoInternal(BaseItem item, DtoOptions options, User? user = null, BaseItem? owner = null) { var dto = new BaseItemDto { @@ -292,7 +290,7 @@ namespace Emby.Server.Implementations.Dto } var path = mediaSource.Path; - string fileExtensionContainer = null; + string? fileExtensionContainer = null; if (!string.IsNullOrEmpty(path)) { @@ -316,7 +314,8 @@ namespace Emby.Server.Implementations.Dto } } - public BaseItemDto GetItemByNameDto(BaseItem item, DtoOptions options, List taggedItems, User user = null) + /// + public BaseItemDto GetItemByNameDto(BaseItem item, DtoOptions options, List? taggedItems, User? user = null) { var dto = GetBaseItemDtoInternal(item, options, user); @@ -486,10 +485,10 @@ namespace Emby.Server.Implementations.Dto return images .Select(p => GetImageCacheTag(item, p)) .Where(i => i is not null) - .ToArray(); + .ToArray()!; // null values got filtered out } - private string GetImageCacheTag(BaseItem item, ItemImageInfo image) + private string? GetImageCacheTag(BaseItem item, ItemImageInfo image) { try { @@ -508,7 +507,7 @@ namespace Emby.Server.Implementations.Dto /// The dto. /// The item. /// The requesting user. - private void AttachPeople(BaseItemDto dto, BaseItem item, User user = null) + private void AttachPeople(BaseItemDto dto, BaseItem item, User? user = null) { // Ordering by person type to ensure actors and artists are at the front. // This is taking advantage of the fact that they both begin with A @@ -552,7 +551,7 @@ namespace Emby.Server.Implementations.Dto var list = new List(); - var dictionary = people.Select(p => p.Name) + Dictionary dictionary = people.Select(p => p.Name) .Distinct(StringComparer.OrdinalIgnoreCase).Select(c => { try @@ -565,9 +564,9 @@ namespace Emby.Server.Implementations.Dto return null; } }).Where(i => i is not null) - .Where(i => user is null || i.IsVisible(user)) - .DistinctBy(x => x.Name, StringComparer.OrdinalIgnoreCase) - .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase); + .Where(i => user is null || i!.IsVisible(user)) + .DistinctBy(x => x!.Name, StringComparer.OrdinalIgnoreCase) + .ToDictionary(i => i!.Name, StringComparer.OrdinalIgnoreCase)!; // null values got filtered out for (var i = 0; i < people.Count; i++) { @@ -580,7 +579,7 @@ namespace Emby.Server.Implementations.Dto Type = person.Type }; - if (dictionary.TryGetValue(person.Name, out Person entity)) + if (dictionary.TryGetValue(person.Name, out Person? entity)) { baseItemPerson.PrimaryImageTag = GetTagAndFillBlurhash(dto, entity, ImageType.Primary); baseItemPerson.Id = entity.Id; @@ -650,7 +649,7 @@ namespace Emby.Server.Implementations.Dto return _libraryManager.GetGenreId(name); } - private string GetTagAndFillBlurhash(BaseItemDto dto, BaseItem item, ImageType imageType, int imageIndex = 0) + private string? GetTagAndFillBlurhash(BaseItemDto dto, BaseItem item, ImageType imageType, int imageIndex = 0) { var image = item.GetImageInfo(imageType, imageIndex); if (image is not null) @@ -661,9 +660,14 @@ namespace Emby.Server.Implementations.Dto return null; } - private string GetTagAndFillBlurhash(BaseItemDto dto, BaseItem item, ItemImageInfo image) + private string? GetTagAndFillBlurhash(BaseItemDto dto, BaseItem item, ItemImageInfo image) { var tag = GetImageCacheTag(item, image); + if (tag is null) + { + return null; + } + if (!string.IsNullOrEmpty(image.BlurHash)) { dto.ImageBlurHashes ??= new Dictionary>(); @@ -716,7 +720,7 @@ namespace Emby.Server.Implementations.Dto /// The item. /// The owner. /// The options. - private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem owner, DtoOptions options) + private void AttachBasicFields(BaseItemDto dto, BaseItem item, BaseItem? owner, DtoOptions options) { if (options.ContainsField(ItemFields.DateCreated)) { @@ -1089,7 +1093,7 @@ namespace Emby.Server.Implementations.Dto } } - BaseItem[] allExtras = null; + BaseItem[]? allExtras = null; if (options.ContainsField(ItemFields.SpecialFeatureCount)) { @@ -1126,7 +1130,7 @@ namespace Emby.Server.Implementations.Dto dto.SeasonId = episode.SeasonId; dto.SeriesId = episode.SeriesId; - Series episodeSeries = null; + Series? episodeSeries = null; // this block will add the series poster for episodes without a poster // TODO maybe remove the if statement entirely @@ -1154,8 +1158,10 @@ namespace Emby.Server.Implementations.Dto } // Add SeriesInfo - if (item is Series series) + Series? series; + if (item is Series tmp) { + series = tmp; dto.AirDays = series.AirDays; dto.AirTime = series.AirTime; dto.Status = series.Status?.ToString(); @@ -1256,7 +1262,7 @@ namespace Emby.Server.Implementations.Dto } } - private BaseItem GetImageDisplayParent(BaseItem currentItem, BaseItem originalItem) + private BaseItem? GetImageDisplayParent(BaseItem currentItem, BaseItem originalItem) { if (currentItem is MusicAlbum musicAlbum) { @@ -1277,7 +1283,7 @@ namespace Emby.Server.Implementations.Dto return parent; } - private void AddInheritedImages(BaseItemDto dto, BaseItem item, DtoOptions options, BaseItem owner) + private void AddInheritedImages(BaseItemDto dto, BaseItem item, DtoOptions options, BaseItem? owner) { if (!item.SupportsInheritedParentImages) { @@ -1297,7 +1303,7 @@ namespace Emby.Server.Implementations.Dto return; } - BaseItem parent = null; + BaseItem? parent = null; var isFirst = true; var imageTags = dto.ImageTags; @@ -1370,7 +1376,7 @@ namespace Emby.Server.Implementations.Dto } } - private string GetMappedPath(BaseItem item, BaseItem ownerItem) + private string GetMappedPath(BaseItem item, BaseItem? ownerItem) { var path = item.Path; diff --git a/Jellyfin.Api/Extensions/DtoExtensions.cs b/Jellyfin.Api/Extensions/DtoExtensions.cs index 7d9823c25c..aeac1ef6b8 100644 --- a/Jellyfin.Api/Extensions/DtoExtensions.cs +++ b/Jellyfin.Api/Extensions/DtoExtensions.cs @@ -26,8 +26,6 @@ public static class DtoExtensions internal static DtoOptions AddClientFields( this DtoOptions dtoOptions, ClaimsPrincipal user) { - dtoOptions.Fields ??= Array.Empty(); - string? client = user.GetClient(); // No client in claim diff --git a/MediaBrowser.Controller/Dto/DtoOptions.cs b/MediaBrowser.Controller/Dto/DtoOptions.cs index ecc833154d..cb638cf90b 100644 --- a/MediaBrowser.Controller/Dto/DtoOptions.cs +++ b/MediaBrowser.Controller/Dto/DtoOptions.cs @@ -1,5 +1,3 @@ -#nullable disable - #pragma warning disable CS1591 using System;