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

@@ -72,6 +72,8 @@
<DependentUpon>ChatMainControl.xaml</DependentUpon>
</Compile>
<Compile Include="Data\OwnChatApi.cs" />
<Compile Include="Extensions\IDictionaryTExtensions.cs" />
<Compile Include="Extensions\IListTExtensions.cs" />
<Compile Include="HauptKlassen\Chat.cs" />
<Compile Include="HauptKlassen\ChatEmoji.cs" />
<Compile Include="LoginControl.xaml.cs">

View File

@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using System.Windows.Media;
using ChatController.LoginKlassen;
using static System.String;
namespace ChatController.ChatKlassen
@@ -9,18 +10,10 @@ namespace ChatController.ChatKlassen
{
public string Name { get; }
private string _ReceivedMessage;
public string ReceivedMessage
private GroupLatestMessage _ReceivedMessage;
public GroupLatestMessage ReceivedMessage
{
get
{
if (!IsNullOrEmpty(_ReceivedMessage) && _ReceivedMessage.Length > 25)
{
return _ReceivedMessage.Substring(0, 25) + "...";
}
return _ReceivedMessage;
}
get => _ReceivedMessage;
set
{
@@ -84,10 +77,10 @@ namespace ChatController.ChatKlassen
public int UserOid { get; set; }
public string UserIdManage { get; set; }
public Contact(string pName, ImageSource pImage, string pLastMessageText, DateTime pTimeStamp, int pGroupId, string pUserIdManage, bool pOnlyEmployees, int pUserCount)
public Contact(string pName, ImageSource pImage, GroupLatestMessage pLatestMessage, DateTime pTimeStamp, int pGroupId, string pUserIdManage, bool pOnlyEmployees, int pUserCount)
{
Name = pName;
ReceivedMessage = pLastMessageText;
ReceivedMessage = pLatestMessage;
Image = pImage;
TimeStamp = pTimeStamp;
GroupId = pGroupId;

View File

@@ -92,7 +92,7 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Path=Name, FallbackValue=FirstName}" Foreground="{Binding Path=ContactChatColor}" FontSize="16" Margin="1" />
<TextBlock Text="{Binding Path=ReceivedMessage}" Grid.Row="1" FontSize="14" Foreground="{Binding Path=Color}" Margin="1" />
<TextBlock Text="{Binding Path=ReceivedMessage.Text}" Grid.Row="1" FontSize="14" Foreground="{Binding Path=Color}" Margin="1" />
</Grid>
</Grid>
</Border>

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,9 +128,7 @@ namespace ChatController
Clientlist.Items.Refresh();
}
public void ShowNotification(string pTitle, string pMessage, int pGroupId)
{
if (!_Group2NotifyIcons.ContainsKey(pGroupId))
public void ShowNotification(string pTitle, GroupLatestMessage pMessage, int pGroupId)
{
var notificationIcon = Resource.ownchat_favicon;
@@ -140,7 +139,7 @@ namespace ChatController
notificationIcon = Utils.ImageSourceToIcon(contact.Image);
}
var notifyIcon = new NotifyIcon { Icon = notificationIcon, Visible = true };
var notifyIcon = new NotifyIcon { Icon = notificationIcon, Visible = true, Tag = pMessage };
notifyIcon.BalloonTipClicked += (sender, args) =>
{
@@ -161,17 +160,19 @@ namespace ChatController
DisposeAndRemoveNotification((NotifyIcon)sender, pGroupId);
};
_Group2NotifyIcons.Add(pGroupId, notifyIcon);
}
_Group2NotifyIcons.AddOrUpdateValueInDictionary(pGroupId, notifyIcon);
_Group2NotifyIcons[pGroupId].ShowBalloonTip(Constants.NotificationTimeout, pTitle, pMessage, ToolTipIcon.None);
_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);
}

View File

@@ -1234,26 +1234,18 @@ namespace ChatController.HauptKlassen
foreach(var groupInput in pGroupInputs)
{
var messageText = string.Empty;
var formattedTime = new DateTime();
var latestMessage = groupInput.LastMessage;
if(latestMessage?.Text != null)
{
messageText = latestMessage.Text;
var timeStamp = DateTime.Parse(latestMessage.Timestamp.Date);
var clientZone = TimeZoneInfo.Local;
formattedTime = TimeZoneInfo.ConvertTimeFromUtc(timeStamp, clientZone);
}
if(string.IsNullOrEmpty(messageText) && !string.IsNullOrEmpty(groupInput.LastMessage?.File))
{
messageText = Path.GetFileName(groupInput.LastMessage.File);
}
string userIdManage = null;
foreach(var user in groupInput.Users)
@@ -1269,7 +1261,7 @@ namespace ChatController.HauptKlassen
var avatar = Utils.AvatarToImageSourceConverter(groupInput.Avatar, groupInput.OnlyEmployees, groupInput.Users.Length > 2);
contacts.Add(new Contact(groupInput.Name, avatar, messageText, formattedTime, groupInput.Oid, userIdManage, groupInput.OnlyEmployees, groupInput.Users.Length));
contacts.Add(new Contact(groupInput.Name, avatar, groupInput.LastMessage, formattedTime, groupInput.Oid, userIdManage, groupInput.OnlyEmployees, groupInput.Users.Length));
if(pShouldUpdateLastTimeStamp)
{

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
namespace ChatController.LoginKlassen
{
@@ -24,7 +25,30 @@ namespace ChatController.LoginKlassen
public class GroupLatestMessage
{
public long Id { get; set; }
public string Text { get; set; }
private string _Text;
public string Text
{
get
{
var result = _Text;
if (string.IsNullOrEmpty(_Text) && !string.IsNullOrEmpty(File))
{
result = Path.GetFileName(File);
}
if (!string.IsNullOrEmpty(_Text) && _Text.Length > 25)
{
result = _Text.Substring(0, 25) + "...";
}
return result;
}
set => _Text = value;
}
public string File { get; set; }
public string OriginalFileName { get; set; }
public string SmallerImage { get; set; }