This commit is contained in:
Sam Jongenelen 2024-04-25 07:15:35 -06:00 committed by GitHub
commit 86b5db2fa9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 2 deletions

View File

@ -55,6 +55,7 @@ public class SessionController : BaseJellyfinApiController
/// <param name="controllableByUserId">Filter by sessions that a given user is allowed to remote control.</param>
/// <param name="deviceId">Filter by device Id.</param>
/// <param name="activeWithinSeconds">Optional. Filter by sessions that were active in the last n seconds.</param>
/// <param name="nowPlaying">Optional. Filter by sessions that are currently playing content.</param>
/// <response code="200">List of sessions returned.</response>
/// <returns>An <see cref="IEnumerable{SessionInfo}"/> with the available sessions.</returns>
[HttpGet("Sessions")]
@ -63,7 +64,8 @@ public class SessionController : BaseJellyfinApiController
public ActionResult<IEnumerable<SessionInfo>> GetSessions(
[FromQuery] Guid? controllableByUserId,
[FromQuery] string? deviceId,
[FromQuery] int? activeWithinSeconds)
[FromQuery] int? activeWithinSeconds,
[FromQuery] bool? nowPlaying)
{
var result = _sessionManager.Sessions;
@ -118,6 +120,13 @@ public class SessionController : BaseJellyfinApiController
result = result.Where(i => i.LastActivityDate >= minActiveDate);
}
if (nowPlaying.HasValue)
{
result = nowPlaying.Value
? result.Where(i => i.NowPlayingItem != null)
: result.Where(i => i.NowPlayingItem == null);
}
return Ok(result);
}

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Net;
using System.Threading.Tasks;
using Xunit;
@ -24,4 +24,18 @@ public class SessionControllerTests : IClassFixture<JellyfinApplicationFactory>
using var response = await client.GetAsync($"Sessions?controllableByUserId={Guid.NewGuid()}");
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
[Theory]
[InlineData("?nowPlaying=false")]
[InlineData("?nowPlaying=true")]
[InlineData("")]
public async Task GetSessions_NowPlaying_Ok(string querystring)
{
var client = _factory.CreateClient();
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
using var response = await client.GetAsync($"Sessions{querystring}").ConfigureAwait(false);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}