Change to make the 'getUser(using:)' method more consistent

This commit is contained in:
Morgan Pretty 2022-03-24 14:16:38 +11:00
parent 7aa1221987
commit 6205e72eab
2 changed files with 9 additions and 13 deletions

View file

@ -36,21 +36,17 @@ extension Storage {
}
@objc public func getUser() -> Contact? {
return getUser(using: nil)
}
public func getUser(using transaction: Any?) -> Contact? {
guard let userPublicKey = getUserPublicKey() else { return nil }
var result: Contact?
if let transaction = transaction {
result = Storage.shared.getContact(with: userPublicKey, using: transaction)
}
else {
Storage.read { transaction in
result = Storage.shared.getContact(with: userPublicKey, using: transaction)
}
Storage.read { transaction in
result = self.getUser(using: transaction)
}
return result
}
public func getUser(using transaction: Any) -> Contact? {
guard let userPublicKey = getUserPublicKey() else { return nil }
return Storage.shared.getContact(with: userPublicKey, using: transaction)
}
}

View file

@ -17,7 +17,7 @@ public protocol SessionMessagingKitStorageProtocol {
func getUserKeyPair() -> ECKeyPair?
func getUserED25519KeyPair() -> Box.KeyPair?
func getUser() -> Contact?
func getUser(using transaction: Any?) -> Contact?
func getUser(using transaction: Any) -> Contact?
func getAllContacts() -> Set<Contact>
func getAllContacts(with transaction: YapDatabaseReadTransaction) -> Set<Contact>