Benachrichtigungsanzeige verbessert:

Mehrere Benachrichtigungen öffnen alle den richtigen Chat
This commit is contained in:
Lyndon
2019-09-03 15:15:12 +02:00
parent 69cb1cf509
commit 305a26370f
6 changed files with 77 additions and 64 deletions

View File

@@ -15,6 +15,7 @@ using System.Windows.Navigation;
using System.Windows.Threading;
using ChatController.ChatKlassen;
using ChatController.Extensions;
using ChatController.HauptKlassen;
using ChatController.LoginKlassen;
using ChatController.Utilities;
@@ -36,7 +37,7 @@ namespace ChatController
{
public partial class ChatMainControl
{
private readonly Dictionary<long, NotifyIcon> _Group2NotifyIcons = new Dictionary<long, NotifyIcon>();
private readonly Dictionary<long, List<NotifyIcon>> _Group2NotifyIcons = new Dictionary<long, List<NotifyIcon>>();
private readonly Dictionary<int, SyncFileInfoStruct> _GroupId2DateTime = new Dictionary<int, SyncFileInfoStruct>();
@@ -127,51 +128,51 @@ namespace ChatController
Clientlist.Items.Refresh();
}
public void ShowNotification(string pTitle, string pMessage, int pGroupId)
public void ShowNotification(string pTitle, GroupLatestMessage pMessage, int pGroupId)
{
if (!_Group2NotifyIcons.ContainsKey(pGroupId))
var notificationIcon = Resource.ownchat_favicon;
var contact = _ContactList.FirstOrDefault(a => a.GroupId == pGroupId);
if (contact != null)
{
var notificationIcon = Resource.ownchat_favicon;
var contact = _ContactList.FirstOrDefault(a => a.GroupId == pGroupId);
if(contact != null)
{
notificationIcon = Utils.ImageSourceToIcon(contact.Image);
}
var notifyIcon = new NotifyIcon { Icon = notificationIcon, Visible = true };
notifyIcon.BalloonTipClicked += (sender, args) =>
{
DisposeAndRemoveNotification((NotifyIcon)sender, pGroupId);
if (_ContainingWindow.WindowState == WindowState.Minimized)
{
_ContainingWindow.WindowState = WindowState.Normal;
}
_ContainingWindow.Activate();
SelectContact(_ContactList.FirstOrDefault(f => f.GroupId.Equals(pGroupId)));
};
notifyIcon.BalloonTipClosed += (sender, args) =>
{
DisposeAndRemoveNotification((NotifyIcon)sender, pGroupId);
};
_Group2NotifyIcons.Add(pGroupId, notifyIcon);
notificationIcon = Utils.ImageSourceToIcon(contact.Image);
}
_Group2NotifyIcons[pGroupId].ShowBalloonTip(Constants.NotificationTimeout, pTitle, pMessage, ToolTipIcon.None);
var notifyIcon = new NotifyIcon { Icon = notificationIcon, Visible = true, Tag = pMessage };
notifyIcon.BalloonTipClicked += (sender, args) =>
{
DisposeAndRemoveNotification((NotifyIcon)sender, pGroupId);
if (_ContainingWindow.WindowState == WindowState.Minimized)
{
_ContainingWindow.WindowState = WindowState.Normal;
}
_ContainingWindow.Activate();
SelectContact(_ContactList.FirstOrDefault(f => f.GroupId.Equals(pGroupId)));
};
notifyIcon.BalloonTipClosed += (sender, args) =>
{
DisposeAndRemoveNotification((NotifyIcon)sender, pGroupId);
};
_Group2NotifyIcons.AddOrUpdateValueInDictionary(pGroupId, notifyIcon);
_Group2NotifyIcons[pGroupId].Find(f => f.Tag is GroupLatestMessage message && message.Id.Equals(pMessage.Id))?.ShowBalloonTip(Constants.NotificationTimeout, pTitle, "Sie haben eine neue Nachricht", ToolTipIcon.None);
}
public void ClearNotifications()
{
foreach(var group2NotifyIcon in _Group2NotifyIcons)
{
group2NotifyIcon.Value.Dispose();
foreach(var notifyIcon in group2NotifyIcon.Value)
{
notifyIcon.Dispose();
}
}
_Group2NotifyIcons.Clear();
@@ -701,7 +702,8 @@ namespace ChatController
{
if (contact.GroupId == newContact.GroupId)
{
if (!contact.ReceivedMessage.Equals(newContact.ReceivedMessage))
// ReceivedMessage kann null sein!
if (contact.ReceivedMessage != null && !contact.ReceivedMessage.Id.Equals(newContact.ReceivedMessage?.Id))
{
contact.ReceivedMessage = newContact.ReceivedMessage;
contact.TimeStamp = newContact.TimeStamp;
@@ -710,7 +712,7 @@ namespace ChatController
if ((Clientlist.SelectedItem != null && !((Contact)Clientlist.SelectedItem).GroupId.Equals(newContact.GroupId) || Clientlist.SelectedItem == null) || _IsInBackground)
{
ContainingWindow.Icon = Utils.GetImageSourceFromIcon(Resource.oC_favico_NewMessage);
ShowNotification(newContact.Name, "Sie haben eine neue Nachricht", newContact.GroupId);
ShowNotification(newContact.Name, newContact.ReceivedMessage, newContact.GroupId);
}
// Wenn der momentan ausgewählte Kontakt der aktuelle Kontakt in der Schleife ist, werden die Nachrichten nicht als ungelesen angezeigt, sonst schon.
@@ -1014,7 +1016,7 @@ namespace ChatController
foreach(var contactItem in Clientlist.Items)
{
if(contactItem is Contact contact && contact.HasUnreadMessages && !string.IsNullOrEmpty(contact.ReceivedMessage))
if(contactItem is Contact contact && contact.HasUnreadMessages && !string.IsNullOrEmpty(contact.ReceivedMessage?.Text))
{
contacts.Add(contact);
}