|
|
@ -54,7 +54,7 @@ namespace Jellyfin.Server.Implementations.Devices
|
|
|
|
var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
|
|
|
|
var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
|
|
|
|
await using (dbContext.ConfigureAwait(false))
|
|
|
|
await using (dbContext.ConfigureAwait(false))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
deviceOptions = await dbContext.DeviceOptions.AsQueryable().FirstOrDefaultAsync(dev => dev.DeviceId == deviceId).ConfigureAwait(false);
|
|
|
|
deviceOptions = await dbContext.DeviceOptions.FirstOrDefaultAsync(dev => dev.DeviceId == deviceId).ConfigureAwait(false);
|
|
|
|
if (deviceOptions is null)
|
|
|
|
if (deviceOptions is null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
deviceOptions = new DeviceOptions(deviceId);
|
|
|
|
deviceOptions = new DeviceOptions(deviceId);
|
|
|
@ -132,22 +132,11 @@ namespace Jellyfin.Server.Implementations.Devices
|
|
|
|
var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
|
|
|
|
var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
|
|
|
|
await using (dbContext.ConfigureAwait(false))
|
|
|
|
await using (dbContext.ConfigureAwait(false))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var devices = dbContext.Devices.AsQueryable();
|
|
|
|
var devices = dbContext.Devices
|
|
|
|
|
|
|
|
.OrderBy(d => d.Id)
|
|
|
|
if (query.UserId.HasValue)
|
|
|
|
.Where(device => !query.UserId.HasValue || device.UserId.Equals(query.UserId.Value))
|
|
|
|
{
|
|
|
|
.Where(device => query.DeviceId == null || device.DeviceId == query.DeviceId)
|
|
|
|
devices = devices.Where(device => device.UserId.Equals(query.UserId.Value));
|
|
|
|
.Where(device => query.AccessToken == null || device.AccessToken == query.AccessToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (query.DeviceId is not null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
devices = devices.Where(device => device.DeviceId == query.DeviceId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (query.AccessToken is not null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
devices = devices.Where(device => device.AccessToken == query.AccessToken);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var count = await devices.CountAsync().ConfigureAwait(false);
|
|
|
|
var count = await devices.CountAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
@ -179,11 +168,10 @@ namespace Jellyfin.Server.Implementations.Devices
|
|
|
|
/// <inheritdoc />
|
|
|
|
/// <inheritdoc />
|
|
|
|
public async Task<QueryResult<DeviceInfo>> GetDevicesForUser(Guid? userId, bool? supportsSync)
|
|
|
|
public async Task<QueryResult<DeviceInfo>> GetDevicesForUser(Guid? userId, bool? supportsSync)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IAsyncEnumerable<Device> sessions;
|
|
|
|
|
|
|
|
var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
|
|
|
|
var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
|
|
|
|
await using (dbContext.ConfigureAwait(false))
|
|
|
|
await using (dbContext.ConfigureAwait(false))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sessions = dbContext.Devices
|
|
|
|
IAsyncEnumerable<Device> sessions = dbContext.Devices
|
|
|
|
.Include(d => d.User)
|
|
|
|
.Include(d => d.User)
|
|
|
|
.OrderByDescending(d => d.DateLastActivity)
|
|
|
|
.OrderByDescending(d => d.DateLastActivity)
|
|
|
|
.ThenBy(d => d.DeviceId)
|
|
|
|
.ThenBy(d => d.DeviceId)
|
|
|
|