mirror of
https://github.com/nextcloud/spreed.git
synced 2025-12-18 05:20:50 +01:00
Add an endpoint to return all participants of a room with its breakout rooms
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
def0f4f704
commit
6150cb402e
6 changed files with 101 additions and 10 deletions
|
|
@ -66,6 +66,8 @@ return [
|
|||
])],
|
||||
/** @see \OCA\Talk\Controller\RoomController::getParticipants() */
|
||||
['name' => 'Room#getParticipants', 'url' => '/api/{apiVersion}/room/{token}/participants', 'verb' => 'GET', 'requirements' => $requirementsWithToken],
|
||||
/** @see \OCA\Talk\Controller\RoomController::getBreakoutRoomParticipants() */
|
||||
['name' => 'Room#getBreakoutRoomParticipants', 'url' => '/api/{apiVersion}/room/{token}/breakout-rooms/participants', 'verb' => 'GET', 'requirements' => $requirementsWithToken],
|
||||
/** @see \OCA\Talk\Controller\RoomController::addParticipantToRoom() */
|
||||
['name' => 'Room#addParticipantToRoom', 'url' => '/api/{apiVersion}/room/{token}/participants', 'verb' => 'POST', 'requirements' => $requirementsWithToken],
|
||||
/** @see \OCA\Talk\Controller\RoomController::removeSelfFromRoom() */
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ Group and public conversations can be used to host breakout rooms.
|
|||
+ `403 Forbidden` When the current user is not a moderator/owner
|
||||
+ `404 Not Found` When the conversation could not be found for the participant
|
||||
- Data: Array of conversations (breakout rooms and parent)
|
||||
See array definition in `Get user´s conversations` (API v4)
|
||||
See array definition in [Get user´s conversations](conversation.md#get-user-s-conversations) (API v4)
|
||||
|
||||
## Remove breakout rooms
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ Group and public conversations can be used to host breakout rooms.
|
|||
+ `403 Forbidden` When the current user is not a moderator/owner
|
||||
+ `404 Not Found` When the conversation could not be found for the participant
|
||||
- Data: Parent conversation
|
||||
See array definition in `Get user´s conversations` (API v4)
|
||||
See array definition in [Get user´s conversations](conversation.md#get-user-s-conversations) (API v4)
|
||||
|
||||
## Start breakout rooms
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ Group and public conversations can be used to host breakout rooms.
|
|||
+ `403 Forbidden` When the current user is not a moderator/owner
|
||||
+ `404 Not Found` When the conversation could not be found for the participant
|
||||
- Data: Array of conversations (breakout rooms and parent)
|
||||
See array definition in `Get user´s conversations` (API v4)
|
||||
See array definition in [Get user´s conversations](conversation.md#get-user-s-conversations) (API v4)
|
||||
|
||||
## Stop breakout rooms
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ Group and public conversations can be used to host breakout rooms.
|
|||
+ `403 Forbidden` When the current user is not a moderator/owner
|
||||
+ `404 Not Found` When the conversation could not be found for the participant
|
||||
- Data: Array of conversations (breakout rooms and parent)
|
||||
See array definition in `Get user´s conversations` (API v4)
|
||||
See array definition in [Get user´s conversations](conversation.md#get-user-s-conversations) (API v4)
|
||||
|
||||
## Broadcast message to breakout rooms
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ Group and public conversations can be used to host breakout rooms.
|
|||
+ `404 Not Found` When the conversation could not be found for the participant
|
||||
+ `413 Payload Too Large` When the message was longer than the allowed limit of 32000 characters (check the `spreed => config => chat => max-length` capability for the limit)
|
||||
- Data: Array of conversations (breakout rooms and parent)
|
||||
See array definition in `Get user´s conversations` (API v4)
|
||||
See array definition in [Get user´s conversations](conversation.md#get-user-s-conversations) (API v4)
|
||||
|
||||
## Reorganize attendees
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ Group and public conversations can be used to host breakout rooms.
|
|||
+ `403 Forbidden` When the current user is not a moderator/owner
|
||||
+ `404 Not Found` When the conversation could not be found for the participant
|
||||
- Data: Array of conversations (breakout rooms and parent)
|
||||
See array definition in `Get user´s conversations` (API v4)
|
||||
See array definition in [Get user´s conversations](conversation.md#get-user-s-conversations) (API v4)
|
||||
|
||||
## Request assistance
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ This endpoint allows participants to raise their hand (token is the breakout roo
|
|||
+ `400 Bad Request` Error `room`: When the room is not a breakout room or breakout rooms are not started
|
||||
+ `404 Not Found` When the conversation could not be found for the participant
|
||||
- Data: Breakout room
|
||||
See array definition in `Get user´s conversations` (API v4)
|
||||
See array definition in [Get user´s conversations](conversation.md#get-user-s-conversations) (API v4)
|
||||
|
||||
## Reset request for assistance
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ This endpoint allows participants to raise their hand (token is the breakout roo
|
|||
+ `400 Bad Request` Error `room`: When the room is not a breakout room or breakout rooms are not started
|
||||
+ `404 Not Found` When the conversation could not be found for the participant
|
||||
- Data: Breakout room
|
||||
See array definition in `Get user´s conversations` (API v4)
|
||||
See array definition in [Get user´s conversations](conversation.md#get-user-s-conversations) (API v4)
|
||||
|
||||
## List all breakout rooms
|
||||
|
||||
|
|
@ -181,4 +181,4 @@ This endpoint allows participants to raise their hand (token is the breakout roo
|
|||
+ `400 Bad Request` Error `target`: When the target room is not breakout room of the parent
|
||||
+ `404 Not Found` When the conversation could not be found for the participant
|
||||
- Data: Target breakout room
|
||||
See array definition in `Get user´s conversations` (API v4)
|
||||
See array definition in [Get user´s conversations](conversation.md#get-user-s-conversations) (API v4)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,16 @@
|
|||
| `status` | string | v2 | | Optional: Only available with `includeStatus=true`, for users with a set status and when there are less than 100 participants in the conversation |
|
||||
| `statusIcon` | string | v2 | | Optional: Only available with `includeStatus=true`, for users with a set status and when there are less than 100 participants in the conversation |
|
||||
| `statusMessage` | string | v2 | | Optional: Only available with `includeStatus=true`, for users with a set status and when there are less than 100 participants in the conversation |
|
||||
| `roomToken` | string | v4 | | Optional: Only available with `breakout-rooms-v1` capability |
|
||||
|
||||
|
||||
## Get list of participants in a conversation including its breakout rooms
|
||||
|
||||
* Required capability: `breakout-rooms-v1`
|
||||
* Method: `GET`
|
||||
* Endpoint: `/room/{token}/breakout-rooms/participants`
|
||||
* Data: See Data in `Get list of participants in a conversations`
|
||||
* Response: See Response in `Get list of participants in a conversations`
|
||||
|
||||
## Add a participant to a conversation
|
||||
|
||||
|
|
|
|||
|
|
@ -699,9 +699,39 @@ class RoomController extends AEnvironmentAwareController {
|
|||
return new DataResponse([], Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
$maxPingAge = $this->timeFactory->getTime() - Session::SESSION_TIMEOUT_KILL;
|
||||
$participants = $this->participantService->getSessionsAndParticipantsForRoom($this->room);
|
||||
|
||||
return $this->formatParticipantList($participants, $includeStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @PublicPage
|
||||
* @RequireParticipant
|
||||
* @RequireModeratorOrNoLobby
|
||||
*
|
||||
* @param bool $includeStatus
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function getBreakoutRoomParticipants(bool $includeStatus = false): DataResponse {
|
||||
if ($this->participant->getAttendee()->getParticipantType() === Participant::GUEST) {
|
||||
return new DataResponse([], Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
$breakoutRooms = $this->breakoutRoomService->getBreakoutRooms($this->room, $this->participant);
|
||||
$breakoutRooms[] = $this->room;
|
||||
$participants = $this->participantService->getSessionsAndParticipantsForRooms($breakoutRooms);
|
||||
|
||||
return $this->formatParticipantList($participants, $includeStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Participant[] $participants
|
||||
* @param bool $includeStatus
|
||||
* @return DataResponse
|
||||
*/
|
||||
protected function formatParticipantList(array $participants, bool $includeStatus): DataResponse {
|
||||
$results = $headers = $statuses = [];
|
||||
$maxPingAge = $this->timeFactory->getTime() - Session::SESSION_TIMEOUT_KILL;
|
||||
|
||||
if ($this->userId !== null
|
||||
&& $includeStatus
|
||||
|
|
@ -747,6 +777,7 @@ class RoomController extends AEnvironmentAwareController {
|
|||
}
|
||||
|
||||
$result = [
|
||||
'roomToken' => $participant->getRoom()->getToken(),
|
||||
'inCall' => Participant::FLAG_DISCONNECTED,
|
||||
'lastPing' => 0,
|
||||
'sessionIds' => [],
|
||||
|
|
|
|||
|
|
@ -67,6 +67,10 @@ class Participant {
|
|||
$this->session = $session;
|
||||
}
|
||||
|
||||
public function getRoom(): Room {
|
||||
return $this->room;
|
||||
}
|
||||
|
||||
public function getAttendee(): Attendee {
|
||||
return $this->attendee;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1266,6 +1266,34 @@ class ParticipantService {
|
|||
return $this->getParticipantsFromQuery($query, $room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all sessions and attendees without a session for the room
|
||||
*
|
||||
* This will return multiple items for the same attendee if the attendee
|
||||
* has multiple sessions in the room.
|
||||
*
|
||||
* @param Room[] $rooms
|
||||
* @return Participant[]
|
||||
*/
|
||||
public function getSessionsAndParticipantsForRooms(array $rooms): array {
|
||||
$roomIds = array_map(static fn (Room $room) => $room->getId(), $rooms);
|
||||
$map = array_combine($roomIds, $rooms);
|
||||
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
|
||||
$helper = new SelectHelper();
|
||||
$helper->selectAttendeesTable($query);
|
||||
$helper->selectSessionsTable($query);
|
||||
$query->from('talk_attendees', 'a')
|
||||
->leftJoin(
|
||||
'a', 'talk_sessions', 's',
|
||||
$query->expr()->eq('s.attendee_id', 'a.id')
|
||||
)
|
||||
->where($query->expr()->in('a.room_id', $query->createNamedParameter($roomIds, IQueryBuilder::PARAM_INT_ARRAY)));
|
||||
|
||||
return $this->getParticipantsForRoomsFromQuery($query, $map);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param int $maxAge
|
||||
|
|
@ -1350,12 +1378,28 @@ class ParticipantService {
|
|||
|
||||
/**
|
||||
* @param IQueryBuilder $query
|
||||
* @param Room $room
|
||||
* @return Participant[]
|
||||
*/
|
||||
protected function getParticipantsFromQuery(IQueryBuilder $query, Room $room): array {
|
||||
return $this->getParticipantsForRoomsFromQuery($query, [$room->getId() => $room]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IQueryBuilder $query
|
||||
* @param Room[] $rooms Room ID => Room object
|
||||
* @psalm-param array<int, Room> $rooms
|
||||
* @return Participant[]
|
||||
*/
|
||||
protected function getParticipantsForRoomsFromQuery(IQueryBuilder $query, array $rooms): array {
|
||||
$participants = [];
|
||||
$result = $query->executeQuery();
|
||||
while ($row = $result->fetch()) {
|
||||
$room = $rooms[(int) $row['room_id']] ?? null;
|
||||
if ($room === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attendee = $this->attendeeMapper->createAttendeeFromRow($row);
|
||||
if (isset($row['s_id'])) {
|
||||
$session = $this->sessionMapper->createSessionFromRow($row);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue