public async Task HandleAsync()
        {
            foreach (var message in notice.Messages)
            {
                try
                {
                    if (message.Attachments != null && message.Attachments.Any())
                    {
                        bool isValid = await attachmentsService.CheckEditedMessageAttachmentsAsync(MessageConverter.GetMessageVm(message, null), notice.EditorUserId).ConfigureAwait(false);

                        if (!isValid)
                        {
                            return;
                        }
                    }
                    MessageDto edited = await updateMessagesService.EditMessageAsync(message, message.SenderId.GetValueOrDefault()).ConfigureAwait(false);

                    conversationsNoticeService.SendMessagesUpdatedNoticeAsync(
                        message.ConversationId,
                        message.ConversationType,
                        new List <MessageDto> {
                        edited
                    },
                        message.SenderId.GetValueOrDefault(),
                        false,
                        null);
                    UsersConversationsCacheService.Instance.MessageEditedUpdateConversations(edited);
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(ex);
                }
            }
        }
Example #2
0
        public async Task EditMessage()
        {
            var message         = fillTestDbHelper.Messages.FirstOrDefault();
            var expectedMessage = MessageConverter.GetMessageDto(message);

            expectedMessage.Text = "Edited message text";
            var actualMessage = await updateMessagesService.EditMessageAsync(expectedMessage, expectedMessage.SenderId.Value);

            Assert.Equal(expectedMessage.Text, actualMessage.Text);
        }
Example #3
0
        public async Task <Response> CreateResponseAsync()
        {
            try
            {
                if (request.Message.Attachments != null && request.Message.Attachments.Any())
                {
                    var isValid = await attachmentsService.CheckEditedMessageAttachmentsAsync(
                        request.Message, clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false);

                    if (!isValid)
                    {
                        throw new InvalidAttachmentsException();
                    }
                }
                MessageDto edited = await updateMessagesService.EditMessageAsync(
                    MessageConverter.GetMessageDto(request.Message),
                    clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false);

                conversationsNoticeService.SendMessagesUpdatedNoticeAsync(
                    request.Message.ConversationId.GetValueOrDefault(),
                    request.Message.ConversationType,
                    new List <MessageDto> {
                    edited
                },
                    clientConnection.UserId.GetValueOrDefault(),
                    false,
                    clientConnection);
                nodeNoticeService.SendMessagesUpdateNodeNoticeAsync(
                    new List <MessageDto> {
                    edited
                },
                    edited.ConversationId,
                    edited.ConversationType,
                    clientConnection.UserId.GetValueOrDefault());
                UsersConversationsCacheService.Instance.MessageEditedUpdateConversations(edited);
                return(new MessagesResponse(request.RequestId,
                                            new List <MessageVm>
                {
                    MessageConverter.GetMessageVm(edited, clientConnection.UserId)
                }));
            }
            catch (InvalidAttachmentsException ex)
            {
                Logger.WriteLog(ex);
                return(new ResultResponse(request.RequestId, "Invalid attachments.", ErrorCode.InvalidAttachment));
            }
            catch (ObjectDoesNotExistsException ex)
            {
                Logger.WriteLog(ex);
                return(new ResultResponse(request.RequestId, "Message not found.", ErrorCode.ObjectDoesNotExists));
            }
        }