Username change now dirty reactive in ui
This commit is contained in:
@@ -37,9 +37,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)
|
||||
@@ -70,7 +75,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();
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user