make marking date played up to the caller to decide
This commit is contained in:
parent
842b95ea02
commit
0a7df60207
|
@ -184,6 +184,9 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
||||||
public Guid UserId { get; set; }
|
public Guid UserId { get; set; }
|
||||||
|
|
||||||
|
[ApiMember(Name = "DatePlayed", Description = "The date the item was played (if any)", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
|
||||||
|
public DateTime? DatePlayed { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the id.
|
/// Gets or sets the id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -630,7 +633,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
{
|
{
|
||||||
var user = _userManager.GetUserById(request.UserId);
|
var user = _userManager.GetUserById(request.UserId);
|
||||||
|
|
||||||
var task = UpdatePlayedStatus(user, request.Id, true);
|
var task = UpdatePlayedStatus(user, request.Id, true, request.DatePlayed);
|
||||||
|
|
||||||
return ToOptimizedResult(task.Result);
|
return ToOptimizedResult(task.Result);
|
||||||
}
|
}
|
||||||
|
@ -703,7 +706,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
{
|
{
|
||||||
var user = _userManager.GetUserById(request.UserId);
|
var user = _userManager.GetUserById(request.UserId);
|
||||||
|
|
||||||
var task = UpdatePlayedStatus(user, request.Id, false);
|
var task = UpdatePlayedStatus(user, request.Id, false, null);
|
||||||
|
|
||||||
return ToOptimizedResult(task.Result);
|
return ToOptimizedResult(task.Result);
|
||||||
}
|
}
|
||||||
|
@ -714,12 +717,20 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
/// <param name="user">The user.</param>
|
/// <param name="user">The user.</param>
|
||||||
/// <param name="itemId">The item id.</param>
|
/// <param name="itemId">The item id.</param>
|
||||||
/// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
|
/// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
|
||||||
|
/// <param name="datePlayed">The date played.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
private async Task<UserItemDataDto> UpdatePlayedStatus(User user, string itemId, bool wasPlayed)
|
private async Task<UserItemDataDto> UpdatePlayedStatus(User user, string itemId, bool wasPlayed, DateTime? datePlayed)
|
||||||
{
|
{
|
||||||
var item = _dtoService.GetItemByDtoId(itemId, user.Id);
|
var item = _dtoService.GetItemByDtoId(itemId, user.Id);
|
||||||
|
|
||||||
await item.SetPlayedStatus(user, wasPlayed, _userDataRepository).ConfigureAwait(false);
|
if (wasPlayed)
|
||||||
|
{
|
||||||
|
await item.MarkPlayed(user, datePlayed, _userDataRepository).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await item.MarkUnplayed(user, _userDataRepository).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
return _dtoService.GetUserItemDataDto(_userDataRepository.GetUserData(user.Id, item.GetUserDataKey()));
|
return _dtoService.GetUserItemDataDto(_userDataRepository.GetUserData(user.Id, item.GetUserDataKey()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1315,14 +1315,14 @@ namespace MediaBrowser.Controller.Entities
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Marks the item as either played or unplayed
|
/// Marks the played.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user">The user.</param>
|
/// <param name="user">The user.</param>
|
||||||
/// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
|
/// <param name="datePlayed">The date played.</param>
|
||||||
/// <param name="userManager">The user manager.</param>
|
/// <param name="userManager">The user manager.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
/// <exception cref="System.ArgumentNullException"></exception>
|
/// <exception cref="System.ArgumentNullException"></exception>
|
||||||
public virtual async Task SetPlayedStatus(User user, bool wasPlayed, IUserDataRepository userManager)
|
public virtual async Task MarkPlayed(User user, DateTime? datePlayed, IUserDataRepository userManager)
|
||||||
{
|
{
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
|
@ -1333,20 +1333,39 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
var data = userManager.GetUserData(user.Id, key);
|
var data = userManager.GetUserData(user.Id, key);
|
||||||
|
|
||||||
if (wasPlayed)
|
data.PlayCount = Math.Max(data.PlayCount, 1);
|
||||||
|
|
||||||
|
data.LastPlayedDate = datePlayed ?? data.LastPlayedDate;
|
||||||
|
data.Played = true;
|
||||||
|
|
||||||
|
await userManager.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks the unplayed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The user.</param>
|
||||||
|
/// <param name="userManager">The user manager.</param>
|
||||||
|
/// <returns>Task.</returns>
|
||||||
|
/// <exception cref="System.ArgumentNullException"></exception>
|
||||||
|
public virtual async Task MarkUnplayed(User user, IUserDataRepository userManager)
|
||||||
|
{
|
||||||
|
if (user == null)
|
||||||
{
|
{
|
||||||
data.PlayCount = Math.Max(data.PlayCount, 1);
|
throw new ArgumentNullException();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//I think it is okay to do this here.
|
|
||||||
// if this is only called when a user is manually forcing something to un-played
|
|
||||||
// then it probably is what we want to do...
|
|
||||||
data.PlayCount = 0;
|
|
||||||
data.PlaybackPositionTicks = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Played = wasPlayed;
|
var key = GetUserDataKey();
|
||||||
|
|
||||||
|
var data = userManager.GetUserData(user.Id, key);
|
||||||
|
|
||||||
|
//I think it is okay to do this here.
|
||||||
|
// if this is only called when a user is manually forcing something to un-played
|
||||||
|
// then it probably is what we want to do...
|
||||||
|
data.PlayCount = 0;
|
||||||
|
data.PlaybackPositionTicks = 0;
|
||||||
|
data.LastPlayedDate = null;
|
||||||
|
data.Played = false;
|
||||||
|
|
||||||
await userManager.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
|
await userManager.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1161,16 +1161,30 @@ namespace MediaBrowser.Controller.Entities
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Marks the item as either played or unplayed
|
/// Marks the played.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user">The user.</param>
|
/// <param name="user">The user.</param>
|
||||||
/// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
|
/// <param name="datePlayed">The date played.</param>
|
||||||
/// <param name="userManager">The user manager.</param>
|
/// <param name="userManager">The user manager.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
public override async Task SetPlayedStatus(User user, bool wasPlayed, IUserDataRepository userManager)
|
public override async Task MarkPlayed(User user, DateTime? datePlayed, IUserDataRepository userManager)
|
||||||
{
|
{
|
||||||
// Sweep through recursively and update status
|
// Sweep through recursively and update status
|
||||||
var tasks = GetRecursiveChildren(user, true).Where(i => !i.IsFolder).Select(c => c.SetPlayedStatus(user, wasPlayed, userManager));
|
var tasks = GetRecursiveChildren(user, true).Where(i => !i.IsFolder).Select(c => c.MarkPlayed(user, datePlayed, userManager));
|
||||||
|
|
||||||
|
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks the unplayed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user">The user.</param>
|
||||||
|
/// <param name="userManager">The user manager.</param>
|
||||||
|
/// <returns>Task.</returns>
|
||||||
|
public override async Task MarkUnplayed(User user, IUserDataRepository userManager)
|
||||||
|
{
|
||||||
|
// Sweep through recursively and update status
|
||||||
|
var tasks = GetRecursiveChildren(user, true).Where(i => !i.IsFolder).Select(c => c.MarkUnplayed(user, userManager));
|
||||||
|
|
||||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -453,18 +453,22 @@ namespace MediaBrowser.Model.ApiClient
|
||||||
Task<CountryInfo[]> GetCountriesAsync();
|
Task<CountryInfo[]> GetCountriesAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Marks an item as played or unplayed.
|
/// Marks the played async.
|
||||||
/// This should not be used to update playstate following playback.
|
|
||||||
/// There are separate playstate check-in methods for that. This should be used for a
|
|
||||||
/// separate option to reset playstate.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="itemId">The item id.</param>
|
/// <param name="itemId">The item id.</param>
|
||||||
/// <param name="userId">The user id.</param>
|
/// <param name="userId">The user id.</param>
|
||||||
/// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
|
/// <param name="datePlayed">The date played.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task{UserItemDataDto}.</returns>
|
||||||
/// <exception cref="ArgumentNullException">itemId</exception>
|
Task<UserItemDataDto> MarkPlayedAsync(string itemId, string userId, DateTime? datePlayed);
|
||||||
Task<UserItemDataDto> UpdatePlayedStatusAsync(string itemId, string userId, bool wasPlayed);
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks the unplayed async.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="itemId">The item id.</param>
|
||||||
|
/// <param name="userId">The user id.</param>
|
||||||
|
/// <returns>Task{UserItemDataDto}.</returns>
|
||||||
|
Task<UserItemDataDto> MarkUnplayedAsync(string itemId, string userId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the favorite status async.
|
/// Updates the favorite status async.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user