public void SetActiveChatContact(VATRPContact contact, IntPtr callPtr) { if (contact == null) { return; } if (Chat != null && Chat.Contact == contact) { Chat.Contact.UnreadMsgCount = 0; Chat.UnreadMsgCount = 0; ChangeUnreadCounter(); _chatsManager.ActivateChat(Chat); return; } this._chat = _chatsManager.GetChat(contact, false); var contactVM = FindContactViewModel(contact); if (contactVM == null) { contactVM = new ContactViewModel(contact); this.Contacts.Add(contactVM); } if (ChatViewContact != null && ChatViewContact.Contact != contactVM.Contact) { ChatViewContact.IsSelected = false; } ChatViewContact = contactVM; if (Chat != null) { Chat.CallPtr = callPtr; if (Chat.Contact != null) { Chat.Contact.UnreadMsgCount = 0; this.Chat.Contact.PropertyChanged += this.Contact_PropertyChanged; } Chat.CharsCountInBubble = 0; Chat.UnreadMsgCount = 0; ChangeUnreadCounter(); _chatsManager.ActivateChat(Chat); if (App.CurrentAccount != null) { Chat.MessageFont = App.CurrentAccount.RTTFontFamily; } } ChatViewContact.IsSelected = true; IsMessagesLoaded = false; this.MessagesListView = CollectionViewSource.GetDefaultView(this.Messages); this.MessagesListView.SortDescriptions.Add(new SortDescription("MessageTime", ListSortDirection.Ascending)); OnPropertyChanged("Chat"); try { if (MessagesListView != null && this.Messages != null) { MessagesListView.Refresh(); } } catch (Exception) { } if (ConversationUpdated != null) { ConversationUpdated(this, EventArgs.Empty); } }