Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable nullable for UserItemData #11390

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ public List<UserItemData> GetAllUserData(long userId)
/// <returns>The user item data.</returns>
private UserItemData ReadRow(SqliteDataReader reader)
{
var userData = new UserItemData();

userData.Key = reader[0].ToString();
// userData.UserId = reader[1].ReadGuidFromBlob();
var userData = new UserItemData
{
Key = reader.GetString(0)
};

if (reader.TryGetDouble(2, out var rating))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -138,13 +137,13 @@ private UserDataChangeInfo GetUserDataChangeInfo(Guid userId, List<BaseItem> cha

return new UserDataChangeInfo
{
UserId = userId.ToString("N", CultureInfo.InvariantCulture),
UserId = userId,
UserDataList = changedItems
.DistinctBy(x => x.Id)
.Select(i =>
{
var dto = _userDataManager.GetUserDataDto(i, user);
dto.ItemId = i.Id.ToString("N", CultureInfo.InvariantCulture);
dto.ItemId = i.Id;
return dto;
})
.ToArray()
Expand Down
7 changes: 4 additions & 3 deletions Emby.Server.Implementations/Library/MediaSourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ private IReadOnlyList<string> NormalizeLanguage(string language)

private void SetDefaultSubtitleStreamIndex(MediaSourceInfo source, UserItemData userData, User user, bool allowRememberingSelection)
{
if (userData.SubtitleStreamIndex.HasValue
if (userData is not null
&& userData.SubtitleStreamIndex.HasValue
&& user.RememberSubtitleSelections
&& user.SubtitleMode != SubtitlePlaybackMode.None
&& allowRememberingSelection)
Expand Down Expand Up @@ -406,7 +407,7 @@ private void SetDefaultSubtitleStreamIndex(MediaSourceInfo source, UserItemData

private void SetDefaultAudioStreamIndex(MediaSourceInfo source, UserItemData userData, User user, bool allowRememberingSelection)
{
if (userData.AudioStreamIndex.HasValue && user.RememberAudioSelections && allowRememberingSelection)
if (userData is not null && userData.AudioStreamIndex.HasValue && user.RememberAudioSelections && allowRememberingSelection)
{
var index = userData.AudioStreamIndex.Value;
// Make sure the saved index is still valid
Expand All @@ -429,7 +430,7 @@ public void SetDefaultAudioAndSubtitleStreamIndices(BaseItem item, MediaSourceIn

if (mediaType == MediaType.Video)
{
var userData = item is null ? new UserItemData() : _userDataManager.GetUserData(user, item);
var userData = item is null ? null : _userDataManager.GetUserData(user, item);

var allowRememberingSelection = item is null || item.EnableRememberingTrackSelections;

Expand Down
10 changes: 1 addition & 9 deletions MediaBrowser.Controller/Entities/UserItemData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#nullable disable

#pragma warning disable CS1591

using System;
Expand All @@ -19,17 +17,11 @@ public class UserItemData
/// </summary>
private double? _rating;

/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
public Guid UserId { get; set; }

/// <summary>
/// Gets or sets the key.
/// </summary>
/// <value>The key.</value>
public string Key { get; set; }
public required string Key { get; set; }

/// <summary>
/// Gets or sets the users 0-10 rating.
Expand Down
31 changes: 0 additions & 31 deletions MediaBrowser.Controller/Providers/MetadataResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

#pragma warning disable CA1002, CA2227, CS1591

using System;
using System.Collections.Generic;
using System.Globalization;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;

Expand Down Expand Up @@ -33,8 +31,6 @@ public List<LocalImageInfo> Images
set => _remoteImages = value;
}

public List<UserItemData> UserDataList { get; set; }

public List<PersonInfo> People { get; set; }

public bool HasMetadata { get; set; }
Expand Down Expand Up @@ -68,32 +64,5 @@ public void ResetPeople()
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 is null)
{
userData = new UserItemData()
{
UserId = new Guid(userId)
};

UserDataList.Add(userData);
}

return userData;
}
}
}
5 changes: 2 additions & 3 deletions MediaBrowser.Model/Dto/UserItemDataDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#nullable disable
using System;

namespace MediaBrowser.Model.Dto
Expand Down Expand Up @@ -66,12 +65,12 @@ public class UserItemDataDto
/// Gets or sets the key.
/// </summary>
/// <value>The key.</value>
public string Key { get; set; }
public required string Key { get; set; }

/// <summary>
/// Gets or sets the item identifier.
/// </summary>
/// <value>The item identifier.</value>
public string ItemId { get; set; }
public Guid ItemId { get; set; }
}
}
6 changes: 3 additions & 3 deletions MediaBrowser.Model/Session/UserDataChangeInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable disable
using System;
using MediaBrowser.Model.Dto;

namespace MediaBrowser.Model.Session
Expand All @@ -12,12 +12,12 @@ public class UserDataChangeInfo
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
public string UserId { get; set; }
public Guid UserId { get; set; }

/// <summary>
/// Gets or sets the user data list.
/// </summary>
/// <value>The user data list.</value>
public UserItemDataDto[] UserDataList { get; set; }
public required UserItemDataDto[] UserDataList { get; set; }
}
}
5 changes: 0 additions & 5 deletions MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ protected override void Fetch(MetadataResult<T> result, string path, Cancellatio
result.People = tmpItem.People;
result.Images = tmpItem.Images;
result.RemoteImages = tmpItem.RemoteImages;

if (tmpItem.UserDataList is not null)
{
result.UserDataList = tmpItem.UserDataList;
}
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public MovieNfoParserTests()

var userData = new Mock<IUserDataManager>();
userData.Setup(x => x.GetUserData(_testUser, It.IsAny<BaseItem>()))
.Returns(new UserItemData());
.Returns(new UserItemData()
{
Key = "Something"
});

var directoryService = new Mock<IDirectoryService>();
_localImageFileMetadata = new FileSystemMetadata()
Expand Down