protected override async ValueTask <SynchronizedSceneTalkingStick> InternalFetchValue(string conferenceId,
                                                                                              string roomId)
        {
            var currentSpeaker = await _repository.GetCurrentSpeaker(conferenceId, roomId);

            var queue = await _repository.FetchQueue(conferenceId, roomId);

            return(new SynchronizedSceneTalkingStick(currentSpeaker?.Id, queue));
        }
        public async Task <Unit> Handle(TalkingStickEnqueueRequest request, CancellationToken cancellationToken)
        {
            var(participant, remove) = request;

            var rooms = await _mediator.FetchSynchronizedObject <SynchronizedRooms>(participant.ConferenceId,
                                                                                    SynchronizedRooms.SyncObjId);

            if (!rooms.Participants.TryGetValue(participant.Id, out var roomId))
            {
                throw SceneError.RoomNotFound.ToException();
            }

            await using (await _repository.LockRoom(participant.ConferenceId, roomId))
            {
                await _mediator.Send(new ClearCacheRequest());

                if (!await CheckParticipantIsInRoom(participant, roomId))
                {
                    throw new ConcurrencyException("Participant switched room.");
                }

                if (remove)
                {
                    await _repository.RemoveFromQueue(participant.Yield(), roomId);
                }
                else
                {
                    var queue = await _repository.FetchQueue(participant.ConferenceId, roomId);

                    if (!queue.Contains(participant.Id))
                    {
                        await _repository.Enqueue(participant, roomId);
                    }

                    await _modeHandler.InvalidateTalkingSceneWithLockAcquired(participant.ConferenceId, roomId);
                }
            }

            await _mediator.Send(new UpdateSynchronizedObjectRequest(participant.ConferenceId,
                                                                     SynchronizedSceneTalkingStick.SyncObjId(roomId)));

            return(Unit.Value);
        }