diff --git a/ChatController/Core/OwnChatCache.cs b/ChatController/Core/OwnChatCache.cs index 1f993ef..9de93f7 100644 --- a/ChatController/Core/OwnChatCache.cs +++ b/ChatController/Core/OwnChatCache.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Linq; using System.Windows.Media; using ChatController.Extensions; @@ -52,6 +51,9 @@ namespace ChatController.Core private List _AvatarCache = new List(); + private List EmployeesWithDefaultAvatar = new List(); + private List ClientsWithDefaultAvatar = new List(); + public void AddAvatar(string uri, ImageSource avatar, long? userId, int? groupId) { lock(_Lock) @@ -76,6 +78,10 @@ namespace ChatController.Core if(uri.Equals($"{BaseUri}/ownChat_avatar_employee.png")) { _DefaultAvatars.AddAndIgnoreDuplicates(DefaultAvatarType.Employee, avatar); + if(userId.HasValue) + { + EmployeesWithDefaultAvatar.AddIfNotIn(userId.Value); + } } if(uri.Equals($"{BaseUri}/ownChat_avatar_employee_group.png")) @@ -86,6 +92,10 @@ namespace ChatController.Core if(uri.Equals($"{BaseUri}/ownChat_avatar_client.png")) { _DefaultAvatars.AddAndIgnoreDuplicates(DefaultAvatarType.Client, avatar); + if(userId.HasValue) + { + ClientsWithDefaultAvatar.AddIfNotIn(userId.Value); + } } if(uri.Equals($"{BaseUri}/ownChat_avatar_client_group.png")) @@ -119,6 +129,11 @@ namespace ChatController.Core if(uri.Equals($"{BaseUri}/ownChat_avatar_employee.png")) { + if(userId.HasValue) + { + EmployeesWithDefaultAvatar.AddIfNotIn(userId.Value); + } + return _DefaultAvatars[DefaultAvatarType.Employee]; } @@ -129,6 +144,11 @@ namespace ChatController.Core if(uri.Equals($"{BaseUri}/ownChat_avatar_client.png")) { + if(userId.HasValue) + { + ClientsWithDefaultAvatar.AddIfNotIn(userId.Value); + } + return _DefaultAvatars[DefaultAvatarType.Client]; } @@ -151,7 +171,24 @@ namespace ChatController.Core { lock(_Lock) { - return _AvatarCache.FirstOrDefault(f => f.UserId.HasValue && f.UserId.Value.Equals(userId))?.ProfilePicture; + var profilePicture = _AvatarCache.FirstOrDefault(f => f.UserId.HasValue && f.UserId.Value.Equals(userId))?.ProfilePicture; + + if(!(profilePicture is null)) + { + return profilePicture; + } + + if(EmployeesWithDefaultAvatar.Contains(userId)) + { + profilePicture = _DefaultAvatars[DefaultAvatarType.Employee]; + } + + if(ClientsWithDefaultAvatar.Contains(userId)) + { + profilePicture = _DefaultAvatars[DefaultAvatarType.Client]; + } + + return profilePicture; } }