diff --git a/PolyChat/Controller.cs b/PolyChat/Controller.cs index b7573d5..5f114e6 100644 --- a/PolyChat/Controller.cs +++ b/PolyChat/Controller.cs @@ -145,9 +145,11 @@ namespace PolyChat private bool isInConnections(string IP) { - if (Connections.ContainsKey(IP)) - return true; - return false; + return Connections.ContainsKey(IP); + } + public bool IsConnected(string ip) + { + return Connections.ContainsKey(ip) && Connections[ip].IsConnected(); } public static string getIP() @@ -195,7 +197,6 @@ namespace PolyChat ip = ip.Substring(0, ip.Length - 4); Debug.WriteLine($"-{ip}"); Debug.WriteLine(jsonArr); - Connect(ip); UIController.OnIncomingConnection(ip); UIController.OnIncomingMessages(ip, jsonArr); } diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs index 2f4788a..06a9db4 100644 --- a/PolyChat/MainPage.xaml.cs +++ b/PolyChat/MainPage.xaml.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Windows.UI.Core; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Data; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 @@ -83,7 +84,7 @@ namespace PolyChat var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { - string ip = IP.GetIPfromCode(dialog.getValue()); + string ip = IP.GetIPFromCode(dialog.getValue()); Controller.Connect(ip); Partners.Add(new ChatPartner( "Connecting...", @@ -136,6 +137,7 @@ namespace PolyChat switch (type) { case "username": + Debug.WriteLine($"! username change for {sendingPartner.Code} -> {content}"); sendingPartner.SetName(Name); break; default: @@ -190,6 +192,7 @@ namespace PolyChat listViewMessages.ItemsSource = selectedPartner.Messages; selectedPartnerName.Text = selectedPartner.Name; updateNoChatSelected(); + if (!Controller.IsConnected(code)) Controller.Connect(code); } private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) diff --git a/PolyChat/Models/ChatPartner.cs b/PolyChat/Models/ChatPartner.cs index 118b7af..32df3be 100644 --- a/PolyChat/Models/ChatPartner.cs +++ b/PolyChat/Models/ChatPartner.cs @@ -1,14 +1,17 @@ using SocketIOSharp.Server.Client; using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Runtime.CompilerServices; namespace PolyChat.Models { - public class ChatPartner + public class ChatPartner : INotifyPropertyChanged { public string Name; public string Code; public ObservableCollection Messages; private SocketIOSocket socketIOSocket; + public event PropertyChangedEventHandler PropertyChanged; public ChatPartner(string name, string code, ObservableCollection messages = null) { @@ -20,6 +23,11 @@ namespace PolyChat.Models public SocketIOSocket SocketIOSocket { get => socketIOSocket; set => socketIOSocket = value; } + private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + public void AddMessage(ChatMessage message) { Messages.Add(message); @@ -28,6 +36,7 @@ namespace PolyChat.Models public void SetName(string name) { Name = name; + NotifyPropertyChanged("Name"); } } } \ No newline at end of file diff --git a/PolyChat/Package.appxmanifest b/PolyChat/Package.appxmanifest index 06228f6..30ac9c8 100644 --- a/PolyChat/Package.appxmanifest +++ b/PolyChat/Package.appxmanifest @@ -9,8 +9,8 @@ + Publisher="CN=PatrickMarcFelix" + Version="0.1.0.0" /> diff --git a/PolyChat/PolyChat.csproj b/PolyChat/PolyChat.csproj index 418a809..12041a4 100644 --- a/PolyChat/PolyChat.csproj +++ b/PolyChat/PolyChat.csproj @@ -17,7 +17,15 @@ 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} true - false + False + False + False + True + Always + x86 + 0 + 6B0D12FC4E83C6F6997C60706A04799ED44B7E56 + SHA256 true @@ -195,6 +203,9 @@ 5.0.2 + + + 14.0 diff --git a/PolyChat/Util/IP.cs b/PolyChat/Util/IP.cs index fcb6fd6..975dcd1 100644 --- a/PolyChat/Util/IP.cs +++ b/PolyChat/Util/IP.cs @@ -7,7 +7,7 @@ namespace PolyChat.Util { private const string REGEX_IP = @"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$"; - public static string GetIPfromCode(string code) + public static string GetIPFromCode(string code) { return code; } diff --git a/PolyChat/Views/NewChatDialog.xaml.cs b/PolyChat/Views/NewChatDialog.xaml.cs index 600c62f..4c888ba 100644 --- a/PolyChat/Views/NewChatDialog.xaml.cs +++ b/PolyChat/Views/NewChatDialog.xaml.cs @@ -29,7 +29,7 @@ namespace PolyChat.Views private void OnKeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) { - if (!IP.ValidateIP(IP.GetIPfromCode(input.Text))) + if (!IP.ValidateIP(IP.GetIPFromCode(input.Text))) { textSuccess.Visibility = Visibility.Collapsed; textError.Visibility = Visibility.Visible;