Benachrichtigungsanzeige verbessert:
Mehrere Benachrichtigungen öffnen alle den richtigen Chat
This commit is contained in:
@@ -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">
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -1268,8 +1260,8 @@ 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)
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user