コード例 #1
0
        public async Task <ConversationDTO> GetConversationWithUserAsync(UserPairIdUsernameDTO userPair)
        {
            var privateConversation = await _conversationRepository.GetConversationWithUser(userPair.UserId, userPair.Username);

            var conversationDTO = _conversationParser.ParseConversation(privateConversation, userPair.UserId);

            return(conversationDTO);
        }
コード例 #2
0
        public async Task StartConversationAsync()
        {
            var userPairDTO = new UserPairIdUsernameDTO()
            {
                UserId   = DataContainer.GetUserId(),
                Username = BookPost.PostOwner.Username
            };
            var conversationDTO = await _conversationService.GetConversationWithUser(userPairDTO);

            DataContainer.ConversationDTO = conversationDTO;
            await _messageService.ConnectToHub();

            await _messageService.JoinChat(conversationDTO);
        }
コード例 #3
0
        public async Task <ConversationDTO> GetConversationWithUser(UserPairIdUsernameDTO userPairDTO)
        {
            using (var httpClient = new HttpClient())
            {
                var response = await httpClient.PostAsync(_apiURL,
                                                          new StringContent(
                                                              JsonConvert.SerializeObject(userPairDTO),
                                                              Encoding.UTF8, "application/json"
                                                              ));

                var jsonResponse = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <ConversationDTO>(jsonResponse));
            }
        }
コード例 #4
0
        public async Task <ConversationDTO> GetConversationWithUser(string username)
        {
            var userPair = new UserPairIdUsernameDTO()
            {
                UserId   = DataContainer.GetUserId(),
                Username = username
            };
            var conversation = await _conversationService.GetConversationWithUser(userPair);

            if (conversation == null)
            {
                return(conversation);
            }

            DataContainer.ConversationDTO = conversation;
            if (conversation.ConversationLastMessage is null)
            {
                UserConversations.Add(conversation);
                await _messageService.JoinChat(conversation);
            }

            return(conversation);
        }
コード例 #5
0
        public async Task <ActionResult <ConversationDTO> > GetConversationWithUser(UserPairIdUsernameDTO userPairDTO)
        {
            var conversation = await _conversationService.GetConversationWithUserAsync(userPairDTO);

            return(Ok(conversation));
        }