|
|
@ -24,8 +24,8 @@ public final class LokiFileServerAPI : LokiDotNetAPI {
|
|
|
|
|
|
|
|
|
|
|
|
/// Gets the device links associated with the given hex encoded public key from the
|
|
|
|
/// Gets the device links associated with the given hex encoded public key from the
|
|
|
|
/// server and stores and returns the valid ones.
|
|
|
|
/// server and stores and returns the valid ones.
|
|
|
|
public static func getDeviceLinks(associatedWith hexEncodedPublicKey: String, in transaction: YapDatabaseReadWriteTransaction? = nil) -> Promise<Set<DeviceLink>> {
|
|
|
|
public static func getDeviceLinks(associatedWith hexEncodedPublicKey: String, usingCache: Bool = false) -> Promise<Set<DeviceLink>> {
|
|
|
|
return getDeviceLinks(associatedWith: [ hexEncodedPublicKey ], in: transaction)
|
|
|
|
return getDeviceLinks(associatedWith: [ hexEncodedPublicKey ], usingCache: usingCache)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc(getDeviceLinksAssociatedWithHexEncodedPublicKeys:)
|
|
|
|
@objc(getDeviceLinksAssociatedWithHexEncodedPublicKeys:)
|
|
|
@ -35,7 +35,7 @@ public final class LokiFileServerAPI : LokiDotNetAPI {
|
|
|
|
|
|
|
|
|
|
|
|
/// Gets the device links associated with the given hex encoded public keys from the
|
|
|
|
/// Gets the device links associated with the given hex encoded public keys from the
|
|
|
|
/// server and stores and returns the valid ones.
|
|
|
|
/// server and stores and returns the valid ones.
|
|
|
|
public static func getDeviceLinks(associatedWith hexEncodedPublicKeys: Set<String>, in transaction: YapDatabaseReadWriteTransaction? = nil) -> Promise<Set<DeviceLink>> {
|
|
|
|
public static func getDeviceLinks(associatedWith hexEncodedPublicKeys: Set<String>, usingCache: Bool = false) -> Promise<Set<DeviceLink>> {
|
|
|
|
let hexEncodedPublicKeysDescription = "[ \(hexEncodedPublicKeys.joined(separator: ", ")) ]"
|
|
|
|
let hexEncodedPublicKeysDescription = "[ \(hexEncodedPublicKeys.joined(separator: ", ")) ]"
|
|
|
|
print("[Loki] Getting device links for: \(hexEncodedPublicKeysDescription).")
|
|
|
|
print("[Loki] Getting device links for: \(hexEncodedPublicKeysDescription).")
|
|
|
|
return getAuthToken(for: server).then(on: DispatchQueue.global()) { token -> Promise<Set<DeviceLink>> in
|
|
|
|
return getAuthToken(for: server).then(on: DispatchQueue.global()) { token -> Promise<Set<DeviceLink>> in
|
|
|
@ -86,19 +86,20 @@ public final class LokiFileServerAPI : LokiDotNetAPI {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}.then(on: DispatchQueue.global()) { deviceLinks -> Promise<Set<DeviceLink>> in
|
|
|
|
}.then(on: DispatchQueue.global()) { deviceLinks -> Promise<Set<DeviceLink>> in
|
|
|
|
let (promise, seal) = Promise<Set<DeviceLink>>.pending()
|
|
|
|
let (promise, seal) = Promise<Set<DeviceLink>>.pending()
|
|
|
|
|
|
|
|
if usingCache {
|
|
|
|
|
|
|
|
storage.setDeviceLinksInCache(deviceLinks)
|
|
|
|
|
|
|
|
seal.fulfill(deviceLinks)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Dispatch async on the main queue to avoid nested write transactions
|
|
|
|
// Dispatch async on the main queue to avoid nested write transactions
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
if let trans = transaction {
|
|
|
|
|
|
|
|
storage.setDeviceLinks(deviceLinks, in: trans)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
storage.dbReadWriteConnection.readWrite{ transaction in
|
|
|
|
storage.dbReadWriteConnection.readWrite{ transaction in
|
|
|
|
storage.setDeviceLinks(deviceLinks, in: transaction)
|
|
|
|
storage.setDeviceLinks(deviceLinks, in: transaction)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have to wait for the device links to be stored because a lot of our logic relies
|
|
|
|
// We have to wait for the device links to be stored because a lot of our logic relies
|
|
|
|
// on them being in the database
|
|
|
|
// on them being in the database
|
|
|
|
seal.fulfill(deviceLinks)
|
|
|
|
seal.fulfill(deviceLinks)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return promise
|
|
|
|
return promise
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|