2024-08-15 11:45:39 +02:00
|
|
|
|
using Microsoft.Win32;
|
2024-07-01 16:21:03 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Threading;
|
2024-07-03 15:58:51 +02:00
|
|
|
|
using bib_talk.Business;
|
2024-08-29 18:41:36 +02:00
|
|
|
|
using System.Windows.Controls;
|
2024-07-01 16:21:03 +02:00
|
|
|
|
|
|
|
|
|
namespace bib_talk
|
|
|
|
|
{
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
2024-08-28 13:53:39 +02:00
|
|
|
|
MainWindowManager mwManager; // MainWindowManager initializeren
|
2024-07-01 16:21:03 +02:00
|
|
|
|
|
2024-08-28 13:53:39 +02:00
|
|
|
|
private DispatcherTimer _timer; // DispatcherTimer initialisieren
|
|
|
|
|
public string loggedinUser; // Feld um eingeloggten User zu speichern
|
|
|
|
|
private bool isFirstLoad = true;
|
2024-07-01 16:21:03 +02:00
|
|
|
|
|
2024-08-28 13:53:39 +02:00
|
|
|
|
// MainWindow Konstruktor mit einem User und LoadMessages Methode
|
2024-07-01 16:21:03 +02:00
|
|
|
|
public MainWindow(string user)
|
|
|
|
|
{
|
|
|
|
|
loggedinUser = user;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitializeTimer();
|
|
|
|
|
LoadData();
|
|
|
|
|
|
2024-07-03 15:58:51 +02:00
|
|
|
|
mwManager = new MainWindowManager(this, user);
|
2024-07-01 16:21:03 +02:00
|
|
|
|
|
2024-07-03 15:58:51 +02:00
|
|
|
|
mwManager.LoadMessages();
|
2024-07-01 16:21:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 13:53:39 +02:00
|
|
|
|
// Der 3 Sekunden Timer für die Nachrichten und Online Benutzer
|
2024-07-01 16:21:03 +02:00
|
|
|
|
private void InitializeTimer()
|
|
|
|
|
{
|
|
|
|
|
_timer = new DispatcherTimer
|
|
|
|
|
{
|
|
|
|
|
Interval = TimeSpan.FromSeconds(2)
|
|
|
|
|
};
|
2024-07-03 15:58:51 +02:00
|
|
|
|
_timer.Tick += (sender, e) => { mwManager.LoadMessages(); mwManager.LoadOnlineUsers(); };
|
2024-07-01 16:21:03 +02:00
|
|
|
|
_timer.Start();
|
|
|
|
|
}
|
2024-08-28 13:53:39 +02:00
|
|
|
|
|
|
|
|
|
// Methode zum Usernamen in dem MainWindow anzeigen
|
2024-07-01 16:21:03 +02:00
|
|
|
|
public void LoadData()
|
|
|
|
|
{
|
2024-08-28 13:53:39 +02:00
|
|
|
|
loggedInUser.Text = "Logged in as: " + loggedinUser;
|
2024-07-01 16:21:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 13:53:39 +02:00
|
|
|
|
// Methode zum User ausloggen und App schließen
|
2024-07-01 16:21:03 +02:00
|
|
|
|
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2024-07-03 15:58:51 +02:00
|
|
|
|
mwManager.LogoutUser();
|
2024-07-01 16:21:03 +02:00
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 13:53:39 +02:00
|
|
|
|
// Custom DraggableArea für das MainWindow
|
2024-07-01 16:21:03 +02:00
|
|
|
|
private void DraggableArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.ButtonState == MouseButtonState.Pressed)
|
|
|
|
|
{
|
|
|
|
|
DragMove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 13:53:39 +02:00
|
|
|
|
// Hotkey (Enter) für das Senden einer Nachricht
|
|
|
|
|
private async void messageBox_KeyDown(object sender, KeyEventArgs e)
|
2024-07-01 16:21:03 +02:00
|
|
|
|
{
|
|
|
|
|
if (e.Key == Key.Enter)
|
|
|
|
|
{
|
2024-07-03 15:58:51 +02:00
|
|
|
|
mwManager.SendMessage();
|
2024-07-01 16:21:03 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 13:53:39 +02:00
|
|
|
|
// Senden Button für das Senden einer Nachricht
|
2024-07-01 16:21:03 +02:00
|
|
|
|
private async void send_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2024-07-03 15:58:51 +02:00
|
|
|
|
mwManager.SendMessage();
|
2024-07-01 16:21:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 13:53:39 +02:00
|
|
|
|
// Methode zum Profilbilder hochladen
|
|
|
|
|
private async void uploadpbclick(object sender, RoutedEventArgs e)
|
2024-07-02 22:40:43 +02:00
|
|
|
|
{
|
|
|
|
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
|
|
openFileDialog.Filter = "Image files (*.jpg, *.jpeg, *.png, *.gif) | *.jpg; *.jpeg; *.png; *.gif";
|
|
|
|
|
if (openFileDialog.ShowDialog() == true)
|
|
|
|
|
{
|
|
|
|
|
string filePath = openFileDialog.FileName;
|
2024-07-03 15:58:51 +02:00
|
|
|
|
await mwManager.UploadProfileImage(filePath);
|
2024-07-02 22:40:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-30 10:08:18 +02:00
|
|
|
|
|
2024-08-30 10:35:09 +02:00
|
|
|
|
#region Ohne Funktion (Fast)
|
|
|
|
|
// Chat Settings Logik
|
|
|
|
|
private void MenuButton_Click(object sender, RoutedEventArgs e)
|
2024-08-29 18:41:36 +02:00
|
|
|
|
{
|
|
|
|
|
// Öffnen Sie das Kontextmenü, wenn Sie auf den Drei-Punkte-Button klicken
|
|
|
|
|
contextMenu.IsOpen = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 10:08:18 +02:00
|
|
|
|
private void muteChatButton_Click(object sender, RoutedEventArgs e)
|
2024-08-29 18:41:36 +02:00
|
|
|
|
{
|
|
|
|
|
// Logik zum Blockieren eines Benutzers
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 10:08:18 +02:00
|
|
|
|
private void clearChatButton_Click(object sender, RoutedEventArgs e)
|
2024-08-29 18:41:36 +02:00
|
|
|
|
{
|
2024-08-30 10:35:09 +02:00
|
|
|
|
//Rufe die Methode zum Löschen des Chats auf
|
|
|
|
|
mwManager.DeleteMessages();
|
2024-08-29 18:41:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 10:08:18 +02:00
|
|
|
|
private void helpButton_Click(object sender, RoutedEventArgs e)
|
2024-08-29 18:41:36 +02:00
|
|
|
|
{
|
|
|
|
|
// Logik zum Entfernen eines Freundes
|
|
|
|
|
}
|
2024-08-30 10:35:09 +02:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
2024-07-01 16:21:03 +02:00
|
|
|
|
}
|