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)); } }
public async Task <Response> CreateResponseAsync() { try { request.Channel.ChannelId = null; request.Channel.Tag = null; ChannelVm channel = await createChannelsService.CreateChannelAsync(request.Channel, clientConnection.UserId.GetValueOrDefault(), request.Subscribers).ConfigureAwait(false); List <long> usersId = await loadChannelsService.GetChannelUsersIdAsync(channel.ChannelId.GetValueOrDefault()).ConfigureAwait(false); conversationsNoticeService.SendChannelNoticeAsync(channel, usersId, clientConnection); UsersConversationsCacheService.Instance.UpdateUsersChannelsAsync(usersId); nodeNoticeService.SendChannelNodeNoticeAsync(channel, clientConnection.UserId.Value, request.Subscribers); BlockSegmentVm segment = await BlockSegmentsService.Instance.CreateChannelSegmentAsync(channel, NodeSettings.Configs.Node.Id).ConfigureAwait(false); BlockGenerationHelper.Instance.AddSegment(segment); return(new ChannelsResponse(request.RequestId, channel)); } catch (UserNotFoundException ex) { Logger.WriteLog(ex, request); return(new ResultResponse(request.RequestId, "Users not found.", ErrorCode.ObjectDoesNotExists)); } catch (UserBlockedException ex) { Logger.WriteLog(ex, request); return(new ResultResponse(request.RequestId, "The user is blacklisted by another user.", ErrorCode.UserBlocked)); } }
public async Task HandleAsync() { var editableChannel = await loadChannelsService.GetChannelByIdAsync(notice.Channel.ChannelId.Value).ConfigureAwait(false); ChannelVm channel = await createChannelsService.CreateOrEditChannelAsync(notice.Channel, notice.RequestorId, notice.Subscribers).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()); }