private async Task <Participant> RetrieveLastParticipantIfLinkedAndLeftAlone(Conference conference, Participant participant, string fromRoomLabel) { if (participant.GetParticipantRoom() != null) { return(null); } var roomQuery = new GetConsultationRoomByIdQuery(conference.Id, fromRoomLabel); var consultationRoom = await _queryHandler.Handle <GetConsultationRoomByIdQuery, ConsultationRoom>(roomQuery); var remainingParticipants = consultationRoom.RoomParticipants.Where(x => x.ParticipantId != participant.Id).ToList(); if (remainingParticipants.Count != 2) { return(null); } var participantIds = remainingParticipants.Select(x => x.ParticipantId); var firstRemaining = conference.Participants.First(x => participantIds.Contains(x.Id)); return(firstRemaining.LinkedParticipants.Any(x => participantIds.Contains(x.LinkedId)) ? firstRemaining : null); }
protected override async Task PublishStatusAsync(CallbackEvent callbackEvent) { var participantStatus = DeriveParticipantStatusForTransferEvent(callbackEvent); var command = new UpdateParticipantStatusAndRoomCommand(SourceConference.Id, SourceParticipant.Id, participantStatus, callbackEvent.TransferTo, callbackEvent.TransferredToRoomLabel); await CommandHandler.Handle(command); if (!callbackEvent.TransferredFromRoomLabel.ToLower().Contains("consultation") || callbackEvent.TransferTo == RoomType.HearingRoom) { return; } var roomQuery = new GetConsultationRoomByIdQuery(SourceConference.Id, callbackEvent.TransferredFromRoomLabel); var room = await QueryHandler.Handle <GetConsultationRoomByIdQuery, ConsultationRoom>(roomQuery); if (room == null) { _logger.LogError("Unable to find room {roomLabel} in conference {conferenceId}", callbackEvent.TransferredFromRoomLabel, SourceConference.Id); } else if (room.Status == RoomStatus.Live && !room.RoomParticipants.Any()) { foreach (var endpoint in room.RoomEndpoints) { await _consultationService.EndpointTransferToRoomAsync(SourceConference.Id, endpoint.EndpointId, RoomType.WaitingRoom.ToString()); } } else if (room.RoomEndpoints.Any()) { var participantsEndpoints = SourceConference.GetEndpoints().Where(x => x.DefenceAdvocate?.Equals(SourceParticipant.Username, System.StringComparison.OrdinalIgnoreCase) ?? false).Select(x => x.Id).ToList(); foreach (var endpoint in room.RoomEndpoints.Where(roomEndpoint => participantsEndpoints.Contains(roomEndpoint.EndpointId))) { await _consultationService.EndpointTransferToRoomAsync(SourceConference.Id, endpoint.EndpointId, RoomType.WaitingRoom.ToString()); } } }
public async Task <IActionResult> StartConsultationWithEndpointAsync(EndpointConsultationRequest request) { var isVhoRequest = request.RequestedById == Guid.Empty; var getConferenceByIdQuery = new GetConferenceByIdQuery(request.ConferenceId); var conference = await _queryHandler.Handle <GetConferenceByIdQuery, Conference>(getConferenceByIdQuery); if (conference == null) { _logger.LogWarning("Unable to find conference"); return(NotFound($"Unable to find conference {request.ConferenceId}")); } var endpoint = conference.GetEndpoints().SingleOrDefault(x => x.Id == request.EndpointId); if (endpoint == null) { _logger.LogWarning("Unable to find endpoint"); return(NotFound($"Unable to find endpoint {request.EndpointId}")); } var requestedBy = conference.GetParticipants().SingleOrDefault(x => x.Id == request.RequestedById); if (isVhoRequest || requestedBy?.UserRole == UserRole.Judge || requestedBy?.UserRole == UserRole.JudicialOfficeHolder) { await _consultationService.EndpointTransferToRoomAsync(request.ConferenceId, endpoint.Id, request.RoomLabel); return(Ok()); } if (requestedBy == null) { _logger.LogWarning("Unable to find defence advocate"); return(NotFound($"Unable to find defence advocate {request.RequestedById}")); } if (string.IsNullOrWhiteSpace(endpoint.DefenceAdvocate)) { const string message = "Endpoint does not have a defence advocate linked"; _logger.LogWarning(message); return(Unauthorized(message)); } if (!endpoint.DefenceAdvocate.Trim().Equals(requestedBy.Username.Trim(), StringComparison.CurrentCultureIgnoreCase)) { const string message = "Defence advocate is not allowed to speak to requested endpoint"; _logger.LogWarning(message); return(Unauthorized(message)); } var roomQuery = new GetConsultationRoomByIdQuery(request.ConferenceId, request.RoomLabel); var room = await _queryHandler.Handle <GetConsultationRoomByIdQuery, ConsultationRoom>(roomQuery); if (room == null) { _logger.LogWarning($"Unable to find room {request.RoomLabel}"); return(NotFound($"Unable to find room {request.RoomLabel}")); } if (room.RoomEndpoints.Any()) { _logger.LogWarning("Unable to join endpoint {endpointId} to {RoomLabel}", endpoint.Id, request.RoomLabel); return(BadRequest("Room already has an active endpoint")); } await _consultationService.EndpointTransferToRoomAsync(request.ConferenceId, endpoint.Id, request.RoomLabel); return(Ok()); }