Download der Profilbilder optimiert

This commit is contained in:
Lyndon
2022-02-04 15:36:42 +01:00
parent bf99e669fd
commit 69191c69d1
4 changed files with 5 additions and 34 deletions

View File

@@ -114,8 +114,6 @@ namespace ChatController.ChatKlassen
IsGroupChat = pUserCount > 2;
Utils.DownloadUserProfilePictures(userId2Uri);
Utils.DownloadProfilePictureAsync(profilePicturePath, key, delegate(ImageSource imageSource)
{
Image = imageSource;

View File

@@ -11,7 +11,7 @@ namespace ChatController.Core
// Key-> "group-127" oder "user-938"
private Dictionary<string, ImageSourceCacheStorage> _ImageSourceCache = new Dictionary<string, ImageSourceCacheStorage>();
private Dictionary<long, ProfilePictureObject> _UserProfilePictures = new Dictionary<long, ProfilePictureObject>();
private readonly Dictionary<long, ProfilePictureObject> _UserProfilePictures = new Dictionary<long, ProfilePictureObject>();
private static OwnChatCache _Instance;

View File

@@ -421,7 +421,7 @@ namespace ChatController.HauptKlassen
{
var connectionData = JsonConvert.DeserializeObject<UserDaten>(response.Content);
if (connectionData.Success)
if(connectionData != null && connectionData.Success)
{
_AuthToken = connectionData.Response.User.Token;
_UserId = connectionData.Response.User.Oid;
@@ -437,11 +437,11 @@ namespace ChatController.HauptKlassen
{
var errorMessage = string.Empty;
if (connectionData.Error?.ChatCodeFailed != null)
if (connectionData?.Error?.ChatCodeFailed != null)
{
errorMessage = $"Fehler: {connectionData.Error.ChatCodeFailed[0]}";
}
else if (connectionData.Error?.LoginFailed != null)
else if (connectionData?.Error?.LoginFailed != null)
{
errorMessage = $"Fehler: {connectionData.Error.LoginFailed[0]}";
}

View File

@@ -79,33 +79,6 @@ namespace ChatController.Utilities
client.ExecuteAsync(request, response => { /*Das übernimmt der ResponseWriter von oben*/ });
}
public static void DownloadUserProfilePictures(Dictionary<long, string> userId2Uris)
{
var cache = OwnChatCache.GetInstance();
foreach(var id2Uri in userId2Uris)
{
var userProfilePicture = cache.GetUserProfilePictureFromCache(id2Uri.Key);
if(userProfilePicture == null)
{
try
{
var uri = id2Uri.Value;
DownloadImage(uri, profilePicture =>
{
cache.AddUserProfilePictureToCache(profilePicture, id2Uri.Key, uri);
});
}
catch(Exception)
{
}
}
}
}
public static void DownloadImageAsync(string uri, string key, CacheCategory cacheCategory, Action<ImageSource> callback)
{
if(string.IsNullOrEmpty(uri))