Nullabfrage hinzugefügt
This commit is contained in:
@@ -319,7 +319,7 @@ namespace ChatController
|
||||
_ContainingWindow.Activate();
|
||||
|
||||
var selectedContact = _ContactList?.FirstOrDefault(f => f?.Contact.GroupId == pGroupId);
|
||||
if(!(selectedContact is null))
|
||||
if(!(selectedContact?.Contact is null))
|
||||
{
|
||||
SelectContact(selectedContact.Contact);
|
||||
}
|
||||
@@ -374,83 +374,93 @@ namespace ChatController
|
||||
return;
|
||||
}
|
||||
|
||||
if(Clientlist?.SelectedItem is ContactDependencyObject selectedContactDependencyObject)
|
||||
if(Clientlist?.SelectedItem is ContactDependencyObject selectedContactDependencyObject && !(selectedContactDependencyObject.Contact is null))
|
||||
{
|
||||
SelectContact(selectedContactDependencyObject.Contact);
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo: Hier kommt es immer wieder zu einer NullPointerException
|
||||
private void SelectContact(Contact contact)
|
||||
{
|
||||
if(contact is null)
|
||||
try
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ChatMessageFileWrapper = null;
|
||||
|
||||
ShouldInterruptContactsThread = true;
|
||||
|
||||
StartWaitingImmediately();
|
||||
|
||||
_ScrollPrueferAktivieren = false;
|
||||
|
||||
if(contact.HasUnreadMessages)
|
||||
{
|
||||
contact.HasUnreadMessages = false;
|
||||
|
||||
Clientlist.Items.Refresh();
|
||||
OnPropertyChanged(nameof(ContactList));
|
||||
}
|
||||
|
||||
var currentContact = contact;
|
||||
contact.IsNewMessage = false;
|
||||
|
||||
var shouldChangeIcon = _ContactList.Any(contactDependencyObject => contactDependencyObject.Contact.IsNewMessage);
|
||||
if(shouldChangeIcon)
|
||||
{
|
||||
ContainingWindow.Icon = Utils.ConvertIconToImageSource(Resource.ownchat_favicon);
|
||||
}
|
||||
|
||||
CurrentContact = currentContact;
|
||||
|
||||
OnPropertyChanged(nameof(IsSendButtonEnabled));
|
||||
|
||||
foreach(ContactDependencyObject item in Clientlist.Items)
|
||||
{
|
||||
if(item.Contact.Equals(contact))
|
||||
if(contact is null)
|
||||
{
|
||||
Clientlist.SelectedItem = item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_ChatMessages.Clear();
|
||||
OnPropertyChanged(nameof(_ChatMessages));
|
||||
ChatMessageFileWrapper = null;
|
||||
|
||||
Chat.LoadChatMessagesForContactAsync(currentContact, GetFirstMessage(), chatMessages =>
|
||||
{
|
||||
this.Dispatch(() =>
|
||||
ShouldInterruptContactsThread = true;
|
||||
|
||||
// Zeigt die Warteanimation (das Rädchen)
|
||||
StartWaitingImmediately();
|
||||
|
||||
_ScrollPrueferAktivieren = false;
|
||||
|
||||
if(contact.HasUnreadMessages)
|
||||
{
|
||||
_ChatMessages.Clear();
|
||||
_ChatMessages.AddRangeIfElementsNotIn(chatMessages);
|
||||
OnPropertyChanged(nameof(_ChatMessages));
|
||||
contact.HasUnreadMessages = false;
|
||||
|
||||
WpfUtils.ScrollToBottomOfListBox(ChatListBox);
|
||||
Clientlist?.Items.Refresh();
|
||||
OnPropertyChanged(nameof(ContactList));
|
||||
}
|
||||
|
||||
ChatListBox.ContextMenu = Chat.ErstelleKontextMenue();
|
||||
SetContextHandler();
|
||||
_ScrollPrueferAktivieren = true;
|
||||
var currentContact = contact;
|
||||
|
||||
ListenForMessages();
|
||||
Cursor = Cursors.Arrow;
|
||||
contact.IsNewMessage = false;
|
||||
|
||||
WriteToNewSyncFile();
|
||||
var shouldChangeIcon = _ContactList.Any(contactDependencyObject => contactDependencyObject.Contact.IsNewMessage);
|
||||
if(shouldChangeIcon)
|
||||
{
|
||||
ContainingWindow.Icon = Utils.ConvertIconToImageSource(Resource.ownchat_favicon);
|
||||
}
|
||||
|
||||
ShouldInterruptContactsThread = false;
|
||||
CurrentContact = currentContact;
|
||||
|
||||
EndWaiting();
|
||||
OnPropertyChanged(nameof(IsSendButtonEnabled));
|
||||
|
||||
foreach(ContactDependencyObject item in Clientlist.Items)
|
||||
{
|
||||
if(item.Contact.Equals(contact))
|
||||
{
|
||||
Clientlist.SelectedItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
_ChatMessages.Clear();
|
||||
OnPropertyChanged(nameof(_ChatMessages));
|
||||
|
||||
Chat.LoadChatMessagesForContactAsync(currentContact, GetFirstMessage(), chatMessages =>
|
||||
{
|
||||
this.Dispatch(() =>
|
||||
{
|
||||
_ChatMessages.Clear();
|
||||
_ChatMessages.AddRangeIfElementsNotIn(chatMessages);
|
||||
OnPropertyChanged(nameof(_ChatMessages));
|
||||
|
||||
WpfUtils.ScrollToBottomOfListBox(ChatListBox);
|
||||
|
||||
ChatListBox.ContextMenu = Chat.ErstelleKontextMenue();
|
||||
SetContextHandler();
|
||||
_ScrollPrueferAktivieren = true;
|
||||
|
||||
ListenForMessages();
|
||||
Cursor = Cursors.Arrow;
|
||||
|
||||
WriteToNewSyncFile();
|
||||
|
||||
ShouldInterruptContactsThread = false;
|
||||
|
||||
EndWaiting();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetContextHandler()
|
||||
|
||||
Reference in New Issue
Block a user