From 6205e72eabfafbe3760f0eb7021ab2561d5be93e Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Thu, 24 Mar 2022 14:16:38 +1100 Subject: [PATCH] Change to make the 'getUser(using:)' method more consistent --- .../Database/Storage+Shared.swift | 20 ++++++++----------- SessionMessagingKit/Storage.swift | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/SessionMessagingKit/Database/Storage+Shared.swift b/SessionMessagingKit/Database/Storage+Shared.swift index 0f3fdb8e4..d297aefb1 100644 --- a/SessionMessagingKit/Database/Storage+Shared.swift +++ b/SessionMessagingKit/Database/Storage+Shared.swift @@ -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) + } } diff --git a/SessionMessagingKit/Storage.swift b/SessionMessagingKit/Storage.swift index 6bcabb3ae..ee5def11d 100644 --- a/SessionMessagingKit/Storage.swift +++ b/SessionMessagingKit/Storage.swift @@ -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 func getAllContacts(with transaction: YapDatabaseReadTransaction) -> Set