diff --git a/PolyChat/Controller.cs b/PolyChat/Controller.cs index 61793fb..0a7c9fe 100644 --- a/PolyChat/Controller.cs +++ b/PolyChat/Controller.cs @@ -99,12 +99,13 @@ namespace PolyChat Debug.WriteLine($"{type} -> {ip} content: {content}"); JObject json = new JObject( new JProperty("type", type), - new JProperty("content", content), - new JProperty("timestamp", DateTime.Now.ToString()) + new JProperty("content", content) ); Debug.WriteLine($"json: {json.ToString()}"); + // send as json Connections[ip].SendMessage(json.ToString()); - SaveChats(ip, json.ToString()); + // save to logs + SaveChats(ip, json.ToString(), DateTime.Now); } private void OnMessage(string ip, JToken[] data) @@ -112,9 +113,10 @@ namespace PolyChat Debug.WriteLine("--- Controller.OnMessage ---"); if (data != null && data.Length > 0 && data[0] != null) { + DateTime now = DateTime.Now; Debug.WriteLine("RAW: " + data[0]); - UIController.OnIncomingMessage(ip, data[0].ToString()); - SaveChats(ip, data[0].ToString()); + UIController.OnIncomingMessage(ip, data[0].ToString(), now); + SaveChats(ip, data[0].ToString(), now); } else Debug.WriteLine("Undefined: " + data); } @@ -199,10 +201,10 @@ namespace PolyChat /// /// /// - public void SaveChats(String ip, String json) + public void SaveChats(string ip, string json, DateTime timeStamp) { //Vielleicht noch so machen dass die mit gleicher ip nacheinander gemacht - //werden damit es ncith zu überschreibungen kommt vielleicth auch ganz oben oder am ende ne + //werden damit es nicht zu überschreibungen kommt vielleicth auch ganz oben oder am ende ne //writing flag setzen oder auch in der datei selbst ne flag setzen //also save fils from myself new Thread(() => @@ -217,6 +219,7 @@ namespace PolyChat { Debug.WriteLine("--adding new chatmessage--"); //structure intact + JObject obj = JObject.Parse(json); //save new chat String saved = output.Substring(0, output.Length - 1); output = saved + ", " + json + " ]"; diff --git a/PolyChat/MainPage.xaml.cs b/PolyChat/MainPage.xaml.cs index 7cc022e..c3c3b84 100644 --- a/PolyChat/MainPage.xaml.cs +++ b/PolyChat/MainPage.xaml.cs @@ -125,7 +125,7 @@ namespace PolyChat /// Adds an message to the UI, based on .sender if known /// /// ChatMessage - public async void OnIncomingMessage(string origin, string json) + public async void OnIncomingMessage(string origin, string json, DateTime timeStamp) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { @@ -139,7 +139,7 @@ namespace PolyChat sendingPartner.SetName(Name); break; default: - sendingPartner.AddMessage(new ChatMessage(origin, type, content)); + sendingPartner.AddMessage(new ChatMessage(origin, type, content, timeStamp)); break; } }); @@ -156,8 +156,8 @@ namespace PolyChat new ChatMessage( origin, item["type"].ToString(), - item["content"].ToString()//, - //DateTime.Parse(item["timestamp"].ToString()) + item["content"].ToString(), + DateTime.Parse(item["timestamp"].ToString()) ) ); } diff --git a/PolyChat/Models/ChatMessage.cs b/PolyChat/Models/ChatMessage.cs index 5757702..32e6f49 100644 --- a/PolyChat/Models/ChatMessage.cs +++ b/PolyChat/Models/ChatMessage.cs @@ -33,9 +33,9 @@ namespace PolyChat.Models /// Create Message loaded with timestamp /// /// Origin IP - /// Message Type - /// Message Content (not JSON) - /// Message Content (not JSON) + /// Message Type, usually "message" + /// Message Content, usually plain text + /// Parsed DateTime public ChatMessage(string origin, string type, string content, DateTime timeStamp, bool foreign = false) { Origin = origin;