예제 #1
0
        public async Task <Response> CreateResponseAsync()
        {
            List <ChatVm> result = new List <ChatVm>();

            try
            {
                foreach (var chat in request.Chats)
                {
                    ChatVm editableChat = await loadChatsService.GetChatByIdAsync(chat.Id);

                    ChatVm editedChat =
                        await updateChatsService.EditChatAsync(chat, clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false);

                    result.Add(editedChat);
                    if (editableChat.Name != editedChat.Name)
                    {
                        var systemMessageInfo = SystemMessageInfoFactory.CreateNameChangedMessageInfo(editableChat.Name, editedChat.Name);
                        var message           = await systemMessagesService.CreateMessageAsync(ConversationType.Chat, editedChat.Id.Value, systemMessageInfo);

                        conversationsNoticeService.SendSystemMessageNoticeAsync(message);
                    }
                    List <BlockSegmentVm> segments = await BlockSegmentsService.Instance.CreateEditPrivateChatSegmentsAsync(
                        editedChat,
                        NodeSettings.Configs.Node.Id,
                        NodeData.Instance.NodeKeys.SignPrivateKey,
                        NodeData.Instance.NodeKeys.SymmetricKey,
                        NodeData.Instance.NodeKeys.Password,
                        NodeData.Instance.NodeKeys.KeyId).ConfigureAwait(false);

                    if (segments.Any())
                    {
                        nodeNoticeService.SendBlockSegmentsNodeNoticeAsync(segments.ToList());
                        foreach (var segment in segments)
                        {
                            BlockGenerationHelper.Instance.AddSegment(segment);
                        }
                    }
                    editedChat.Users = null;
                    conversationsNoticeService.SendEditChatNoticeAsync(editedChat, clientConnection);
                    IEnumerable <long> chatUsersId = await loadChatsService.GetChatUsersIdAsync(chat.Id).ConfigureAwait(false);

                    UsersConversationsCacheService.Instance.UpdateUsersChatsAsync(chatUsersId);
                }

                nodeNoticeService.SendEditChatsNodeNoticeAsync(result);
                return(new ChatsResponse(request.RequestId, result));
            }
            catch (PermissionDeniedException ex)
            {
                Logger.WriteLog(ex, request);
                return(new ResultResponse(request.RequestId, "Chat not found or user does not have access to chat.", ErrorCode.PermissionDenied));
            }
        }
예제 #2
0
        public async Task EditChat()
        {
            var chat         = fillTestDbHelper.Chats.FirstOrDefault();
            var expectedChat = new EditChatVm
            {
                Id    = chat.Id,
                About = "Edited about",
                Name  = "Edited name",
                Photo = "NewPhotoRef"
            };
            var actualChat = await updateChatsService.EditChatAsync(expectedChat, chat.ChatUsers.FirstOrDefault(opt => opt.UserRole >= UserRole.Admin).UserId);

            Assert.True(
                expectedChat.Id == actualChat.Id &&
                expectedChat.Name == actualChat.Name &&
                expectedChat.About == actualChat.About &&
                expectedChat.Photo == actualChat.Photo);
        }