Username change now dirty reactive in ui
This commit is contained in:
committed by
Felix Hartmann (PEA3-Fe-FI)
parent
7286b211bf
commit
43d8b2919c
@@ -36,9 +36,14 @@ namespace PolyChat
|
|||||||
{
|
{
|
||||||
UIController = uiController;
|
UIController = uiController;
|
||||||
OwnIP = getIP();
|
OwnIP = getIP();
|
||||||
loadChats();
|
//loadChats();
|
||||||
//SaveChats("10", "{das ist ein test}");
|
//SaveChats("10", "{das ist ein test}");
|
||||||
Serve();
|
Serve();
|
||||||
|
|
||||||
|
// test
|
||||||
|
UIController.OnIncomingConnection("1.1.1.1");
|
||||||
|
UIController.OnIncomingConnection("1.2.3.4");
|
||||||
|
UIController.OnIncomingConnection("1.2.4.8");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Connect(string ip)
|
public void Connect(string ip)
|
||||||
@@ -69,7 +74,7 @@ namespace PolyChat
|
|||||||
{
|
{
|
||||||
Debug.WriteLine("--- Client connected! ---");
|
Debug.WriteLine("--- Client connected! ---");
|
||||||
// setup event listeners
|
// setup event listeners
|
||||||
socket.On("initial", async (JToken[] data) =>
|
socket.On("initial", (JToken[] data) =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine("--- initial packet received ---");
|
Debug.WriteLine("--- initial packet received ---");
|
||||||
string ForeignIp = data[0].ToString();
|
string ForeignIp = data[0].ToString();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace PolyChat
|
|||||||
private ObservableCollection<ChatPartner> Partners;
|
private ObservableCollection<ChatPartner> Partners;
|
||||||
private ChatPartner selectedPartner = null;
|
private ChatPartner selectedPartner = null;
|
||||||
private string username;
|
private string username;
|
||||||
|
|
||||||
public MainPage()
|
public MainPage()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
@@ -80,6 +81,14 @@ namespace PolyChat
|
|||||||
|
|
||||||
public async void OnOpenNewChatDialog(object sender = null, RoutedEventArgs e = null)
|
public async void OnOpenNewChatDialog(object sender = null, RoutedEventArgs e = null)
|
||||||
{
|
{
|
||||||
|
OnIncomingMessage(
|
||||||
|
"1.1.1.1",
|
||||||
|
new JObject(
|
||||||
|
new JProperty("type", "username"),
|
||||||
|
new JProperty("content", "Cloudflare")
|
||||||
|
).ToString(),
|
||||||
|
DateTime.Now
|
||||||
|
);
|
||||||
NewChatDialog dialog = new NewChatDialog();
|
NewChatDialog dialog = new NewChatDialog();
|
||||||
var result = await dialog.ShowAsync();
|
var result = await dialog.ShowAsync();
|
||||||
if (result == ContentDialogResult.Primary)
|
if (result == ContentDialogResult.Primary)
|
||||||
@@ -138,7 +147,10 @@ namespace PolyChat
|
|||||||
{
|
{
|
||||||
case "username":
|
case "username":
|
||||||
Debug.WriteLine($"! username change for {sendingPartner.Code} -> {content}");
|
Debug.WriteLine($"! username change for {sendingPartner.Code} -> {content}");
|
||||||
sendingPartner.SetName(Name);
|
sendingPartner.Name = content;
|
||||||
|
int index = Partners.IndexOf(sendingPartner);
|
||||||
|
Partners.Remove(sendingPartner);
|
||||||
|
Partners.Insert(index, sendingPartner);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sendingPartner.AddMessage(new ChatMessage(origin, type, content, timeStamp));
|
sendingPartner.AddMessage(new ChatMessage(origin, type, content, timeStamp));
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
using SocketIOSharp.Server.Client;
|
using SocketIOSharp.Server.Client;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace PolyChat.Models
|
namespace PolyChat.Models
|
||||||
{
|
{
|
||||||
public class ChatPartner : INotifyPropertyChanged
|
public class ChatPartner
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
public string Code;
|
public string Code;
|
||||||
public ObservableCollection<ChatMessage> Messages;
|
public ObservableCollection<ChatMessage> Messages;
|
||||||
private SocketIOSocket socketIOSocket;
|
private SocketIOSocket socketIOSocket;
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
|
||||||
|
|
||||||
public ChatPartner(string name, string code, ObservableCollection<ChatMessage> messages = null)
|
public ChatPartner(string name, string code, ObservableCollection<ChatMessage> messages = null)
|
||||||
{
|
{
|
||||||
@@ -23,20 +23,9 @@ namespace PolyChat.Models
|
|||||||
|
|
||||||
public SocketIOSocket SocketIOSocket { get => socketIOSocket; set => socketIOSocket = value; }
|
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)
|
public void AddMessage(ChatMessage message)
|
||||||
{
|
{
|
||||||
Messages.Add(message);
|
Messages.Add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetName(string name)
|
|
||||||
{
|
|
||||||
Name = name;
|
|
||||||
NotifyPropertyChanged("Name");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user