Download der Profilbilder optimiert
This commit is contained in:
@@ -114,8 +114,6 @@ namespace ChatController.ChatKlassen
|
||||
|
||||
IsGroupChat = pUserCount > 2;
|
||||
|
||||
Utils.DownloadUserProfilePictures(userId2Uri);
|
||||
|
||||
Utils.DownloadProfilePictureAsync(profilePicturePath, key, delegate(ImageSource imageSource)
|
||||
{
|
||||
Image = imageSource;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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]}";
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user