private async Task LoadMessages(Conversation conversation)
        {
            _messageCollection.Clear();

            var messageList = await _messageDao.GetAllFromConversation(conversation.Id);
            foreach (Message m in messageList)
            {
                _messageCollection.Add(m);
            }
            MessageListView.ItemsSource = _messageCollection;
        }
 public async Task<bool> Exists(Conversation conversation)
 {
     IHubProxy hubProxy = await DBConnection.GetProxy(hubName);
     return await hubProxy.Invoke<bool>("Exists", conversation);
 }
        /// <summary>
        /// Creates conversation with user entered in the textbox. 
        /// Because of that, conversation is currently possible only between 2 users.
        /// </summary>
        private async void AddConversationButton_Click(object sender, RoutedEventArgs e)
        {
            User newContact = new User();
            newContact.Username = AddConversationTextBox.Text;
            if (!await _userDao.Exists(newContact))
            {
                ErrorLabel.Content = "Contact with that username doesn't exist!";
                return;
            }
            newContact = await _userDao.Get(newContact.Username);
            
            Conversation newConversation = new Conversation();
            newConversation.Participants.Add(ActiveUser);
            newConversation.Participants.Add(newContact);

            if (await _conversationDao.Exists(newConversation))
            {
                ErrorLabel.Content = "That conversation already exists!";
            }
            else
            {
                newConversation.Id = await _conversationDao.Add(newConversation);

                ActiveUser.Conversations.Add(newConversation);
                await _userDao.Update(ActiveUser);

                newContact.Conversations.Add(newConversation);
                await _userDao.Update(newContact);

                //ActiveUser.ConversationIdList.Add(newConversation.Id);
                //await _userDao.Update(ActiveUser);

                //newContact.ConversationIdList.Add(newConversation.Id);
                //await _userDao.Update(newContact);

                _conversationCollection.Add(newConversation);
                CollectionView view =
                    (CollectionView) CollectionViewSource.GetDefaultView(ConversationListView.ItemsSource);
                view.Refresh();
            }
        }
 public async Task<int> Add(Conversation conversation)
 {
     IHubProxy hubProxy = await DBConnection.GetProxy(hubName);
     return await hubProxy.Invoke<int>("Add", conversation);
 }