implement sync item removals
This commit is contained in:
parent
8d10ee581c
commit
5e6354854d
|
@ -1,4 +1,5 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MediaBrowser.Model.Sync
|
||||
{
|
||||
public class SyncJobItemQuery
|
||||
|
@ -27,6 +28,11 @@ namespace MediaBrowser.Model.Sync
|
|||
/// Gets or sets the status.
|
||||
/// </summary>
|
||||
/// <value>The status.</value>
|
||||
public SyncJobItemStatus? Status { get; set; }
|
||||
public List<SyncJobItemStatus> Statuses { get; set; }
|
||||
|
||||
public SyncJobItemQuery()
|
||||
{
|
||||
Statuses = new List<SyncJobItemStatus>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
"TitleMediaBrowser": "Media Browser",
|
||||
"ThisWizardWillGuideYou": "This wizard will help guide you through the setup process. To begin, please select your preferred language.",
|
||||
"TellUsAboutYourself": "Tell us about yourself",
|
||||
"ButtonQuickStartGuide": "Quick start guide",
|
||||
"LabelYourFirstName": "Your first name:",
|
||||
"MoreUsersCanBeAddedLater": "More users can be added later within the Dashboard.",
|
||||
"UserProfilesIntro": "Media Browser includes built-in support for user profiles, enabling each user to have their own display settings, playstate and parental controls.",
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
// Respect ItemLimit, if set
|
||||
if (job.ItemLimit.HasValue)
|
||||
{
|
||||
if (jobItems.Count >= job.ItemLimit.Value)
|
||||
if (jobItems.Count(j => j.Status != SyncJobItemStatus.RemovedFromDevice && j.Status != SyncJobItemStatus.Failed) >= job.ItemLimit.Value)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -310,9 +310,10 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
{
|
||||
await EnsureSyncJobs(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// If it already has a converting status then is must have been aborted during conversion
|
||||
var result = _syncRepo.GetJobItems(new SyncJobItemQuery
|
||||
{
|
||||
Status = SyncJobItemStatus.Queued
|
||||
Statuses = new List<SyncJobItemStatus> { SyncJobItemStatus.Queued, SyncJobItemStatus.Converting }
|
||||
});
|
||||
|
||||
var jobItems = result.Items;
|
||||
|
@ -327,10 +328,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (item.Status == SyncJobItemStatus.Queued)
|
||||
{
|
||||
await ProcessJobItem(item, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
await ProcessJobItem(item, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var job = _syncRepo.GetJob(item.JobId);
|
||||
await UpdateJobStatus(job).ConfigureAwait(false);
|
||||
|
|
|
@ -392,7 +392,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
var jobItemResult = GetJobItems(new SyncJobItemQuery
|
||||
{
|
||||
TargetId = targetId,
|
||||
Status = SyncJobItemStatus.Transferring
|
||||
Statuses = new List<SyncJobItemStatus> { SyncJobItemStatus.Transferring }
|
||||
});
|
||||
|
||||
return jobItemResult.Items.Select(GetJobItemInfo)
|
||||
|
@ -404,21 +404,65 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
var jobItemResult = GetJobItems(new SyncJobItemQuery
|
||||
{
|
||||
TargetId = request.TargetId,
|
||||
Status = SyncJobItemStatus.Synced
|
||||
Statuses = new List<SyncJobItemStatus> { SyncJobItemStatus.Synced }
|
||||
});
|
||||
|
||||
var response = new SyncDataResponse();
|
||||
|
||||
foreach (var jobItem in jobItemResult.Items)
|
||||
{
|
||||
if (!request.LocalItemIds.Contains(jobItem.ItemId, StringComparer.OrdinalIgnoreCase))
|
||||
if (request.LocalItemIds.Contains(jobItem.ItemId, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
var job = _repo.GetJob(jobItem.JobId);
|
||||
var user = _userManager.GetUserById(job.UserId);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
// Tell the device to remove it since the user is gone now
|
||||
response.ItemIdsToRemove.Add(jobItem.ItemId);
|
||||
}
|
||||
else if (job.UnwatchedOnly)
|
||||
{
|
||||
var libraryItem = _libraryManager.GetItemById(jobItem.ItemId);
|
||||
|
||||
if (IsLibraryItemAvailable(libraryItem))
|
||||
{
|
||||
if (libraryItem.IsPlayed(user) && libraryItem is Video)
|
||||
{
|
||||
// Tell the device to remove it since it has been played
|
||||
response.ItemIdsToRemove.Add(jobItem.ItemId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Tell the device to remove it since it's no longer available
|
||||
response.ItemIdsToRemove.Add(jobItem.ItemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Content is no longer on the device
|
||||
jobItem.Status = SyncJobItemStatus.RemovedFromDevice;
|
||||
await _repo.Update(jobItem).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
var response = new SyncDataResponse();
|
||||
|
||||
response.ItemIdsToRemove = response.ItemIdsToRemove.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private bool IsLibraryItemAvailable(BaseItem item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Make sure it hasn't been deleted
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -467,10 +467,11 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
cmd.Parameters.Add(cmd, "@TargetId", DbType.String).Value = query.TargetId;
|
||||
}
|
||||
|
||||
if (query.Status.HasValue)
|
||||
if (query.Statuses.Count > 0)
|
||||
{
|
||||
whereClauses.Add("Status=@Status");
|
||||
cmd.Parameters.Add(cmd, "@Status", DbType.String).Value = query.Status.Value.ToString();
|
||||
var statuses = string.Join(",", query.Statuses.Select(i => "'" + i.ToString() + "'").ToArray());
|
||||
|
||||
whereClauses.Add(string.Format("Status in ({0})", statuses));
|
||||
}
|
||||
|
||||
var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
||||
|
|
|
@ -216,15 +216,9 @@
|
|||
<Content Include="dashboard-ui\css\images\icons\remote.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="dashboard-ui\css\images\items\folders\edit.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="dashboard-ui\css\images\items\folders\home.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="dashboard-ui\css\images\items\folders\report.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="dashboard-ui\css\images\icons\audiocd.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
Loading…
Reference in New Issue
Block a user