From 6bf25e28f7f0500ec8d645e33a8a1f88951173f5 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 23 Jul 2021 09:00:28 +1000 Subject: [PATCH] Debug --- SessionMessagingKit/Database/Storage+Contacts.swift | 5 ----- .../MessageReceiver+Handling.swift | 12 ++++++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/SessionMessagingKit/Database/Storage+Contacts.swift b/SessionMessagingKit/Database/Storage+Contacts.swift index 26cfc8a3f..04f3cf128 100644 --- a/SessionMessagingKit/Database/Storage+Contacts.swift +++ b/SessionMessagingKit/Database/Storage+Contacts.swift @@ -32,11 +32,6 @@ extension Storage { OWSFileSystem.deleteFileIfExists(path) } } - // Download new profile picture if needed - if contact.profilePictureURL != nil && contact.profilePictureURL != oldContact?.profilePictureURL { - let profileManager = SSKEnvironment.shared.profileManager - profileManager.downloadAvatar(forUserProfile: contact) - } // Post notification let notificationCenter = NotificationCenter.default notificationCenter.post(name: .contactUpdated, object: contact.sessionID) diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift index b11b8a3ad..ffebdd830 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift @@ -183,10 +183,6 @@ extension MessageReceiver { // Profile updateProfileIfNeeded(publicKey: userPublicKey, name: message.displayName, profilePictureURL: message.profilePictureURL, profileKey: given(message.profileKey) { OWSAES256Key(data: $0)! }, sentTimestamp: message.sentTimestamp!, transaction: transaction) - transaction.addCompletionQueue(DispatchQueue.main) { - let userProfile = storage.getUser() ?? Contact(sessionID: userPublicKey) - SSKEnvironment.shared.profileManager.downloadAvatar(forUserProfile: userProfile) - } // Initial configuration sync if !UserDefaults.standard[.hasSyncedInitialConfiguration] { UserDefaults.standard[.hasSyncedInitialConfiguration] = true @@ -320,8 +316,8 @@ extension MessageReceiver { } } // Profile picture & profile key - if let profileKey = profileKey, let profilePictureURL = profilePictureURL, profileKey.keyData.count == kAES256_KeyByteLength, - profileKey != contact.profileEncryptionKey { + if let profileKey = profileKey, let profilePictureURL = profilePictureURL, + profileKey.keyData.count == kAES256_KeyByteLength, profileKey != contact.profileEncryptionKey { let shouldUpdate: Bool if isCurrentUser { shouldUpdate = given(userDefaults[.lastProfilePictureUpdate]) { sentTimestamp > UInt64($0.timeIntervalSince1970 * 1000) } ?? true @@ -338,6 +334,10 @@ extension MessageReceiver { } // Persist changes Storage.shared.setContact(contact, using: transaction) + // Download the profile picture if needed + transaction.addCompletionQueue(DispatchQueue.main) { + SSKEnvironment.shared.profileManager.downloadAvatar(forUserProfile: contact) + } }