Ejemplo n.º 1
0
        private void ReloadMessageHistoryListForSelectedContact()
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate()
            {
                LbChatMessages.Items.Clear();
                List <Message> messageHistory =
                    _clientService.ContactsMessageHistory.FirstOrDefault(u => u.Key.Id == _selectedChatContact.Id)
                    .Value;

                foreach (var message in messageHistory)
                {
                    string messageString =
                        $"{message.SendTime.ToShortTimeString()} {message.Sender.UserName}:  {message.MessageText}";
                    LbChatMessages.Items.Add(messageString);
                }
                LbChatMessages.Items.MoveCurrentToLast();
                LbChatMessages.ScrollIntoView(LbChatMessages.Items.CurrentItem);
            });
        }
Ejemplo n.º 2
0
        private void _clientService_MessageReceived(Message message)
        {
            if (ChatContactsList.FirstOrDefault(u => u.Id == message.Sender.Id) == null)
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)ReloadContactList);
            }

            if (_selectedChatContact != null && (message.Sender.UserName == _selectedChatContact.UserName))
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate()
                {
                    string messageString =
                        $"{message.SendTime.ToShortTimeString()} {message.Sender.UserName}:  {message.MessageText}";
                    LbChatMessages.Items.Add(messageString);
                    LbChatMessages.Items.MoveCurrentToLast();
                    LbChatMessages.ScrollIntoView(LbChatMessages.Items.CurrentItem);
                });
            }
        }