From 9d605c03f034ba91cd51330ec41cdcb374dd9422 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 22 Jul 2021 15:23:35 +1000 Subject: [PATCH] Debug --- Session/Onboarding/Onboarding.swift | 7 ++++++- SessionMessagingKit/Database/Storage+Contacts.swift | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Session/Onboarding/Onboarding.swift b/Session/Onboarding/Onboarding.swift index 2166affe7..924536923 100644 --- a/Session/Onboarding/Onboarding.swift +++ b/Session/Onboarding/Onboarding.swift @@ -8,7 +8,12 @@ enum Onboarding { func preregister(with seed: Data, ed25519KeyPair: Sign.KeyPair, x25519KeyPair: ECKeyPair) { let userDefaults = UserDefaults.standard KeyPairUtilities.store(seed: seed, ed25519KeyPair: ed25519KeyPair, x25519KeyPair: x25519KeyPair) - TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = x25519KeyPair.hexEncodedPublicKey + let x25519PublicKey = x25519KeyPair.hexEncodedPublicKey + TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = x25519PublicKey + Storage.writeSync { transaction in + let user = Contact(sessionID: x25519PublicKey) + Storage.shared.setContact(user, using: transaction) + } switch self { case .register: userDefaults[.hasViewedSeed] = false diff --git a/SessionMessagingKit/Database/Storage+Contacts.swift b/SessionMessagingKit/Database/Storage+Contacts.swift index cf448694d..26cfc8a3f 100644 --- a/SessionMessagingKit/Database/Storage+Contacts.swift +++ b/SessionMessagingKit/Database/Storage+Contacts.swift @@ -25,12 +25,18 @@ extension Storage { transaction.setObject(contact, forKey: contact.sessionID, inCollection: Storage.contactCollection) transaction.addCompletionQueue(DispatchQueue.main) { // Delete old profile picture if needed - if let oldProfilePictureFileName = oldContact?.profilePictureFileName { + if let oldProfilePictureFileName = oldContact?.profilePictureFileName, + oldProfilePictureFileName != contact.profilePictureFileName { let path = OWSUserProfile.profileAvatarFilepath(withFilename: oldProfilePictureFileName) DispatchQueue.global(qos: .default).async { 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)