Ejemplo n.º 1
0
        public async Task HandleAsync()
        {
            try
            {
                List <long> nodesIds = await conversationsService.GetConversationNodesIdsAsync(request.ConversationType, request.ConversationId).ConfigureAwait(false);

                if (!nodesIds.Contains(current.Node.Id))
                {
                    NodeWebSocketCommunicationManager.SendResponse(new ResultNodeResponse(request.RequestId, ErrorCode.PermissionDenied, "No rights to load messages."), current);
                    return;
                }
                List <MessageDto> messages = await loadMessagesService.GetMessagesAsync(
                    request.ConversationId,
                    request.ConversationType,
                    request.Direction.GetValueOrDefault(true),
                    request.MessageId,
                    request.AttachmentsTypes,
                    request.Length).ConfigureAwait(false);

                MessagesNodeResponse response = new MessagesNodeResponse(request.RequestId, messages);
                NodeWebSocketCommunicationManager.SendResponse(response, current);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
                NodeWebSocketCommunicationManager.SendResponse(new ResultNodeResponse(request.RequestId, ErrorCode.UnknownError), current);
            }
        }
Ejemplo n.º 2
0
        public async Task <List <MessageDto> > GetMessagesAsync(NodeConnection connection, long conversationId, ConversationType conversationType, Guid?messageId, List <AttachmentType> attachmentsTypes, bool direction = true, int length = 1000)
        {
            if (connection == null)
            {
                return(new List <MessageDto>());
            }
            GetMessagesNodeRequest request = new GetMessagesNodeRequest(conversationType, conversationId, messageId, attachmentsTypes, direction, length);

            SendRequest(connection, request);
            NodeResponse response = await GetResponseAsync(request).ConfigureAwait(false);

            if (response.ResponseType == Enums.NodeResponseType.Messages)
            {
                MessagesNodeResponse messagesResponse = (MessagesNodeResponse)response;
                return(messagesResponse.Messages);
            }
            else
            {
                throw new BadResponseException();
            }
        }