Exemple #1
0
        public async Task <IActionResult> ListConversations(string username)
        {
            try
            {
                var conversations = await conversationsStore.ListConversations(username);

                var conversationList = new List <ListConversationsItemDto>();
                foreach (var conversation in conversations)
                {
                    string      recipientUserName = conversation.Participants.Except(new[] { username }).First();
                    UserProfile profile           = await profileStore.GetProfile(recipientUserName);

                    var recipientInfo = new UserInfoDto(profile.Username, profile.FirstName, profile.LastName);
                    conversationList.Add(new ListConversationsItemDto(conversation.Id, recipientInfo, conversation.LastModifiedDateUtc));
                }
                return(Ok(new ListConversationsDto(conversationList)));
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e, "Could not reach storage to list user conversations, username {username}", username);
                return(StatusCode(503));
            }
            catch (Exception e)
            {
                logger.LogError(Events.InternalError, e, "Failed to retrieve conversations for user {username}", username);
                return(StatusCode(500));
            }
        }
        public async Task <IActionResult> ListConversations(string username, [FromQuery] string startCt, [FromQuery] string endCt, [FromQuery] int limit)
        {
            try
            {
                return(await listConversationsControllerTimeMetric.TrackTime(async() =>
                {
                    var conversationsWindow =
                        await conversationsStore.ListConversations(username, startCt, endCt, limit);

                    var conversationList = new List <ListConversationsItemDto>();
                    foreach (var conversation in conversationsWindow.Conversations)
                    {
                        string recipientUserName = conversation.Participants.Except(new[] { username }).First();
                        UserProfile profile = await profileStore.GetProfile(recipientUserName);
                        var recipientInfo = new UserInfoDto(profile.Username, profile.FirstName, profile.LastName);
                        conversationList.Add(new ListConversationsItemDto(conversation.Id, recipientInfo,
                                                                          conversation.LastModifiedDateUtc));
                    }

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

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

                    return Ok(new ListConversationsDto(conversationList, nextUri, previousUri));
                }));
            }
            catch (ProfileNotFoundException)
            {
                return(NotFound($"Profile for user {username} was not found"));
            }
            catch (StorageErrorException e)
            {
                logger.LogError(Events.StorageError, e, "Could not reach storage to list user conversations, username {username}", username);
                return(StatusCode(503, $"Could not reach storage to list user conversations, username {username}"));
            }
            catch (Exception e)
            {
                logger.LogError(Events.InternalError, e, "Failed to retrieve conversations for user {username}", username);
                return(StatusCode(500, $"Failed to retrieve conversations for user {username}"));
            }
        }
Exemple #3
0
 public Task <SortedConversationsWindow> ListConversations(string username, string startCt, string endCt, int limit)
 {
     return(listConversationsMetric.TrackTime(() => store.ListConversations(username, startCt, endCt, limit)));
 }
 public Task <SortedConversationsWindow> ListConversations(string username, string startCt, string endCt, int limit)
 {
     return(faultTolerancePolicy.Execute(
                async() => await store.ListConversations(username, startCt, endCt, limit)
                ));
 }