fix nested transaction crash

pull/507/head
ryanzhao 4 years ago
parent f08d0470e5
commit 3c4a19e30d

@ -174,7 +174,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
} }
let context = Contact.context(for: thread) 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? let notificationTitle: String?
switch previewType { switch previewType {

@ -7,8 +7,16 @@ extension Storage {
public func getContact(with sessionID: String) -> Contact? { public func getContact(with sessionID: String) -> Contact? {
var result: Contact? var result: Contact?
Storage.read { transaction in 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() { if let result = result, result.sessionID == getUserHexEncodedPublicKey() {
result.isTrusted = true // Always trust ourselves result.isTrusted = true // Always trust ourselves
} }

Loading…
Cancel
Save