|
|
@ -8,6 +8,7 @@ public class DotNetAPI : NSObject {
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: Settings
|
|
|
|
// MARK: Settings
|
|
|
|
private static let attachmentType = "network.loki"
|
|
|
|
private static let attachmentType = "network.loki"
|
|
|
|
|
|
|
|
private static let maxRetryCount: UInt = 4
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: Error
|
|
|
|
// MARK: Error
|
|
|
|
@objc(LKDotNetAPIError)
|
|
|
|
@objc(LKDotNetAPIError)
|
|
|
@ -123,13 +124,15 @@ public class DotNetAPI : NSObject {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let serverPublicKeyPromise = FileServerAPI.server.contains(host) ? Promise.value(FileServerAPI.fileServerPublicKey)
|
|
|
|
let serverPublicKeyPromise = FileServerAPI.server.contains(host) ? Promise.value(FileServerAPI.fileServerPublicKey)
|
|
|
|
: PublicChatAPI.getOpenGroupServerPublicKey(for: host)
|
|
|
|
: PublicChatAPI.getOpenGroupServerPublicKey(for: host)
|
|
|
|
return serverPublicKeyPromise.then2 { serverPublicKey in
|
|
|
|
return attempt(maxRetryCount: maxRetryCount, recoveringOn: SnodeAPI.workQueue) {
|
|
|
|
return OnionRequestAPI.sendOnionRequest(request, to: host, using: serverPublicKey, isJSONRequired: false).map2 { json in
|
|
|
|
serverPublicKeyPromise.then2 { serverPublicKey in
|
|
|
|
guard let body = json["body"] as? JSON, let data = body["data"] as? [UInt8] else {
|
|
|
|
return OnionRequestAPI.sendOnionRequest(request, to: host, using: serverPublicKey, isJSONRequired: false).map2 { json in
|
|
|
|
print("[Loki] Couldn't parse attachment from: \(json).")
|
|
|
|
guard let body = json["body"] as? JSON, let data = body["data"] as? [UInt8] else {
|
|
|
|
throw DotNetAPIError.parsingFailed
|
|
|
|
print("[Loki] Couldn't parse attachment from: \(json).")
|
|
|
|
|
|
|
|
throw DotNetAPIError.parsingFailed
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Data(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Data(data)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|