Username change now dirty reactive in ui

This commit is contained in:
Patrick Hellebrand
2021-09-23 14:02:42 +02:00
committed by Felix Hartmann (PEA3-Fe-FI)
parent 7286b211bf
commit 43d8b2919c
3 changed files with 23 additions and 17 deletions

View File

@@ -36,9 +36,14 @@ namespace PolyChat
{
UIController = uiController;
OwnIP = getIP();
loadChats();
//loadChats();
//SaveChats("10", "{das ist ein test}");
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)
@@ -69,7 +74,7 @@ namespace PolyChat
{
Debug.WriteLine("--- Client connected! ---");
// setup event listeners
socket.On("initial", async (JToken[] data) =>
socket.On("initial", (JToken[] data) =>
{
Debug.WriteLine("--- initial packet received ---");
string ForeignIp = data[0].ToString();

View File

@@ -26,6 +26,7 @@ namespace PolyChat
private ObservableCollection<ChatPartner> Partners;
private ChatPartner selectedPartner = null;
private string username;
public MainPage()
{
this.InitializeComponent();
@@ -80,6 +81,14 @@ namespace PolyChat
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();
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
@@ -138,7 +147,10 @@ namespace PolyChat
{
case "username":
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;
default:
sendingPartner.AddMessage(new ChatMessage(origin, type, content, timeStamp));
@@ -159,7 +171,7 @@ namespace PolyChat
origin,
item["type"].ToString(),
item["content"].ToString()//,
//DateTime.Parse(item["timestamp"].ToString())
//DateTime.Parse(item["timestamp"].ToString())
)
);
}

View File

@@ -1,17 +1,17 @@
using SocketIOSharp.Server.Client;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace PolyChat.Models
{
public class ChatPartner : INotifyPropertyChanged
public class ChatPartner
{
public string Name;
public string Code;
public ObservableCollection<ChatMessage> Messages;
private SocketIOSocket socketIOSocket;
public event PropertyChangedEventHandler PropertyChanged;
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; }
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void AddMessage(ChatMessage message)
{
Messages.Add(message);
}
public void SetName(string name)
{
Name = name;
NotifyPropertyChanged("Name");
}
}
}