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.
session-ios/SignalServiceKit/src/Loki/Database/OWSPrimaryStorage+Loki.swift

23 lines
982 B
Swift

6 years ago
extension OWSPrimaryStorage {
6 years ago
public func storeDeviceLink(_ deviceLink: LokiDeviceLink, in transaction: YapDatabaseReadWriteTransaction) {
let collection = getCollection(for: deviceLink.master.hexEncodedPublicKey)
transaction.setObject(deviceLink, forKey: deviceLink.slave.hexEncodedPublicKey, inCollection: collection)
}
public func getDeviceLinks(for masterHexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> [LokiDeviceLink] {
let collection = getCollection(for: masterHexEncodedPublicKey)
var result: [LokiDeviceLink] = []
transaction.enumerateRows(inCollection: collection) { _, object, _, _ in
guard let deviceLink = object as? LokiDeviceLink else { return }
result.append(deviceLink)
}
return result
}
private func getCollection(for primaryDevice: String) -> String {
return "LokiDeviceLinkCollection-\(primaryDevice)"
}
}