public async Task <ListMessagesDto> ListMessages(string conversationId, [FromQuery] string startCt,
                                                         [FromQuery] string endCt, [FromQuery] int limit)
        {
            var messagesWindow = await conversationsStore.ListMessages(conversationId, startCt, endCt, limit);

            List <ListMessagesItemDto> dtos =
                (messagesWindow.Messages.Select(m => new ListMessagesItemDto(m.Text, m.SenderUsername, m.UtcTime))).ToList();

            string newStartCt = messagesWindow.StartCt;
            string newEndCt   = messagesWindow.EndCt;

            string nextUri     = (string.IsNullOrEmpty(newStartCt)) ? "" : $"api/conversation/{conversationId}?startCt={newStartCt}&limit={limit}";
            string previousUri = (string.IsNullOrEmpty(newEndCt)) ? "" : $"api/conversation/{conversationId}?endCt={newEndCt}&limit={limit}";

            return(new ListMessagesDto(dtos, nextUri, previousUri));
        }
Пример #2
0
        public async Task <IActionResult> ListMessages(string conversationId)
        {
            try
            {
                IEnumerable <Message> messages = await conversationsStore.ListMessages(conversationId);

                IEnumerable <ListMessagesItemDto> dtos =
                    messages.Select(m => new ListMessagesItemDto(m.Text, m.SenderUsername, m.UtcTime));
                return(Ok(new ListMessagesDto(dtos)));
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e,
                                "Could not reach storage to list messages, conversationId {conversationId}", conversationId);
                return(StatusCode(503));
            }
            catch (Exception e)
            {
                logger.LogError(Events.InternalError, e,
                                "Failed to list messages of conversation {conversationId}", conversationId);
                return(StatusCode(500));
            }
        }
Пример #3
0
 public Task <SortedMessagesWindow> ListMessages(string conversationId, string startCt, string endCt, int limit)
 {
     return(listMessagesMetric.TrackTime(() => store.ListMessages(conversationId, startCt, endCt, limit)));
 }
 public Task <SortedMessagesWindow> ListMessages(string conversationId, string startCt, string endCt, int limit)
 {
     return(faultTolerancePolicy.Execute(
                async() => await store.ListMessages(conversationId, startCt, endCt, limit)
                ));
 }