mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.1 KiB
Swift
32 lines
1.1 KiB
Swift
import SessionProtocolKit
|
|
|
|
extension Storage {
|
|
|
|
private static let contactCollection = "LokiContactCollection"
|
|
|
|
@objc(getContactWithSessionID:)
|
|
public func getContact(with sessionID: String) -> Contact? {
|
|
var result: Contact?
|
|
Storage.read { transaction in
|
|
result = transaction.object(forKey: sessionID, inCollection: Storage.contactCollection) as? Contact
|
|
}
|
|
return result
|
|
}
|
|
|
|
@objc(setContact:usingTransaction:)
|
|
public func setContact(_ contact: Contact, using transaction: Any) {
|
|
(transaction as! YapDatabaseReadWriteTransaction).setObject(contact, forKey: contact.sessionID, inCollection: Storage.contactCollection)
|
|
}
|
|
|
|
public func getAllContacts() -> Set<Contact> {
|
|
var result: Set<Contact> = []
|
|
Storage.read { transaction in
|
|
transaction.enumerateRows(inCollection: Storage.contactCollection) { _, object, _, _ in
|
|
guard let contact = object as? Contact else { return }
|
|
result.insert(contact)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
}
|