コード例 #1
0
        public async Task <Response> CreateResponseAsync()
        {
            try
            {
                ChannelVm editableChannel = await loadChannelsService.GetChannelByIdAsync(request.Channel.ChannelId.Value);

                ChannelVm channel = await updateChannelsService.EditChannelAsync(request.Channel, clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false);

                if (editableChannel.ChannelName != channel.ChannelName)
                {
                    var systemMessageInfo = SystemMessageInfoFactory.CreateNameChangedMessageInfo(editableChannel.ChannelName, channel.ChannelName);
                    var message           = await systemMessagesService.CreateMessageAsync(ObjectsLibrary.Enums.ConversationType.Channel, channel.ChannelId.Value, systemMessageInfo);

                    conversationsNoticeService.SendSystemMessageNoticeAsync(message);
                }
                IEnumerable <long> usersId = await loadChannelsService.GetChannelUsersIdAsync(channel.ChannelId.GetValueOrDefault()).ConfigureAwait(false);

                conversationsNoticeService.SendChannelNoticeAsync(channel, usersId.ToList(), clientConnection);
                UsersConversationsCacheService.Instance.UpdateUsersChannelsAsync(usersId.ToList());
                nodeNoticeService.SendChannelNodeNoticeAsync(channel, clientConnection.UserId.GetValueOrDefault(), null);
                BlockSegmentVm segment = await BlockSegmentsService.Instance.CreateChannelSegmentAsync(channel, NodeSettings.Configs.Node.Id).ConfigureAwait(false);

                BlockGenerationHelper.Instance.AddSegment(segment);
                return(new ChannelsResponse(request.RequestId, channel));
            }
            catch (PermissionDeniedException ex)
            {
                Logger.WriteLog(ex, request);
                return(new ResultResponse(request.RequestId, "Channel not found or user does not have access to the channel.", ObjectsLibrary.Enums.ErrorCode.PermissionDenied));
            }
        }
コード例 #2
0
        public async Task EditChannel()
        {
            var channel         = fillTestDbHelper.Channels.FirstOrDefault();
            var expectedChannel = ChannelConverter.GetChannelVm(ChannelConverter.GetChannelDto(channel));

            expectedChannel.ChannelName = "Edited channel name";
            expectedChannel.About       = "Edited channel about";
            expectedChannel.Tag         = "EDITEDTAG";
            var actualChannel = await updateChannelsService.EditChannelAsync(expectedChannel, channel.ChannelUsers.FirstOrDefault(opt => opt.ChannelUserRole >= ChannelUserRole.Administrator).UserId);

            Assert.True(expectedChannel.ChannelName == actualChannel.ChannelName && expectedChannel.About == actualChannel.About && expectedChannel.Tag != actualChannel.Tag);
        }
コード例 #3
0
        public async Task <ChannelVm> CreateOrEditChannelAsync(ChannelVm channel, long requestorId, IEnumerable <ChannelUserVm> subscribers)
        {
            using (MessengerDbContext context = contextFactory.Create())
            {
                bool isExistsChannel = await context.Channels.AnyAsync(opt => opt.ChannelId == channel.ChannelId).ConfigureAwait(false);

                if (isExistsChannel)
                {
                    return(await updateChannelsService.EditChannelAsync(channel, requestorId).ConfigureAwait(false));
                }
                else
                {
                    return(await CreateChannelAsync(channel, requestorId, subscribers).ConfigureAwait(false));
                }
            }
        }