diff --git a/Session/Notifications/AppNotifications.swift b/Session/Notifications/AppNotifications.swift index ba078de92..fbb44d372 100644 --- a/Session/Notifications/AppNotifications.swift +++ b/Session/Notifications/AppNotifications.swift @@ -174,7 +174,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol { } let context = Contact.context(for: thread) - let senderName = Storage.shared.getContact(with: incomingMessage.authorId)?.displayName(for: context) ?? incomingMessage.authorId + let senderName = Storage.shared.getContact(with: incomingMessage.authorId, using: transaction)?.displayName(for: context) ?? incomingMessage.authorId let notificationTitle: String? switch previewType { diff --git a/SessionMessagingKit/Database/Storage+Contacts.swift b/SessionMessagingKit/Database/Storage+Contacts.swift index 04f3cf128..5581de050 100644 --- a/SessionMessagingKit/Database/Storage+Contacts.swift +++ b/SessionMessagingKit/Database/Storage+Contacts.swift @@ -7,8 +7,16 @@ extension Storage { public func getContact(with sessionID: String) -> Contact? { var result: Contact? Storage.read { transaction in - result = transaction.object(forKey: sessionID, inCollection: Storage.contactCollection) as? Contact + result = self.getContact(with: sessionID, using: transaction) } + return result + } + + @objc(getContactWithSessionID:using:) + public func getContact(with sessionID: String, using transaction: Any) -> Contact? { + var result: Contact? + let transaction = transaction as! YapDatabaseReadTransaction + result = transaction.object(forKey: sessionID, inCollection: Storage.contactCollection) as? Contact if let result = result, result.sessionID == getUserHexEncodedPublicKey() { result.isTrusted = true // Always trust ourselves }