From b023b1be9467a26bfbcde7f52052cb04bde67651 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 4 Mar 2021 11:11:58 +1100 Subject: [PATCH] Fix profile updating issue --- SessionMessagingKit/Database/Storage+Contacts.swift | 13 ++++++++++--- .../MessageReceiver+Handling.swift | 3 --- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/SessionMessagingKit/Database/Storage+Contacts.swift b/SessionMessagingKit/Database/Storage+Contacts.swift index 448afc6f0..979fd9710 100644 --- a/SessionMessagingKit/Database/Storage+Contacts.swift +++ b/SessionMessagingKit/Database/Storage+Contacts.swift @@ -14,9 +14,16 @@ extension Storage { @objc(setContact:usingTransaction:) public func setContact(_ contact: Contact, using transaction: Any) { - (transaction as! YapDatabaseReadWriteTransaction).setObject(contact, forKey: contact.sessionID, inCollection: Storage.contactCollection) - DispatchQueue.main.async { - NotificationCenter.default.post(name: .contactUpdated, object: contact.sessionID) + let transaction = transaction as! YapDatabaseReadWriteTransaction + transaction.setObject(contact, forKey: contact.sessionID, inCollection: Storage.contactCollection) + transaction.addCompletionQueue(DispatchQueue.main) { + let notificationCenter = NotificationCenter.default + notificationCenter.post(name: .contactUpdated, object: contact.sessionID) + if contact.sessionID == getUserHexEncodedPublicKey() { + notificationCenter.post(name: Notification.Name(kNSNotificationName_LocalProfileDidChange), object: nil) + } else { + notificationCenter.post(name: Notification.Name(kNSNotificationName_OtherUsersProfileDidChange), object: nil) + } } } diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift index c95b37516..313345165 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift @@ -206,9 +206,6 @@ extension MessageReceiver { } userProfile.save(with: transaction) Storage.shared.setContact(user, using: transaction) - transaction.addCompletionQueue(DispatchQueue.main) { - NotificationCenter.default.post(name: Notification.Name(kNSNotificationName_LocalProfileDidChange), object: nil) - } transaction.addCompletionQueue(DispatchQueue.main) { SSKEnvironment.shared.profileManager.downloadAvatar(for: userProfile) }