public async Task <IActionResult> GetMessagesThread([FromQuery] GetMessagesThreadPaginationRequest request) { var response = await mediator.Send(request); logger.LogResponse($"User #{HttpContext.GetCurrentUserId()} opened chat with user #{request.RecipientId}", response.Error); return(this.CreateResponse(response)); }
public async Task <IPagedList <Message> > GetMessagesThread(GetMessagesThreadPaginationRequest paginationRequest) { var currentUser = await profileService.GetCurrentUser(); if (currentUser.Id == paginationRequest.RecipientId) { throw new EntityNotFoundException("Messages thread not found"); } if (!SendMessageOnlyToFriendsSpecification.Create(paginationRequest.RecipientId).IsSatisfied(currentUser)) { throw new NoPermissionsException("You can chat only with your friends"); } var messages = await database.MessageRepository.GetMessagesThread(currentUser.Id, paginationRequest.RecipientId, (paginationRequest.PageNumber, paginationRequest.PageSize)); messages = await MarkAsRead(currentUser.Id, paginationRequest.RecipientId, messages); return(messages); }