public static IServiceRequestBuilder <TResponse> VerifyMessageConformsOptions <TResponse>(
            this IServiceRequestBuilder <TResponse> builder, SendChatMessageDto message)
        {
            var neededPermissions = GetRequiredPermissions(message);

            return(builder.RequirePermissions(neededPermissions));
        }
Пример #2
0
        public void GetRequiredPermissions_NoOptionsConfigured_ReturnCanSendChatMessagePermission()
        {
            // arrange
            var messageDto = new SendChatMessageDto("Hello", "test", new ChatMessageOptions());

            // act
            var requiredPermissions = ServiceInvokerChatMiddleware.GetRequiredPermissions(messageDto);

            // assert
            var permission = Assert.Single(requiredPermissions);

            Assert.Equal(DefinedPermissions.Chat.CanSendChatMessage.Key, permission !.Key);
        }
Пример #3
0
        public void GetRequiredPermissions_IsAnnouncement_ReturnCanSendChatMessageAndCanSendAnonymouslyPermission()
        {
            // arrange
            var messageDto = new SendChatMessageDto("Hello", "test", new ChatMessageOptions {
                IsAnnouncement = true
            });

            // act
            var requiredPermissions = ServiceInvokerChatMiddleware.GetRequiredPermissions(messageDto).ToList();

            // assert
            Assert.Equal(2, requiredPermissions.Count);
            Assert.Contains(requiredPermissions, x => x.Key == DefinedPermissions.Chat.CanSendChatMessage.Key);
            Assert.Contains(requiredPermissions, x => x.Key == DefinedPermissions.Chat.CanSendAnnouncement.Key);
        }
Пример #4
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());
        }
        public static IEnumerable <PermissionDescriptor <bool> > GetRequiredPermissions(SendChatMessageDto message)
        {
            yield return(DefinedPermissions.Chat.CanSendChatMessage);

            if (message.Options.IsAnonymous)
            {
                yield return(DefinedPermissions.Chat.CanSendAnonymously);
            }

            if (message.Options.IsAnnouncement)
            {
                yield return(DefinedPermissions.Chat.CanSendAnnouncement);
            }
        }