Der Login läuft jetzt mit RestSharp.
Die Akzentfarbe von den Chatgruppen vom Server wird berücksichtigt. Bilder sind im richtigen Seitenverhältnis skaliert. Ein Bild, das man gerade erst verschickt hat und das man öffnen will, bevor es auf dem Server angekommen ist, wird jetzt erst angezeigt, sobald es auf dem Server ist. Die Textbox für eine neue Nachricht wird nur angezeigt, wenn eine Gruppe ausgewählt ist und wenn man das Recht hat Nachrichten an diese Gruppe zu verschicken. Diverse Codeverbesserungen.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -13,14 +16,13 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Threading;
|
||||
|
||||
using ChatController.Annotations;
|
||||
using ChatController.ChatKlassen;
|
||||
using ChatController.Extensions;
|
||||
using ChatController.HauptKlassen;
|
||||
using ChatController.LoginKlassen;
|
||||
using ChatController.Utilities;
|
||||
using ChatController.Utilities.Extensions;
|
||||
|
||||
using Button = System.Windows.Controls.Button;
|
||||
using Cursors = System.Windows.Input.Cursors;
|
||||
using DataFormats = System.Windows.DataFormats;
|
||||
@@ -35,7 +37,7 @@ using Timer = System.Windows.Forms.Timer;
|
||||
|
||||
namespace ChatController
|
||||
{
|
||||
public partial class ChatMainControl
|
||||
public partial class ChatMainControl : INotifyPropertyChanged
|
||||
{
|
||||
private readonly Dictionary<long, List<NotifyIcon>> _Group2NotifyIcons = new Dictionary<long, List<NotifyIcon>>();
|
||||
|
||||
@@ -50,6 +52,7 @@ namespace ChatController
|
||||
set
|
||||
{
|
||||
_ContainingWindow = value;
|
||||
|
||||
if(value != null)
|
||||
{
|
||||
_ContainingWindow.Deactivated += ContainingWindowOnDeactivated;
|
||||
@@ -59,11 +62,49 @@ namespace ChatController
|
||||
}
|
||||
|
||||
private Chat _Chat;
|
||||
private CurrentContact _CurrentContact;
|
||||
private Contact _CurrentContact;
|
||||
|
||||
private bool _IsChatBoxOnFocus;
|
||||
public ObservableCollection<ChatMessage> CurrentChatMessages => _CurrentContact != null && _Chat != null ? new ObservableCollection<ChatMessage>(_Chat.Messages) : new ObservableCollection<ChatMessage>();
|
||||
|
||||
private IOrderedEnumerable<Contact> _ContactList;
|
||||
public Contact CurrentContact
|
||||
{
|
||||
get => _CurrentContact;
|
||||
|
||||
set
|
||||
{
|
||||
if(!Equals(_CurrentContact, value))
|
||||
{
|
||||
_CurrentContact = value;
|
||||
|
||||
OnPropertyChanged(nameof(CurrentContact));
|
||||
OnPropertyChanged(nameof(ChatMessageInputGridVisibility));
|
||||
OnPropertyChanged(nameof(CurrentChatMessages));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<Contact> ContactList
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ContactList == null ? new ObservableCollection<Contact>() : new ObservableCollection<Contact>(_ContactList.OrderByDescending(contact => contact.TimeStamp));
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility ChatMessageInputGridVisibility
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_CurrentContact == null)
|
||||
{
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return _CurrentContact.IsChatMessageInputGridVisible ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Contact> _ContactList;
|
||||
|
||||
private bool _ScrollPrueferAktivieren;
|
||||
|
||||
@@ -81,6 +122,8 @@ namespace ChatController
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = this;
|
||||
|
||||
ReloadGruppen.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
@@ -96,11 +139,15 @@ namespace ChatController
|
||||
|
||||
public void InitMitChatdaten(ChatDatenUebergabe cdu)
|
||||
{
|
||||
_Chat = new Chat(cdu);
|
||||
_Chat = new Chat(cdu, exception => {
|
||||
this.Dispatch(() => {
|
||||
EndWaiting();
|
||||
MessageBox.Show($"Fehler: {exception.Message}", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
});
|
||||
});
|
||||
|
||||
_ContactList = _Chat.AddContacts();
|
||||
|
||||
Clientlist.ItemsSource = _ContactList;
|
||||
OnPropertyChanged(nameof(ContactList));
|
||||
|
||||
ReadNewSyncFile();
|
||||
|
||||
@@ -118,9 +165,6 @@ namespace ChatController
|
||||
}
|
||||
}
|
||||
|
||||
var view = (CollectionView) CollectionViewSource.GetDefaultView(Clientlist.ItemsSource);
|
||||
view.Filter = UserFilter;
|
||||
|
||||
GlobalListeningThreadtimer?.Stop();
|
||||
GlobalListeningThreadtimer = null;
|
||||
InitGlobalListeningThread();
|
||||
@@ -205,6 +249,7 @@ namespace ChatController
|
||||
}
|
||||
}
|
||||
|
||||
// WebRequest: LoadChatMessagesForContact
|
||||
private void SelectContact(Contact pContact)
|
||||
{
|
||||
if(pContact == null)
|
||||
@@ -226,7 +271,7 @@ namespace ChatController
|
||||
Clientlist.Items.Refresh();
|
||||
}
|
||||
|
||||
var currentContact = new CurrentContact(pContact);
|
||||
var currentContact = pContact;
|
||||
pContact.IsNewMessage = false;
|
||||
|
||||
var shouldChangeIcon = _ContactList.Any(contact => contact.IsNewMessage);
|
||||
@@ -236,7 +281,7 @@ namespace ChatController
|
||||
}
|
||||
|
||||
AktChatUserList.Items.Add(currentContact);
|
||||
_CurrentContact = currentContact;
|
||||
CurrentContact = currentContact;
|
||||
|
||||
if(Clientlist.Items.Contains(pContact))
|
||||
{
|
||||
@@ -245,7 +290,7 @@ namespace ChatController
|
||||
|
||||
var chatMessages = _Chat.LoadChatMessagesForContact(currentContact);
|
||||
|
||||
ChatListBox.ItemsSource = chatMessages;
|
||||
OnPropertyChanged(nameof(CurrentChatMessages));
|
||||
|
||||
if (VisualTreeHelper.GetChildrenCount(ChatListBox) > 0)
|
||||
{
|
||||
@@ -270,192 +315,215 @@ namespace ChatController
|
||||
{
|
||||
var contextItems = ChatListBox?.ContextMenu?.Items;
|
||||
|
||||
if(contextItems == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var menuItemText in _MenuItemName2Callback.Keys)
|
||||
{
|
||||
var cb = _MenuItemName2Callback[menuItemText];
|
||||
var callback = _MenuItemName2Callback[menuItemText];
|
||||
|
||||
var menuItem = new MenuItem();
|
||||
|
||||
menuItem.Click += (s, e2) =>
|
||||
{
|
||||
cb(menuItemText);
|
||||
callback(menuItemText);
|
||||
};
|
||||
|
||||
menuItem.Header = menuItemText;
|
||||
|
||||
contextItems.Add(menuItem);
|
||||
}
|
||||
|
||||
var item2 = (MenuItem)contextItems[0];
|
||||
item2.Click += Item2OnClick; // umbenenen in Speichern unter
|
||||
var item3 = (MenuItem)contextItems[1];
|
||||
item3.Click += Item3OnClick; //Umbenenen in Einfügen
|
||||
if(contextItems.Count > 0)
|
||||
{
|
||||
var saveAsMenuItem = (MenuItem) contextItems[0];
|
||||
saveAsMenuItem.Click += SaveAsOnClick;
|
||||
}
|
||||
|
||||
if(contextItems.Count > 1)
|
||||
{
|
||||
var pasteMenuItem = (MenuItem) contextItems[1];
|
||||
pasteMenuItem.Click += PasteOnClick;
|
||||
}
|
||||
|
||||
// neu und vor Einfügen setzen und anpassen
|
||||
var item4 = (MenuItem) contextItems[2];
|
||||
item4.Click += Item4OnClick; //Umbenenen in Kopieren
|
||||
|
||||
}
|
||||
|
||||
private void Item2OnClick(object sender, RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
foreach (var items in ChatListBox.SelectedItems)
|
||||
if(contextItems.Count > 2)
|
||||
{
|
||||
var item = (ChatMessage)items;
|
||||
|
||||
_Chat.SaveFileAs(item);
|
||||
var copyMenuItem = (MenuItem) contextItems[2];
|
||||
copyMenuItem.Click += CopyOnClick;
|
||||
}
|
||||
}
|
||||
|
||||
private void Item3OnClick(object sender, RoutedEventArgs routedEventArgs)
|
||||
private void SaveAsOnClick(object sender, RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
var kontakt = (CurrentContact)AktChatUserList.Items[0];
|
||||
foreach (var items in ChatListBox.SelectedItems)
|
||||
{
|
||||
var chatMessage = (ChatMessage) items;
|
||||
|
||||
_Chat.SaveFileAs(chatMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void PasteOnClick(object sender, RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
var kontakt = (Contact)AktChatUserList.Items[0];
|
||||
_Chat.Paste(kontakt.GroupId,this);
|
||||
}
|
||||
|
||||
private void Item4OnClick(object sender, RoutedEventArgs routedEventArgs)
|
||||
private void CopyOnClick(object sender, RoutedEventArgs routedEventArgs)
|
||||
{
|
||||
string chatmessages = "";
|
||||
var chatMessages = string.Empty;
|
||||
|
||||
foreach (var items in ChatListBox.SelectedItems)
|
||||
{
|
||||
var item = (ChatMessage)items;
|
||||
var item = (ChatMessage) items;
|
||||
|
||||
chatmessages += item.UserMessage + "\n";
|
||||
chatMessages += item.UserMessage + "\n";
|
||||
}
|
||||
|
||||
if(!chatmessages.Equals(""))
|
||||
_Chat.Copy(chatmessages, 1);
|
||||
if(!string.IsNullOrWhiteSpace(chatMessages))
|
||||
{
|
||||
_Chat.Copy(chatMessages, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void Chat_OnContextMenuOpening(object sender, ContextMenuEventArgs e)
|
||||
{
|
||||
var chatItems = ChatListBox.SelectedItems;
|
||||
|
||||
if (chatItems.Count > 0)
|
||||
if(ChatListBox?.ContextMenu == null)
|
||||
{
|
||||
foreach (var items in chatItems)
|
||||
return;
|
||||
}
|
||||
|
||||
if(ChatListBox.SelectedItems is List<ChatMessage> chatMessages)
|
||||
{
|
||||
if(chatMessages.Count > 0)
|
||||
{
|
||||
var item = items as ChatMessage;
|
||||
if (item != null && item.ImageSources != null)
|
||||
foreach(var items in chatMessages)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[0];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[0];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
var item = items as ChatMessage;
|
||||
if(item?.ImageSources != null)
|
||||
{
|
||||
if(ChatListBox.ContextMenu != null)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
((MenuItem)contextItems[0]).Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[0];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
if (item.ImageSources == null && item.FilePath == null)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem) contextItems[2];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[2];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
if(item.ImageSources == null && item.FilePath == null)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[2];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[2];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Schalte speichern unter Aus
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[0];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
//prüfe ob was in dem Speicher vorhanden ist //Einfügen
|
||||
var dataObject = System.Windows.Forms.Clipboard.GetDataObject();
|
||||
|
||||
if(dataObject != null && dataObject.GetDataPresent(DataFormats.FileDrop))
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem) contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if(dataObject != null && dataObject.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem) contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if(dataObject != null && dataObject.GetDataPresent(DataFormats.Bitmap))
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem) contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
//prüfe ob dokumentation erlaubt
|
||||
var kontakt = (Contact)AktChatUserList.Items[0];
|
||||
if(kontakt.UserIdManage == null && ChatListBox.ContextMenu.Items.Count > 3)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[3];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else if(ChatListBox.ContextMenu.Items.Count > 3)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[3];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
if(ChatListBox.ContextMenu.Items.Count == 0)
|
||||
{
|
||||
ChatListBox.ContextMenu.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Schalte speichern unter Aus
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[0];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
|
||||
//prüfe ob was in dem Speicher vorhanden ist //Einfügen
|
||||
var d = System.Windows.Forms.Clipboard.GetDataObject();
|
||||
|
||||
if (d.GetDataPresent(DataFormats.FileDrop))
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if (d.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if (d.GetDataPresent(DataFormats.Bitmap))
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[1];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
//prüfe ob dokumentation erlaubt
|
||||
var kontakt = (CurrentContact)AktChatUserList.Items[0];
|
||||
if (kontakt.UserIdManage == null && ChatListBox.ContextMenu.Items.Count > 3)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[3];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else if (ChatListBox.ContextMenu.Items.Count > 3)
|
||||
{
|
||||
var contextItems = ChatListBox.ContextMenu.Items;
|
||||
var ContextItemSpeichernUnter = (MenuItem)contextItems[3];
|
||||
ContextItemSpeichernUnter.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (ChatListBox.ContextMenu.Items.Count == 0)
|
||||
{
|
||||
ChatListBox.ContextMenu.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void MediaButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (AktChatUserList.Items.Count > 0)
|
||||
{
|
||||
var kontakt = (CurrentContact)AktChatUserList.Items[0];
|
||||
|
||||
var medium = _Chat.OpenFile();
|
||||
var fileToOpen = _Chat.OpenFile();
|
||||
|
||||
if(medium != null) {
|
||||
if(fileToOpen != null)
|
||||
{
|
||||
var filePath = FileUtils.ScaleImage(fileToOpen, Path.GetExtension(fileToOpen.ToUpperInvariant()), _Chat.ChatDaten.MaxUploadSize);
|
||||
|
||||
string convertetMedia = _Chat.ScaleImage(medium, Path.GetExtension(medium.ToUpperInvariant()));
|
||||
var isFileSizeTooLarge = FileUtils.CheckFileSize(filePath, _Chat.ChatDaten.MaxUploadSize);
|
||||
|
||||
if (!convertetMedia.Equals(""))
|
||||
if(isFileSizeTooLarge)
|
||||
{
|
||||
_Chat.AddNewFile(convertetMedia,medium,kontakt.GroupId);
|
||||
MessageBox.Show($"Die ausgewählte Datei ist zu groß. Die maximale Größe beträgt {_Chat.ChatDaten.MaxUploadSize / 1000 / 1000} MB", "Senden nicht möglich", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
CollectionViewSource.GetDefaultView(ChatListBox.ItemsSource).Refresh();
|
||||
if (!string.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
//_Chat.AddNewFile(filePath, fileToOpen, CurrentContact.GroupId);
|
||||
|
||||
OnPropertyChanged(nameof(CurrentChatMessages));
|
||||
|
||||
ChatListBox.Items.MoveCurrentToLast();
|
||||
ChatListBox.ScrollIntoView(ChatListBox.Items.CurrentItem);
|
||||
|
||||
_Chat.SendFileToContact(kontakt, convertetMedia,medium);
|
||||
_Chat.SendFileToContact(CurrentContact, filePath,fileToOpen);
|
||||
|
||||
if (!convertetMedia.Equals("") && !convertetMedia.Equals(medium) && File.Exists(convertetMedia))
|
||||
if (!string.IsNullOrWhiteSpace(filePath) && !filePath.Equals(fileToOpen) && File.Exists(filePath))
|
||||
{
|
||||
File.Delete(convertetMedia);
|
||||
File.Delete(filePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Die gewählte Datei ist zu groß!", "Fehler", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -466,51 +534,18 @@ namespace ChatController
|
||||
|
||||
private void SendButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!AktChatUserList.Items.IsEmpty && !Chatbox.Text.Equals("") && _IsChatBoxOnFocus)
|
||||
if (!AktChatUserList.Items.IsEmpty && !string.IsNullOrEmpty(Chatbox.Text))
|
||||
{
|
||||
if (!Chatbox.Text.Equals(""))
|
||||
{
|
||||
var kontakt = (CurrentContact)AktChatUserList.Items[0];
|
||||
|
||||
_Chat.AddNewMessage(Chatbox.Text, kontakt.GroupId);
|
||||
|
||||
CollectionViewSource.GetDefaultView(ChatListBox.ItemsSource).Refresh();
|
||||
_Chat.AddNewMessage(Chatbox.Text, CurrentContact.GroupId);
|
||||
|
||||
ChatListBox.Items.MoveCurrentToLast();
|
||||
ChatListBox.ScrollIntoView(ChatListBox.Items.CurrentItem);
|
||||
|
||||
_Chat.SendMessage(Chatbox.Text, kontakt.GroupId);
|
||||
OnPropertyChanged(nameof(CurrentChatMessages));
|
||||
|
||||
Chatbox.Text = "";
|
||||
|
||||
if (Chatbox.Text.Equals(""))
|
||||
{
|
||||
Chatbox.Text = "Nachricht schreiben";
|
||||
Chatbox.Foreground = new SolidColorBrush(Colors.DarkGray);
|
||||
_IsChatBoxOnFocus = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AktChatUserList.Items.IsEmpty)
|
||||
{
|
||||
MessageBox.Show("Bitte wählen Sie einen Chatpartner aus.", "Fehler", MessageBoxButton.OK);
|
||||
if (string.IsNullOrEmpty(Chatbox.Text))
|
||||
{
|
||||
Chatbox.Text = "Nachricht schreiben";
|
||||
Chatbox.Foreground = new SolidColorBrush(Colors.DarkGray);
|
||||
_IsChatBoxOnFocus = false;
|
||||
}
|
||||
}
|
||||
else if (string.IsNullOrEmpty(Chatbox.Text))
|
||||
{
|
||||
MessageBox.Show("Sie können keine leere Nachricht verschicken.", "Fehler", MessageBoxButton.OK);
|
||||
|
||||
Chatbox.Text = "Nachricht schreiben";
|
||||
Chatbox.Foreground = new SolidColorBrush(Colors.DarkGray);
|
||||
_IsChatBoxOnFocus = false;
|
||||
}
|
||||
ChatListBox.Items.MoveCurrentToLast();
|
||||
ChatListBox.ScrollIntoView(ChatListBox.Items.CurrentItem);
|
||||
|
||||
_Chat.SendMessage(Chatbox.Text, CurrentContact.GroupId);
|
||||
|
||||
Chatbox.Text = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -518,9 +553,8 @@ namespace ChatController
|
||||
{
|
||||
if (Chatbox.Text.Equals("Nachricht schreiben"))
|
||||
{
|
||||
Chatbox.Text = "";
|
||||
Chatbox.Text = string.Empty;
|
||||
Chatbox.Foreground = new SolidColorBrush(Colors.Black);
|
||||
_IsChatBoxOnFocus = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,32 +564,18 @@ namespace ChatController
|
||||
{
|
||||
if (e.Key == Key.Return)
|
||||
{
|
||||
if (!AktChatUserList.Items.IsEmpty && !Chatbox.Text.Equals(""))
|
||||
if (!AktChatUserList.Items.IsEmpty && !string.IsNullOrEmpty(Chatbox.Text))
|
||||
{
|
||||
var kontakt = (CurrentContact)AktChatUserList.Items[0];
|
||||
|
||||
_Chat.AddNewMessage(Chatbox.Text, kontakt.GroupId);
|
||||
|
||||
CollectionViewSource.GetDefaultView(ChatListBox.ItemsSource).Refresh();
|
||||
_Chat.AddNewMessage(Chatbox.Text, CurrentContact.GroupId);
|
||||
|
||||
OnPropertyChanged(nameof(CurrentChatMessages));
|
||||
|
||||
ChatListBox.Items.MoveCurrentToLast();
|
||||
ChatListBox.ScrollIntoView(ChatListBox.Items.CurrentItem);
|
||||
|
||||
_Chat.SendMessage(Chatbox.Text, kontakt.GroupId);
|
||||
_Chat.SendMessage(Chatbox.Text, CurrentContact.GroupId);
|
||||
|
||||
|
||||
Chatbox.Text = "";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AktChatUserList.Items.IsEmpty)
|
||||
{
|
||||
MessageBox.Show("Bitte wählen Sie einen Chatpartner aus.", "Fehler", MessageBoxButton.OK);
|
||||
}
|
||||
else if (Chatbox.Text.Equals(""))
|
||||
{
|
||||
MessageBox.Show("Sie können keine leere Nachricht verschicken.", "Fehler", MessageBoxButton.OK);
|
||||
}
|
||||
Chatbox.Text = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -570,17 +590,13 @@ namespace ChatController
|
||||
public event EmojiiDelegate OnEmojii;
|
||||
|
||||
private void EmojiButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//hier wie bei login
|
||||
if (OnEmojii != null)
|
||||
{
|
||||
OnEmojii(EmojiButton);
|
||||
}
|
||||
{
|
||||
OnEmojii?.Invoke(EmojiButton);
|
||||
}
|
||||
|
||||
private void Chat_OnScrollChanged(object sender, ScrollChangedEventArgs e)
|
||||
{
|
||||
var scrollBarList = GetVisualChildCollection<ScrollBar>(ChatListBox);
|
||||
var scrollBarList = Utils.GetVisualChildCollection<ScrollBar>(ChatListBox);
|
||||
foreach (var scrollBar in scrollBarList)
|
||||
{
|
||||
if (scrollBar.Orientation == Orientation.Horizontal)
|
||||
@@ -594,74 +610,46 @@ namespace ChatController
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Asynchron machen?
|
||||
private void VerticalScrollbarChanged(object sender, RoutedPropertyChangedEventArgs<double> routedPropertyChangedEventArgs)
|
||||
{
|
||||
if (_ScrollPrueferAktivieren == true)
|
||||
if (_ScrollPrueferAktivieren)
|
||||
{
|
||||
var x = (ScrollBar) sender;
|
||||
var scrollBar = (ScrollBar) sender;
|
||||
|
||||
if (x.Value > 0)
|
||||
{
|
||||
//nix
|
||||
}
|
||||
else
|
||||
if (!(scrollBar.Value > 0))
|
||||
{
|
||||
Cursor = Cursors.Wait;
|
||||
//StartWaiting();
|
||||
|
||||
_ScrollPrueferAktivieren = false;
|
||||
|
||||
ChatListBox.Items.MoveCurrentToFirst();
|
||||
ChatMessage item = ChatListBox.Items.CurrentItem as ChatMessage;
|
||||
var currentChatMessage = ChatListBox.Items.CurrentItem as ChatMessage;
|
||||
|
||||
ChatListBox.ItemsSource = null;
|
||||
var kontakt = (Contact) Clientlist.SelectedItem;
|
||||
|
||||
var kontakt = (Contact)Clientlist.SelectedItem;
|
||||
_Chat.LoadMoreMessages(kontakt); // Ab hier käme das ins Callback
|
||||
|
||||
var xy = _Chat.LoadMoreMessages(kontakt);
|
||||
OnPropertyChanged(nameof(CurrentChatMessages));
|
||||
|
||||
ChatListBox.ItemsSource = xy;
|
||||
|
||||
ChatListBox.ScrollIntoView(item);
|
||||
//EndWaiting();
|
||||
if(currentChatMessage != null)
|
||||
{
|
||||
ChatListBox.ScrollIntoView(currentChatMessage);
|
||||
}
|
||||
|
||||
Cursor = Cursors.Arrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<T> GetVisualChildCollection<T>(object parent) where T : Visual
|
||||
{
|
||||
var visualCollection = new List<T>();
|
||||
GetVisualChildCollection(parent as DependencyObject, visualCollection);
|
||||
|
||||
return visualCollection;
|
||||
}
|
||||
|
||||
private static void GetVisualChildCollection<T>(DependencyObject parent, ICollection<T> visualCollection) where T : Visual
|
||||
{
|
||||
var count = VisualTreeHelper.GetChildrenCount(parent);
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(parent, i);
|
||||
|
||||
if (child is T item)
|
||||
{
|
||||
visualCollection.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetVisualChildCollection(child, visualCollection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ListenForMessages()
|
||||
{
|
||||
_ListeningThreadTimer?.Stop();
|
||||
_ListeningThreadTimer = null;
|
||||
InitListeningThread((CurrentContact)AktChatUserList.Items[0]);
|
||||
EmojisListeningThreadTimer?.Stop();
|
||||
EmojisListeningThreadTimer = null;
|
||||
InitListeningThread((Contact)AktChatUserList.Items[0]);
|
||||
}
|
||||
|
||||
public Timer _ListeningThreadTimer;
|
||||
public Timer EmojisListeningThreadTimer;
|
||||
public Timer GlobalListeningThreadtimer { get; set; }
|
||||
|
||||
private void InitGlobalListeningThread()
|
||||
@@ -689,11 +677,11 @@ namespace ChatController
|
||||
{
|
||||
var contacts = _Chat.NeueGroupklassenKontakte().ToList();
|
||||
|
||||
CurrentContact currentContact = null;
|
||||
Contact currentContact = null;
|
||||
|
||||
if (AktChatUserList.HasItems)
|
||||
{
|
||||
currentContact = (CurrentContact)AktChatUserList.Items[0];
|
||||
currentContact = (Contact) AktChatUserList.Items[0];
|
||||
}
|
||||
|
||||
foreach (var contact in _ContactList)
|
||||
@@ -709,7 +697,7 @@ namespace ChatController
|
||||
contact.TimeStamp = newContact.TimeStamp;
|
||||
|
||||
// TODO: Prüfen, ob die App im Hintergrund oder minimiert ist
|
||||
if ((Clientlist.SelectedItem != null && !((Contact)Clientlist.SelectedItem).GroupId.Equals(newContact.GroupId) || Clientlist.SelectedItem == null) || _IsInBackground)
|
||||
if (Clientlist.SelectedItem != null && !((Contact)Clientlist.SelectedItem).GroupId.Equals(newContact.GroupId) || Clientlist.SelectedItem == null || _IsInBackground)
|
||||
{
|
||||
ContainingWindow.Icon = Utils.GetImageSourceFromIcon(Resource.oC_favico_NewMessage);
|
||||
ShowNotification(newContact.Name, newContact.ReceivedMessage, newContact.GroupId);
|
||||
@@ -745,20 +733,20 @@ namespace ChatController
|
||||
}
|
||||
}
|
||||
|
||||
private void InitListeningThread(CurrentContact pCurrentContacObject)
|
||||
private void InitListeningThread(Contact currentContact)
|
||||
{
|
||||
_ListeningThreadTimer = new Timer {Tag = pCurrentContacObject};
|
||||
_ListeningThreadTimer.Tick += ListeningThreadTimerTickEvent;
|
||||
_ListeningThreadTimer.Interval = 2000;
|
||||
_ListeningThreadTimer.Start();
|
||||
EmojisListeningThreadTimer = new Timer {Tag = currentContact};
|
||||
EmojisListeningThreadTimer.Tick += ListeningThreadTimerTickEvent;
|
||||
EmojisListeningThreadTimer.Interval = 2000;
|
||||
EmojisListeningThreadTimer.Start();
|
||||
}
|
||||
|
||||
private void ListeningThreadTimerTickEvent(object sender, EventArgs e)
|
||||
{
|
||||
ListenForMessagesForCurrentContact((CurrentContact) ((Timer) sender).Tag);
|
||||
ListenForMessagesForCurrentContact((Contact) ((Timer) sender).Tag);
|
||||
}
|
||||
|
||||
private void ListenForMessagesForCurrentContact(CurrentContact pCurrentContact)
|
||||
private void ListenForMessagesForCurrentContact(Contact pCurrentContact)
|
||||
{
|
||||
if (!ShouldInterruptContactsThread)
|
||||
{
|
||||
@@ -771,7 +759,7 @@ namespace ChatController
|
||||
{
|
||||
_Chat.LoadChatMessagesForContact(pCurrentContact);
|
||||
|
||||
CollectionViewSource.GetDefaultView(ChatListBox.ItemsSource).Refresh();
|
||||
OnPropertyChanged(nameof(CurrentChatMessages));
|
||||
|
||||
ChatListBox.Items.MoveCurrentToLast();
|
||||
ChatListBox.ScrollIntoView(ChatListBox.Items.CurrentItem);
|
||||
@@ -782,15 +770,18 @@ namespace ChatController
|
||||
|
||||
private void Suche_OnTextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
OnPropertyChanged(nameof(CurrentChatMessages));
|
||||
CollectionViewSource.GetDefaultView(Clientlist.ItemsSource).Refresh();
|
||||
}
|
||||
|
||||
private bool UserFilter(object item)
|
||||
{
|
||||
if (String.IsNullOrEmpty(Suche.Text))
|
||||
if (string.IsNullOrEmpty(Suche.Text))
|
||||
{
|
||||
return true;
|
||||
else
|
||||
return ((item as Contact).Name.IndexOf(Suche.Text, StringComparison.OrdinalIgnoreCase) >= 0);
|
||||
}
|
||||
|
||||
return (item as Contact).Name.IndexOf(Suche.Text, StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
|
||||
private void Chat_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
@@ -798,19 +789,20 @@ namespace ChatController
|
||||
Cursor = Cursors.Wait;
|
||||
|
||||
var chatItems = ChatListBox.SelectedItems;
|
||||
|
||||
|
||||
if (chatItems.Count > 0)
|
||||
{
|
||||
foreach (var items in chatItems)
|
||||
{
|
||||
var item = items as ChatMessage;
|
||||
|
||||
if (item != null && item.ImageSources != null)
|
||||
if (item?.OriginalImage != null)
|
||||
{
|
||||
StartWaiting();
|
||||
_Chat.ShowPicture(item, EndWaiting);
|
||||
StartWaitingImmediately();
|
||||
|
||||
_Chat.ShowPicture(item.OriginalImage, EndWaiting);
|
||||
}
|
||||
else if(item != null && item.FilePath != null)
|
||||
else if(item?.FilePath != null)
|
||||
{
|
||||
var filename = Path.GetFileName(item.FilePath.ToString());
|
||||
LoadDocument(item.FilePath.ToString(), filename);
|
||||
@@ -860,7 +852,7 @@ namespace ChatController
|
||||
}
|
||||
}
|
||||
|
||||
private ChatControlWaitLayer _waitLayer;
|
||||
private ChatControlWaitLayer _WaitLayer;
|
||||
|
||||
public void StartWaiting()
|
||||
{
|
||||
@@ -869,14 +861,13 @@ namespace ChatController
|
||||
|
||||
public void StartWaitingImmediately()
|
||||
{
|
||||
if (_waitLayer == null)
|
||||
if (_WaitLayer == null)
|
||||
{
|
||||
_waitLayer = new ChatControlWaitLayer();
|
||||
//Grid.SetColumnSpan(_waitLayer, 3);
|
||||
Grid.SetRowSpan(_waitLayer, 3);
|
||||
GridRechts.Children.Add(_waitLayer);
|
||||
Panel.SetZIndex(_waitLayer, int.MaxValue);
|
||||
_waitLayer.RefreshChatUI();
|
||||
_WaitLayer = new ChatControlWaitLayer();
|
||||
Grid.SetRowSpan(_WaitLayer, 3);
|
||||
RootGrid.Children.Add(_WaitLayer);
|
||||
Panel.SetZIndex(_WaitLayer, int.MaxValue);
|
||||
_WaitLayer.RefreshChatUI();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -884,12 +875,12 @@ namespace ChatController
|
||||
{
|
||||
Dispatcher.BeginInvoke(
|
||||
DispatcherPriority.Background,
|
||||
(Action)delegate
|
||||
(Action) delegate
|
||||
{
|
||||
if (_waitLayer != null)
|
||||
if(_WaitLayer != null)
|
||||
{
|
||||
GridRechts.Children.Remove(_waitLayer);
|
||||
_waitLayer = null;
|
||||
RootGrid.Children.Remove(_WaitLayer);
|
||||
_WaitLayer = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -908,22 +899,26 @@ namespace ChatController
|
||||
{
|
||||
try
|
||||
{
|
||||
Cursor = Cursors.Wait;
|
||||
StartWaitingImmediately();
|
||||
|
||||
WriteToNewSyncFile();
|
||||
|
||||
var aktuelleGruppen = _Chat.UpdateGroups();
|
||||
_Chat.ReloadGroupsAsync(data =>
|
||||
{
|
||||
this.Dispatch(() =>
|
||||
{
|
||||
_ContactList = _Chat.GroupklassenAktuallisieren(data); // <- dauert eine Sekunde!
|
||||
OnPropertyChanged(nameof(ContactList));
|
||||
|
||||
_ContactList = _Chat.GroupklassenAktuallisieren(aktuelleGruppen);
|
||||
ReadNewSyncFile();
|
||||
|
||||
ReadNewSyncFile();
|
||||
|
||||
Clientlist.Items.Refresh();
|
||||
|
||||
Cursor = Cursors.Arrow;
|
||||
EndWaiting();
|
||||
});
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
EndWaiting();
|
||||
MessageBox.Show("Ein Fehler bei der Synchronisation ist aufgetreten.\nFehler:\n" + e.Message, "Fehler", MessageBoxButton.OK);
|
||||
}
|
||||
}
|
||||
@@ -1008,6 +1003,7 @@ namespace ChatController
|
||||
}
|
||||
}
|
||||
|
||||
// Wird im BeWoPlaner benutzt
|
||||
public List<Contact> GetContactsWithoutUnreadMessages()
|
||||
{
|
||||
var contacts = new List<Contact>();
|
||||
@@ -1025,6 +1021,7 @@ namespace ChatController
|
||||
return contacts;
|
||||
}
|
||||
|
||||
// Wird im BeWoPlaner benutzt
|
||||
public void ResetNumberOfUnreadMessages(Dictionary<long, DateTime> pGroupId2DateTime)
|
||||
{
|
||||
if(pGroupId2DateTime != null)
|
||||
@@ -1042,6 +1039,7 @@ namespace ChatController
|
||||
}
|
||||
}
|
||||
|
||||
// Wird im BeWoPlaner benutzt
|
||||
public List<ChatMessage> GetSelectedMessages()
|
||||
{
|
||||
var messages = (from object selectedItem in ChatListBox.SelectedItems select selectedItem as ChatMessage).ToList();
|
||||
@@ -1049,11 +1047,12 @@ namespace ChatController
|
||||
return messages.Count > 0 ? messages : null;
|
||||
}
|
||||
|
||||
public CurrentContact GetCurrentContact()
|
||||
// Wird im BeWoPlaner benutzt
|
||||
public Contact GetCurrentContact()
|
||||
{
|
||||
if(AktChatUserList != null && AktChatUserList.Items.Count > 0)
|
||||
{
|
||||
var contact = (CurrentContact) AktChatUserList.Items[0];
|
||||
var contact = (Contact) AktChatUserList.Items[0];
|
||||
|
||||
return contact.UserIdManage == null ? null : contact;
|
||||
}
|
||||
@@ -1061,6 +1060,7 @@ namespace ChatController
|
||||
return null;
|
||||
}
|
||||
|
||||
// Wird im BeWoPlaner benutzt
|
||||
public void AddContextMenu(string menuItemText, Action<string> callBackAction)
|
||||
{
|
||||
if (!_MenuItemName2Callback.ContainsKey(menuItemText))
|
||||
@@ -1069,7 +1069,7 @@ namespace ChatController
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteTempFiles()
|
||||
public void DeleteTempFiles()
|
||||
{
|
||||
foreach (var file in _CreatedTempFiles)
|
||||
{
|
||||
@@ -1086,5 +1086,19 @@ namespace ChatController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private void ChatMainControl_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var view = (CollectionView)CollectionViewSource.GetDefaultView(Clientlist.ItemsSource);
|
||||
view.Filter = UserFilter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user