コード例 #1
0
        public async Task <ChannelSummaryResponse> CreateChannelAsync(CreateChannelRequest createChannelRequest)
        {
            if (String.IsNullOrEmpty(createChannelRequest.Name))
            {
                throw new Exception(LanguageResources.RoomRequired);
            }

            try
            {
                var channel = await _channelService.CreateChannelAsync(createChannelRequest);

                var user = await _memberService.GetMemberSummaryBySaasUserIdAsync(createChannelRequest.SaasUserId);

                await _channelNotificationHub.OnAddChannel(user, channel, createChannelRequest.ClientConnectionId);

                //todo filter creator connection id on join channel
                await _channelNotificationHub.OnJoinChannel(user, channel);

                return(channel);
            }
            catch (NotFoundException ex)
            {
                _logger.Event(PropertyNames.EventId).With.Message("Exception: Channel {channelName} does not exist.", createChannelRequest.Name).Exception(ex).AsError();
                throw new Exception(String.Format(LanguageResources.RoomNotFound, createChannelRequest.Name));
            }
        }
コード例 #2
0
        public async Task <ChannelSummaryResponse> CreateChannelAsync(CreateChannelRequest request)
        {
            var channel = await _channelService.CreateChannelAsync(request);

            var member = await _memberService.GetMemberBySaasUserIdAsync(request.SaasUserId);

            // subscribe creator on channel
            await _pushNotificationService.SubscribeUserOnTagAsync(member.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(channel.Id.ToString()));

            if (request.AllowedMembers != null)
            {
                // subscribe invited members
                foreach (var allowedMemberId in request.AllowedMembers)
                {
                    var chatMember = await _memberService.GetMemberByIdAsync(Guid.Parse(allowedMemberId));

                    if (chatMember == null)
                    {
                        throw new NetKitChatNotFoundException($"Specified chat member {allowedMemberId} is not found.");
                    }

                    await _pushNotificationService.SubscribeUserOnTagAsync(chatMember.SaasUserId, PushNotificationsTagTemplates.GetChatChannelTag(channel.Id.ToString()));
                }
            }

            await _channelNotificationService.OnAddChannel(channel);

            //todo filter creator connection id on join channel
            await _channelNotificationService.OnJoinChannel(member, channel);

            return(channel);
        }
コード例 #3
0
        public async Task <IActionResult> CreateChannelAsync([FromBody] CreateChannelRequest request)
        {
            var userId = GetCurrentUserId();

            request.SaasUserId = userId;
            var channel = await _channelService.CreateChannelAsync(request);

            return(Ok(channel));
        }
コード例 #4
0
        public async Task CreateChannelAsyncTest()
        {
            // Arrange
            var request = new CreateChannelRequest(SaasUserId, "name", ChannelType.Public)
            {
                Description    = "test",
                WelcomeMessage = "test"
            };

            // Act
            var channel = await _channelService.CreateChannelAsync(request);

            var channelMessagesCount = await _channelService.GetChannelMessagesCountAsync(channel.Id);

            // Assert
            Assert.NotNull(channel);
            Assert.Equal(request.Name, channel.Name);
            Assert.Equal(request.Description, channel.Description);
            Assert.Equal(request.WelcomeMessage, channel.WelcomeMessage);
            Assert.Equal(request.Type, channel.Type);
            Assert.True(channelMessagesCount == 0);
        }