mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-23 21:47:14 -04:00
Return SyncPlay group info after creation, add GET group endpoint (#13935)
This commit is contained in:
parent
576f6d411a
commit
5e4bd744c0
3 changed files with 59 additions and 8 deletions
|
@ -100,7 +100,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
|||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void NewGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken)
|
||||
public GroupInfoDto NewGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (session is null)
|
||||
{
|
||||
|
@ -132,6 +132,7 @@ namespace Emby.Server.Implementations.SyncPlay
|
|||
|
||||
UpdateSessionsCounter(session.UserId, 1);
|
||||
group.CreateGroup(session, request, cancellationToken);
|
||||
return group.GetInfo();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,6 +289,31 @@ namespace Emby.Server.Implementations.SyncPlay
|
|||
return list;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public GroupInfoDto GetGroup(SessionInfo session, Guid groupId)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(session);
|
||||
|
||||
var user = _userManager.GetUserById(session.UserId);
|
||||
|
||||
lock (_groupsLock)
|
||||
{
|
||||
foreach (var (_, group) in _groups)
|
||||
{
|
||||
// Locking required as group is not thread-safe.
|
||||
lock (group)
|
||||
{
|
||||
if (group.GroupId.Equals(groupId) && group.HasAccessToPlayQueue(user))
|
||||
{
|
||||
return group.GetInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void HandleRequest(SessionInfo session, IGroupPlaybackRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Api.Constants;
|
||||
using Jellyfin.Api.Helpers;
|
||||
using Jellyfin.Api.Models.SyncPlayDtos;
|
||||
using MediaBrowser.Common.Api;
|
||||
|
@ -50,17 +50,16 @@ public class SyncPlayController : BaseJellyfinApiController
|
|||
/// </summary>
|
||||
/// <param name="requestData">The settings of the new group.</param>
|
||||
/// <response code="204">New group created.</response>
|
||||
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
|
||||
/// <returns>An <see cref="GroupInfoDto"/> for the created group.</returns>
|
||||
[HttpPost("New")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[Authorize(Policy = Policies.SyncPlayCreateGroup)]
|
||||
public async Task<ActionResult> SyncPlayCreateGroup(
|
||||
public async Task<ActionResult<GroupInfoDto>> SyncPlayCreateGroup(
|
||||
[FromBody, Required] NewGroupRequestDto requestData)
|
||||
{
|
||||
var currentSession = await RequestHelpers.GetSession(_sessionManager, _userManager, HttpContext).ConfigureAwait(false);
|
||||
var syncPlayRequest = new NewGroupRequest(requestData.GroupName);
|
||||
_syncPlayManager.NewGroup(currentSession, syncPlayRequest, CancellationToken.None);
|
||||
return NoContent();
|
||||
return Ok(_syncPlayManager.NewGroup(currentSession, syncPlayRequest, CancellationToken.None));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -112,6 +111,23 @@ public class SyncPlayController : BaseJellyfinApiController
|
|||
return Ok(_syncPlayManager.ListGroups(currentSession, syncPlayRequest).AsEnumerable());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a SyncPlay group by id.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the group.</param>
|
||||
/// <response code="200">Group returned.</response>
|
||||
/// <returns>An <see cref="GroupInfoDto"/> for the requested group.</returns>
|
||||
[HttpGet("{id:guid}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[Authorize(Policy = Policies.SyncPlayJoinGroup)]
|
||||
public async Task<ActionResult<GroupInfoDto>> SyncPlayGetGroup([FromRoute] Guid id)
|
||||
{
|
||||
var currentSession = await RequestHelpers.GetSession(_sessionManager, _userManager, HttpContext).ConfigureAwait(false);
|
||||
var group = _syncPlayManager.GetGroup(currentSession, id);
|
||||
return group == null ? NotFound() : Ok(group);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request to set new playlist in SyncPlay group.
|
||||
/// </summary>
|
||||
|
|
|
@ -20,7 +20,8 @@ namespace MediaBrowser.Controller.SyncPlay
|
|||
/// <param name="session">The session that's creating the group.</param>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
void NewGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken);
|
||||
/// <returns>The newly created group.</returns>
|
||||
GroupInfoDto NewGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the session to a group.
|
||||
|
@ -46,6 +47,14 @@ namespace MediaBrowser.Controller.SyncPlay
|
|||
/// <returns>The list of available groups.</returns>
|
||||
List<GroupInfoDto> ListGroups(SessionInfo session, ListGroupsRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Gets available groups for a session by id.
|
||||
/// </summary>
|
||||
/// <param name="session">The session.</param>
|
||||
/// <param name="groupId">The group id.</param>
|
||||
/// <returns>The groups or null.</returns>
|
||||
GroupInfoDto GetGroup(SessionInfo session, Guid groupId);
|
||||
|
||||
/// <summary>
|
||||
/// Handle a request by a session in a group.
|
||||
/// </summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue