delete chat only on explicit button press, not on disconnect, dialog opening fixed

This commit is contained in:
Felix Hartmann (PEA3-Fe-FI)
2021-09-23 14:50:35 +02:00
parent 7a273f7fdc
commit 4e60fd2bdb
5 changed files with 35 additions and 33 deletions

View File

@@ -96,7 +96,6 @@ namespace PolyChat
Debug.WriteLine("---- Added new Connection ----");
Connections.Add(ForeignIp, new Connection(socket, Data => OnMessage(ForeignIp, Data), CloseChat));
UIController.OnIncomingConnection(ForeignIp);
fileManager.loadChat(ForeignIp);
}
});
});
@@ -139,7 +138,7 @@ namespace PolyChat
else Debug.WriteLine("Undefined: " + data);
}
public void CloseChat(string IP, bool wasConnected = true)
public void CloseChat(string IP, bool wasConnected = true, bool delete = false)
{
Debug.WriteLine($"Deleting connection with IP:{IP}");
if (IP != null && Connections.ContainsKey(IP))
@@ -147,13 +146,17 @@ namespace PolyChat
Connections[IP].Close();
Connections.Remove(IP);
}
CloseChatUI(IP, wasConnected);
if (delete || !wasConnected)
CloseChatUI(IP, wasConnected, delete);
if (delete)
fileManager.deleteChat(IP);
}
private void CloseChatUI(string IP, bool wasConnected = true)
private void CloseChatUI(string IP, bool wasConnected = true, bool delete = false)
{
UIController.OnChatPartnerDeleted(IP);
string heading = wasConnected ? "Connection Closed" : "Connection Failed";
if(!delete)
UIController.ShowConnectionError(IP, heading, $"Connecting to {IP} failed...");
}

View File

@@ -66,6 +66,7 @@ namespace PolyChat
() => { /* do nothing */ }
)
);
SafelyOpenDialog(dialog);
});
}
@@ -184,7 +185,7 @@ namespace PolyChat
private void OnDeleteChat(object sender = null, RoutedEventArgs e = null)
{
Controller.CloseChat(selectedPartner.Code);
Controller.CloseChat(selectedPartner.Code,delete: true);
Partners.Remove(selectedPartner);
updateNoChatsPlaceholder();
updateNoChatSelected();

View File

@@ -15,9 +15,9 @@ namespace PolyChat.Models
private SocketIOSocket Socket;
private bool Connected = false;
private readonly string IP;
private Action<string, bool> DeleteConnection;
private Action<string, bool, bool> DeleteConnection;
public Connection(string ip, ushort port, Action<JToken[]> onMessage, Action<string, bool> onClose)
public Connection(string ip, ushort port, Action<JToken[]> onMessage, Action<string, bool, bool> onClose)
{
Debug.WriteLine("! CONNECTING TO SERVER !");
IP = ip;
@@ -32,7 +32,7 @@ namespace PolyChat.Models
Client.On("message", (Action<JToken[]>) onMessage);
}
public Connection(SocketIOSocket socket, Action<JToken[]> onMessage, Action<string, bool> onClose)
public Connection(SocketIOSocket socket, Action<JToken[]> onMessage, Action<string, bool, bool> onClose)
{
Socket = socket;
DeleteConnection = onClose;
@@ -66,7 +66,7 @@ namespace PolyChat.Models
{
Debug.WriteLine("--- Disconnected! ---");
Debug.WriteLine($"--- Deleting Connection with IP: {IP}---");
DeleteConnection(IP, IsConnected());
DeleteConnection(IP, IsConnected(),false);
Connected = false;
}
private void OnError(JToken[] data)

View File

@@ -36,7 +36,7 @@ namespace PolyChat.Models
{
foreach (String path in filepaths)
{
if (Path.GetFileName(path).Equals(ip))
if (Path.GetFileName(path).Equals(ip+".txt"))
{
File.Delete(path);
return;

View File

@@ -34,8 +34,6 @@ namespace PolyChat.Views
// TODO: use event handlers and asign actions here
Primary = primary.Action;
Secondary = secondary.Action;
// show
MainPage.SafelyOpenDialog(this);
}
private void setType(string type, string message)