fix nested transaction crash

This commit is contained in:
ryanzhao 2021-09-13 14:37:10 +10:00
parent f08d0470e5
commit 3c4a19e30d
2 changed files with 10 additions and 2 deletions

View File

@ -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 {

View File

@ -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
}