Ejemplo n.º 1
0
        private void OnChatRoomUpdated(object sender, ConversationUpdatedEventArgs e)
        {
            //************************************************************************************************************************************
            // When a message is sent or received in Chat then this method will called.
            //************************************************************************************************************************************
            if (!e.Conversation.IsRttChat)
            {
                return;
            }

            if (ServiceManager.Instance.Dispatcher.Thread != Thread.CurrentThread)
            {
                ServiceManager.Instance.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                               new EventHandler <ConversationUpdatedEventArgs>(OnChatRoomUpdated), sender, new object[] { e });
                return;
            }

            if (!e.Conversation.Equals(this.Chat))
            {
                return;
            }

            try
            {
                if (MessagesListView != null && MessagesListView.SourceCollection != null)
                {
                    MessagesListView.Refresh();
                }
            }
            catch (Exception)
            {
            }

            RaiseConversationChanged();
        }
        private void OnChatRoomUpdated(object sender, ConversationUpdatedEventArgs e)
        {
            //****************************************************************************************
            // When chat receive a new message then this method called for update chat room.
            //*****************************************************************************************
            if (e.Conversation.IsRttChat)
            {
                return;
            }

            if (ServiceManager.Instance.Dispatcher.Thread != Thread.CurrentThread)
            {
                ServiceManager.Instance.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                               new EventHandler <ConversationUpdatedEventArgs>(OnChatRoomUpdated), sender, new object[] { e });
                return;
            }

            if (ChatViewContact != null && ChatViewContact.Contact == e.Conversation.Contact)
            {
                try
                {
                    if (MessagesListView != null && MessagesListView.SourceCollection != null)
                    {
                        MessagesListView.Refresh();
                    }
                }
                catch (Exception)
                {
                }

                RaiseConversationChanged();
            }
            else
            {
                foreach (var contactVM in this.Contacts)
                {
                    if (contactVM.Contact == e.Conversation.Contact)
                    {
                        contactVM.LastUnreadMessageTime = e.Conversation.LastUnreadMessageTime;
                    }
                }
            }
            RefreshContactsList();
        }