mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-01 22:36:33 +01:00
Refactored api call logic handling.
This commit is contained in:
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Jellyfin.Data.Entities;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
@@ -81,6 +82,42 @@ namespace Emby.Server.Implementations.Library
|
||||
});
|
||||
}
|
||||
|
||||
public void SaveUserData(User user, BaseItem item, UserDataDto userDataDto, UserDataSaveReason reason)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(user);
|
||||
ArgumentNullException.ThrowIfNull(item);
|
||||
ArgumentNullException.ThrowIfNull(reason);
|
||||
ArgumentNullException.ThrowIfNull(userDataDto);
|
||||
|
||||
var userData = GetUserData(user, item);
|
||||
|
||||
var parentProperties = userDataDto.GetType().GetProperties();
|
||||
var childProperties = userData.GetType().GetProperties();
|
||||
|
||||
foreach (var parentProperty in parentProperties)
|
||||
{
|
||||
foreach (var childProperty in childProperties)
|
||||
{
|
||||
if (parentProperty.Name != childProperty.Name)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var value = parentProperty.GetValue(userDataDto, null);
|
||||
|
||||
if (value is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
childProperty.SetValue(userData, value, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SaveUserData(user, item, userData, reason, CancellationToken.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save the provided user data for the given user. Batch operation. Does not fire any events or update the cache.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user