Login zeigt Warteanimation
NullPointerException beim Senden einer Nachricht in einen leeren Chat (AddSeparators) behoben; die previousMessage war null. Download von Dokumenten und Audio-Dateien geht jetzt neben den Bildern Cache der Profilbilder optimiert Beim Klick auf Senden wird die Warteanimation angezeigt
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using ChatController.Extensions;
|
||||
|
||||
namespace ChatController.Core
|
||||
{
|
||||
public class OwnChatCache
|
||||
{
|
||||
public static string BaseUri { get; set; }
|
||||
public long? LoggedOnUserId { get; set; }
|
||||
|
||||
private static readonly object _Lock = new object();
|
||||
@@ -42,6 +47,157 @@ namespace ChatController.Core
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Dictionary<DefaultAvatarType, ImageSource> _DefaultAvatars = new Dictionary<DefaultAvatarType, ImageSource>();
|
||||
|
||||
private List<ProfilePictureObject> _AvatarCache = new List<ProfilePictureObject>();
|
||||
|
||||
public void AddAvatar(string uri, ImageSource avatar, long? userId, int? groupId)
|
||||
{
|
||||
lock(_Lock)
|
||||
{
|
||||
if(uri is null || avatar is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_AvatarCache is null)
|
||||
{
|
||||
_AvatarCache = new List<ProfilePictureObject>();
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(BaseUri))
|
||||
{
|
||||
if(_DefaultAvatars is null)
|
||||
{
|
||||
_DefaultAvatars = new Dictionary<DefaultAvatarType, ImageSource>();
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_employee.png"))
|
||||
{
|
||||
_DefaultAvatars.AddAndIgnoreDuplicates(DefaultAvatarType.Employee, avatar);
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_employee_group.png"))
|
||||
{
|
||||
_DefaultAvatars.AddAndIgnoreDuplicates(DefaultAvatarType.EmployeeGroup, avatar);
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_client.png"))
|
||||
{
|
||||
_DefaultAvatars.AddAndIgnoreDuplicates(DefaultAvatarType.Client, avatar);
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_client_group.png"))
|
||||
{
|
||||
_DefaultAvatars.AddAndIgnoreDuplicates(DefaultAvatarType.ClientGroup, avatar);
|
||||
}
|
||||
}
|
||||
|
||||
if(!_AvatarCache.Any(ppo => ppo.Uri.Equals(uri) && ppo.UserId == userId && ppo.GroupId == groupId))
|
||||
{
|
||||
_AvatarCache.Add(new ProfilePictureObject(userId, uri, avatar, groupId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ImageSource GetAvatar(string uri, long? userId, int? groupId)
|
||||
{
|
||||
lock(_Lock)
|
||||
{
|
||||
if(uri is null || _AvatarCache is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(BaseUri))
|
||||
{
|
||||
if(_DefaultAvatars is null)
|
||||
{
|
||||
_DefaultAvatars = new Dictionary<DefaultAvatarType, ImageSource>();
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_employee.png"))
|
||||
{
|
||||
return _DefaultAvatars[DefaultAvatarType.Employee];
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_employee_group.png"))
|
||||
{
|
||||
return _DefaultAvatars[DefaultAvatarType.EmployeeGroup];
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_client.png"))
|
||||
{
|
||||
return _DefaultAvatars[DefaultAvatarType.Client];
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_client_group.png"))
|
||||
{
|
||||
return _DefaultAvatars[DefaultAvatarType.ClientGroup];
|
||||
}
|
||||
}
|
||||
|
||||
return _AvatarCache.FirstOrDefault(f => uri.Equals(f.Uri) && f.UserId == userId && f.GroupId == groupId)?.ProfilePicture;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt das Profilbild des Absenders einer Nachricht in Gruppenchats zurück
|
||||
/// </summary>
|
||||
/// <param name="userId">UserId des Absenders einer Nachricht</param>
|
||||
/// <returns>Profilbild des Absenders einer Nachricht mit der angegebenen UserId</returns>
|
||||
public ImageSource GetAvatarByUserId(long userId)
|
||||
{
|
||||
lock(_Lock)
|
||||
{
|
||||
return _AvatarCache.FirstOrDefault(f => f.UserId.HasValue && f.UserId.Value.Equals(userId))?.ProfilePicture;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsAvatarInCache(string uri, long? userId, int? groupId)
|
||||
{
|
||||
lock(_Lock)
|
||||
{
|
||||
if(uri is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(BaseUri))
|
||||
{
|
||||
if(_DefaultAvatars is null)
|
||||
{
|
||||
_DefaultAvatars = new Dictionary<DefaultAvatarType, ImageSource>();
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_employee.png"))
|
||||
{
|
||||
return _DefaultAvatars.ContainsKey(DefaultAvatarType.Employee);
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_employee_group.png"))
|
||||
{
|
||||
return _DefaultAvatars.ContainsKey(DefaultAvatarType.EmployeeGroup);
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_client.png"))
|
||||
{
|
||||
return _DefaultAvatars.ContainsKey(DefaultAvatarType.Client);
|
||||
}
|
||||
|
||||
if(uri.Equals($"{BaseUri}/ownChat_avatar_client_group.png"))
|
||||
{
|
||||
return _DefaultAvatars.ContainsKey(DefaultAvatarType.ClientGroup);
|
||||
}
|
||||
}
|
||||
|
||||
return _AvatarCache?.Any(a => uri.Equals(a.Uri) && a.UserId == userId && a.GroupId == groupId) ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Key-> "group-127" oder "user-938"
|
||||
private Dictionary<string, ImageSourceCacheStorage> _ImageSourceCache = new Dictionary<string, ImageSourceCacheStorage>();
|
||||
|
||||
@@ -126,7 +282,12 @@ namespace ChatController.Core
|
||||
{
|
||||
if(!_UserProfilePictures.ContainsKey(userId))
|
||||
{
|
||||
_UserProfilePictures.Add(userId, new ProfilePictureObject(userId, uri, imageSource));
|
||||
Debug.WriteLine($"+++>OwnChatCache.AddUserProfilePictureToCache: Füge Avatar zum Cache hinzu {userId}");
|
||||
_UserProfilePictures.Add(userId, new ProfilePictureObject(userId, uri, imageSource, null));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine($">>>OwnChatCache.AddUserProfilePictureToCache: Cache enthält bereits den Avatar von {userId}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,14 +311,17 @@ namespace ChatController.Core
|
||||
|
||||
public class ProfilePictureObject
|
||||
{
|
||||
public long UserId { get; set; }
|
||||
public long? UserId { get; set; }
|
||||
|
||||
public string Uri { get; set; }
|
||||
|
||||
public ImageSource ProfilePicture { get; set; }
|
||||
|
||||
public ProfilePictureObject(long userId, string uri, ImageSource profilePicture)
|
||||
public int? GroupId { get; set; }
|
||||
|
||||
public ProfilePictureObject(long? userId, string uri, ImageSource profilePicture, int? groupId)
|
||||
{
|
||||
GroupId = groupId;
|
||||
UserId = userId;
|
||||
Uri = uri;
|
||||
ProfilePicture = profilePicture;
|
||||
@@ -252,4 +416,12 @@ namespace ChatController.Core
|
||||
Thumbnail,
|
||||
MessageAttachment
|
||||
}
|
||||
|
||||
public enum DefaultAvatarType
|
||||
{
|
||||
Employee = 0,
|
||||
EmployeeGroup = 1,
|
||||
Client = 2,
|
||||
ClientGroup = 3
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user