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.
25 lines
1.3 KiB
Swift
25 lines
1.3 KiB
Swift
|
|
extension Storage : SessionProtocolKitStorageProtocol {
|
|
|
|
private func getClosedGroupRatchetCollection(_ collection: ClosedGroupRatchetCollectionType, for groupPublicKey: String) -> String {
|
|
switch collection {
|
|
case .old: return "LokiOldClosedGroupRatchetCollection.\(groupPublicKey)"
|
|
case .current: return "LokiClosedGroupRatchetCollection.\(groupPublicKey)"
|
|
}
|
|
}
|
|
|
|
public func getClosedGroupRatchet(for groupPublicKey: String, senderPublicKey: String, from collection: ClosedGroupRatchetCollectionType = .current) -> ClosedGroupRatchet? {
|
|
let collection = getClosedGroupRatchetCollection(collection, for: groupPublicKey)
|
|
var result: ClosedGroupRatchet?
|
|
Storage.read { transaction in
|
|
result = transaction.object(forKey: senderPublicKey, inCollection: collection) as? ClosedGroupRatchet
|
|
}
|
|
return result
|
|
}
|
|
|
|
public func setClosedGroupRatchet(for groupPublicKey: String, senderPublicKey: String, ratchet: ClosedGroupRatchet, in collection: ClosedGroupRatchetCollectionType = .current, using transaction: Any) {
|
|
let collection = getClosedGroupRatchetCollection(collection, for: groupPublicKey)
|
|
(transaction as! YapDatabaseReadWriteTransaction).setObject(ratchet, forKey: senderPublicKey, inCollection: collection)
|
|
}
|
|
}
|