Enable nullable for DtoService and DtoOptions

This commit is contained in:
Bond_009 2024-04-25 12:42:10 +02:00
parent eeb8c59ff2
commit 2b3ebb0751
3 changed files with 34 additions and 32 deletions

View file

@ -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;
/// <inheritdoc />
public IReadOnlyList<BaseItemDto> GetBaseItemDtos(IReadOnlyList<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null)
public IReadOnlyList<BaseItemDto> GetBaseItemDtos(IReadOnlyList<BaseItem> 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<BaseItem> GetTaggedItems(IItemByName byName, User user, DtoOptions options)
private static IList<BaseItem> 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<BaseItem> taggedItems, User user = null)
/// <inheritdoc />
public BaseItemDto GetItemByNameDto(BaseItem item, DtoOptions options, List<BaseItem>? 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
/// <param name="dto">The dto.</param>
/// <param name="item">The item.</param>
/// <param name="user">The requesting user.</param>
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<BaseItemPerson>();
var dictionary = people.Select(p => p.Name)
Dictionary<string, Person> 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<ImageType, Dictionary<string, string>>();
@ -716,7 +720,7 @@ namespace Emby.Server.Implementations.Dto
/// <param name="item">The item.</param>
/// <param name="owner">The owner.</param>
/// <param name="options">The options.</param>
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))
{
@ -1097,7 +1101,7 @@ namespace Emby.Server.Implementations.Dto
}
}
BaseItem[] allExtras = null;
BaseItem[]? allExtras = null;
if (options.ContainsField(ItemFields.SpecialFeatureCount))
{
@ -1134,7 +1138,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
@ -1162,8 +1166,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();
@ -1264,7 +1270,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)
{
@ -1285,7 +1291,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)
{
@ -1305,7 +1311,7 @@ namespace Emby.Server.Implementations.Dto
return;
}
BaseItem parent = null;
BaseItem? parent = null;
var isFirst = true;
var imageTags = dto.ImageTags;
@ -1378,7 +1384,7 @@ namespace Emby.Server.Implementations.Dto
}
}
private string GetMappedPath(BaseItem item, BaseItem ownerItem)
private string GetMappedPath(BaseItem item, BaseItem? ownerItem)
{
var path = item.Path;

View file

@ -26,8 +26,6 @@ public static class DtoExtensions
internal static DtoOptions AddClientFields(
this DtoOptions dtoOptions, ClaimsPrincipal user)
{
dtoOptions.Fields ??= Array.Empty<ItemFields>();
string? client = user.GetClient();
// No client in claim

View file

@ -1,5 +1,3 @@
#nullable disable
#pragma warning disable CS1591
using System;