jellyfin/MediaBrowser.Controller/Providers/MetadataResult.cs
BaronGreenback 2e98de9062
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>
2021-05-05 13:51:14 +02:00

88 lines
2.2 KiB
C#

#pragma warning disable CS1591
using System;
using System.Collections.Generic;
using System.Globalization;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Providers
{
public class MetadataResult<T>
{
public MetadataResult()
{
Images = new List<LocalImageInfo>();
RemoteImages = new List<(string url, ImageType type)>();
ResultLanguage = "en";
}
public List<LocalImageInfo> Images { get; set; }
public List<(string url, ImageType type)> RemoteImages { get; set; }
public List<UserItemData> UserDataList { get; set; }
public List<PersonInfo> People { get; set; }
public bool HasMetadata { get; set; }
public T Item { get; set; }
public string ResultLanguage { get; set; }
public string Provider { get; set; }
public bool QueriedById { get; set; }
public void AddPerson(PersonInfo p)
{
People ??= new List<PersonInfo>();
PeopleHelper.AddPerson(People, p);
}
/// <summary>
/// Not only does this clear, but initializes the list so that services can differentiate between a null list and zero people.
/// </summary>
public void ResetPeople()
{
if (People == null)
{
People = new List<PersonInfo>();
}
else
{
People.Clear();
}
}
public UserItemData GetOrAddUserData(string userId)
{
UserDataList ??= new List<UserItemData>();
UserItemData userData = null;
foreach (var i in UserDataList)
{
if (string.Equals(userId, i.UserId.ToString("N", CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase))
{
userData = i;
}
}
if (userData == null)
{
userData = new UserItemData()
{
UserId = new Guid(userId)
};
UserDataList.Add(userData);
}
return userData;
}
}
}