/// <summary> /// Process message /// to existing chat. /// /// </summary> /// <param name="messageData"></param> /// <returns></returns> public async Task <MessageResponse> ProcessChatMessage(PostMessageToChatDto messageData) { var messageOwner = await _userManager.FindByIdAsync(messageData.UserId); if (messageOwner == null) { return(MessageResponse.Unsuccessful("Error finding message owner.")); } messageData.ApplicationUser = messageOwner; var message = _mapper.Map <Message>(messageData); var messageSaved = await _repository.SaveMessage(message); if (!messageSaved) { return(MessageResponse.Unsuccessful("Error in saving message.")); } var chatResponse = await _chatsManager.RefreshChatActivity(messageData.ChatId); if (!chatResponse.Success) { return(MessageResponse.Unsuccessful(chatResponse.ErrorMessage)); } var messageDetailsDto = _mapper.Map <MessageDetailsDto>(message); messageDetailsDto.ApplicationUser = messageOwner.UserName; return(MessageResponse.Successfull(messageDetailsDto)); }
public async Task <MessageResponse> GetChatMessages(Guid chatId) { var messages = await _repository.GetMessagesByChatId(chatId); return(MessageResponse.Successfull(messages)); }
/// <summary> /// Get all messages /// for logged user. /// </summary> /// <param name="userId"></param> /// <returns></returns> public async Task <MessageResponse> GetUserMessages(string userId) { var userMessages = await _repository.GetMessagesByUserId(userId); return(MessageResponse.Successfull(userMessages)); }