From 69191c69d16038874ae435279e4d9bd573df066e Mon Sep 17 00:00:00 2001 From: Lyndon Date: Fri, 4 Feb 2022 15:36:42 +0100 Subject: [PATCH] Download der Profilbilder optimiert --- ChatController/ChatKlassen/Contact.cs | 2 -- ChatController/Core/OwnChatCache.cs | 2 +- ChatController/HauptKlassen/Login.cs | 6 +++--- ChatController/Utilities/Utils.cs | 29 +-------------------------- 4 files changed, 5 insertions(+), 34 deletions(-) diff --git a/ChatController/ChatKlassen/Contact.cs b/ChatController/ChatKlassen/Contact.cs index 74a5c02..941c20c 100644 --- a/ChatController/ChatKlassen/Contact.cs +++ b/ChatController/ChatKlassen/Contact.cs @@ -114,8 +114,6 @@ namespace ChatController.ChatKlassen IsGroupChat = pUserCount > 2; - Utils.DownloadUserProfilePictures(userId2Uri); - Utils.DownloadProfilePictureAsync(profilePicturePath, key, delegate(ImageSource imageSource) { Image = imageSource; diff --git a/ChatController/Core/OwnChatCache.cs b/ChatController/Core/OwnChatCache.cs index 5699320..ba8f1c4 100644 --- a/ChatController/Core/OwnChatCache.cs +++ b/ChatController/Core/OwnChatCache.cs @@ -11,7 +11,7 @@ namespace ChatController.Core // Key-> "group-127" oder "user-938" private Dictionary _ImageSourceCache = new Dictionary(); - private Dictionary _UserProfilePictures = new Dictionary(); + private readonly Dictionary _UserProfilePictures = new Dictionary(); private static OwnChatCache _Instance; diff --git a/ChatController/HauptKlassen/Login.cs b/ChatController/HauptKlassen/Login.cs index 4648401..1d3d890 100644 --- a/ChatController/HauptKlassen/Login.cs +++ b/ChatController/HauptKlassen/Login.cs @@ -421,7 +421,7 @@ namespace ChatController.HauptKlassen { var connectionData = JsonConvert.DeserializeObject(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]}"; } diff --git a/ChatController/Utilities/Utils.cs b/ChatController/Utilities/Utils.cs index 08b1f7c..bf29556 100644 --- a/ChatController/Utilities/Utils.cs +++ b/ChatController/Utilities/Utils.cs @@ -36,7 +36,7 @@ namespace ChatController.Utilities var cachedProfileImage = cache.GetCachedProfilePicture(key, pathToProfilePicture); - if(cachedProfileImage != null) + if (cachedProfileImage != null) { callback?.Invoke(cachedProfileImage); return; @@ -79,33 +79,6 @@ namespace ChatController.Utilities client.ExecuteAsync(request, response => { /*Das übernimmt der ResponseWriter von oben*/ }); } - public static void DownloadUserProfilePictures(Dictionary 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 callback) { if(string.IsNullOrEmpty(uri))