From bb8b331267773218d628a993445751ae2ee3da20 Mon Sep 17 00:00:00 2001 From: Lyndon Date: Wed, 15 May 2019 14:57:16 +0200 Subject: [PATCH] Ungereimtheiten beim Konvertieren der Zeitangaben ausgemerzt. Manche Datumsangaben waren im lokalen Zeitformat und nicht im Utc-Format. --- ChatController/ChatController.csproj | 1 - ChatController/ChatMainControl.xaml.cs | 45 ++++++++++++++------------ ChatController/HauptKlassen/Chat.cs | 17 +--------- 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/ChatController/ChatController.csproj b/ChatController/ChatController.csproj index 6af1c1a..b411819 100644 --- a/ChatController/ChatController.csproj +++ b/ChatController/ChatController.csproj @@ -138,7 +138,6 @@ - diff --git a/ChatController/ChatMainControl.xaml.cs b/ChatController/ChatMainControl.xaml.cs index 442e72a..b7c34f2 100644 --- a/ChatController/ChatMainControl.xaml.cs +++ b/ChatController/ChatMainControl.xaml.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using System.Net; using System.Text; -using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -20,6 +19,7 @@ using ChatController.HauptKlassen; using ChatController.LoginKlassen; using ChatController.Utilities; using ChatController.Utilities.Extensions; + using Button = System.Windows.Controls.Button; using Cursors = System.Windows.Input.Cursors; using DataFormats = System.Windows.DataFormats; @@ -51,7 +51,7 @@ namespace ChatController private bool _ScrollPrueferAktivieren; - public bool _ShouldInterruptContactsThread = true; + public bool ShouldInterruptContactsThread = true; private readonly List _CreatedTempFiles = new List(); @@ -69,7 +69,7 @@ namespace ChatController public void InitMitChatdaten(ChatDatenUebergabe cdu) { _Chat = new Chat(cdu); - + _ContactList = _Chat.AddContacts(); Clientlist.ItemsSource = _ContactList; @@ -85,7 +85,7 @@ namespace ChatController var isYounger = contact.TimeStamp > dateTimeFromFile; - contact.IsNewMessage = isYounger || isUnread; + contact.IsNewMessage = isUnread; contact.HasUnreadMessages = contact.IsNewMessage; } } @@ -93,14 +93,14 @@ namespace ChatController var view = (CollectionView) CollectionViewSource.GetDefaultView(Clientlist.ItemsSource); view.Filter = UserFilter; - _GlobalListeningThreadtimer?.Stop(); - _GlobalListeningThreadtimer = null; + GlobalListeningThreadtimer?.Stop(); + GlobalListeningThreadtimer = null; InitGlobalListeningThread(); Clientlist.Items.Refresh(); } - public void ShowNotification(string pTitle, string pMessage, long pGroupId) + public void ShowNotification(string pTitle, string pMessage, int pGroupId) { if (!_Group2NotifyIcons.ContainsKey(pGroupId)) { @@ -172,7 +172,12 @@ namespace ChatController private void SelectContact(Contact pContact) { - _ShouldInterruptContactsThread = true; + if(pContact == null) + { + return; + } + + ShouldInterruptContactsThread = true; Cursor = Cursors.Wait; _ScrollPrueferAktivieren = false; @@ -218,7 +223,7 @@ namespace ChatController WriteToNewSyncFile(); - _ShouldInterruptContactsThread = false; + ShouldInterruptContactsThread = false; } private void SetContextHandler() @@ -616,15 +621,15 @@ namespace ChatController InitListeningThread((CurrentContact)AktChatUserList.Items[0]); } - private Timer _ListeningThreadTimer; - private Timer _GlobalListeningThreadtimer; + public Timer _ListeningThreadTimer; + public Timer GlobalListeningThreadtimer { get; set; } private void InitGlobalListeningThread() { - _GlobalListeningThreadtimer = new Timer(); - _GlobalListeningThreadtimer.Tick += GlobalListeningThreadTimerTickEvent; - _GlobalListeningThreadtimer.Interval = 2000; - _GlobalListeningThreadtimer.Start(); + GlobalListeningThreadtimer = new Timer(); + GlobalListeningThreadtimer.Tick += GlobalListeningThreadTimerTickEvent; + GlobalListeningThreadtimer.Interval = 2000; + GlobalListeningThreadtimer.Start(); } private void GlobalListeningThreadTimerTickEvent(object sender, EventArgs e) @@ -713,7 +718,7 @@ namespace ChatController private void ListenForMessagesForCurrentContact(CurrentContact pCurrentContact) { - if (!_ShouldInterruptContactsThread) + if (!ShouldInterruptContactsThread) { var hasNewMessages = _Chat.CheckIfNewMessagesExist(pCurrentContact); @@ -898,7 +903,7 @@ namespace ChatController foreach (var contact in _ContactList.ToList().Where(contact => contact.ReceivedMessage != null)) { - var text = contact.GroupId + ";" + contact.TimeStamp + ";" + contact.IsNewMessage + ";"; + var text = contact.GroupId + ";" + contact.TimeStamp.ToUniversalTime() + ";" + contact.IsNewMessage + ";"; var bytes = enc.GetBytes(text); var base64String = Convert.ToBase64String(bytes); @@ -938,8 +943,6 @@ namespace ChatController var dateTime = DateTime.Parse(splitPlainText[1]); var isUnread = splitPlainText.Length <= 2 || string.IsNullOrEmpty(splitPlainText[2]) || bool.Parse(splitPlainText[2]); - Debug.WriteLine($"{groupId}: {dateTime:dd.MM.yyyy HH:mm:ss}; Is unread: {isUnread}"); - _GroupId2DateTime.Add(groupId, new SyncFileInfoStruct(isUnread, dateTime)); } } @@ -953,8 +956,8 @@ namespace ChatController latestDateTime = id2dateTime.Value.TimeStamp; } } - - //_Chat.LastTimeStamp = !latestDateTime.Equals(Utils.DefaultDate) ? latestDateTime.GetUnixTimeStamp() : DateTime.UtcNow.GetUnixTimeStamp(); + + _Chat.LastTimeStamp = latestDateTime.GetUnixTimeStamp(); } } catch (Exception e) diff --git a/ChatController/HauptKlassen/Chat.cs b/ChatController/HauptKlassen/Chat.cs index d84a2a5..453f01b 100644 --- a/ChatController/HauptKlassen/Chat.cs +++ b/ChatController/HauptKlassen/Chat.cs @@ -3,7 +3,6 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; @@ -22,6 +21,7 @@ using System.Windows.Media.Imaging; using ChatController.LoginKlassen; using ChatController.Utilities; using ChatController.Utilities.Extensions; + using Application = System.Windows.Forms.Application; using Clipboard = System.Windows.Forms.Clipboard; using Color = System.Drawing.Color; @@ -53,21 +53,6 @@ namespace ChatController.HauptKlassen ChatDaten = chatDaten; } - public ChatMessage PrevisouslyLatestMessage { get; set; } - public ChatMessage GetLatestMessage() - { - ChatMessage latestMessage = null; - foreach (var message in Messages) - { - if (latestMessage == null || latestMessage.SendTime < message.SendTime) - { - latestMessage = message; - } - } - - return latestMessage; - } - public IOrderedEnumerable AddContacts() { foreach (var contact in ChatDaten.AlleGruppen.Response)