Exemplo n.º 1
0
        public async Task <SuccessOrError <Unit> > SetUserIsTyping(SetUserTypingDto dto)
        {
            if (!ChatValidationExtensions.TryParseChatChannel(dto.Channel, out var channel))
            {
                return(new FieldValidationError(nameof(FetchChatMessagesDto.Channel), "Could not parse chat channel"));
            }

            var participant = GetContextParticipant();

            return(await GetInvoker().Create(new SetParticipantTypingRequest(participant, channel, dto.IsTyping))
                   .VerifyCanSendToChatChannel(channel).ConferenceMustBeOpen().Send());
        }
Exemplo n.º 2
0
        public async Task <SuccessOrError <Unit> > SendChatMessage(SendChatMessageDto dto)
        {
            if (!ChatValidationExtensions.TryParseChatChannel(dto.Channel, out var channel))
            {
                return(new FieldValidationError(nameof(FetchChatMessagesDto.Channel), "Could not parse chat channel"));
            }

            var participant = GetContextParticipant();
            var builder     = GetInvoker()
                              .Create(new SendChatMessageRequest(participant, dto.Message, channel, dto.Options))
                              .VerifyCanSendToChatChannel(channel).VerifyMessageConformsOptions(dto).ValidateObject(dto)
                              .ConferenceMustBeOpen();

            return(await builder.Send());
        }
Exemplo n.º 3
0
        public async Task <SuccessOrError <IReadOnlyList <ChatMessageDto> > > FetchChatMessages(FetchChatMessagesDto dto)
        {
            if (!ChatValidationExtensions.TryParseChatChannel(dto.Channel, out var channel))
            {
                return(new FieldValidationError(nameof(FetchChatMessagesDto.Channel), "Could not parse chat channel"));
            }

            var participant = GetContextParticipant();
            var result      = await GetInvoker()
                              .Create(new FetchMessagesRequest(participant.ConferenceId, channel, dto.Start, dto.End))
                              .VerifyCanSendToChatChannel(channel).Send();

            if (!result.Success)
            {
                return(result.Error);
            }

            var(messages, totalMessages) = result.Response;
            var(start, _) = IndexUtils.TranslateStartEndIndex(dto.Start, dto.End, totalMessages);

            var messageDtos = new List <ChatMessageDto>(messages.Count);
            var currentId   = start;

            foreach (var chatMessage in messages)
            {
                ChatMessageSender?sender = null;
                if (!chatMessage.Options.IsAnonymous)
                {
                    sender = chatMessage.Sender;
                }

                messageDtos.Add(new ChatMessageDto(currentId++, dto.Channel, sender, chatMessage.Message,
                                                   chatMessage.Timestamp, chatMessage.Options));
            }

            return(messageDtos);
        }