pull/83/head
Niels Andriesse 5 years ago
parent 25817b8688
commit fa43f2f834

@ -28,7 +28,7 @@ public class ConversationMediaView: UIView {
private let maxMessageWidth: CGFloat private let maxMessageWidth: CGFloat
private var loadBlock: (() -> Void)? private var loadBlock: (() -> Void)?
private var unloadBlock: (() -> Void)? private var unloadBlock: (() -> Void)?
var isClosedGroup = false private let isProxied: Bool
// MARK: - LoadState // MARK: - LoadState
@ -91,11 +91,13 @@ public class ConversationMediaView: UIView {
public required init(mediaCache: NSCache<NSString, AnyObject>, public required init(mediaCache: NSCache<NSString, AnyObject>,
attachment: TSAttachment, attachment: TSAttachment,
isOutgoing: Bool, isOutgoing: Bool,
maxMessageWidth: CGFloat) { maxMessageWidth: CGFloat,
isProxied: Bool) {
self.mediaCache = mediaCache self.mediaCache = mediaCache
self.attachment = attachment self.attachment = attachment
self.isOutgoing = isOutgoing self.isOutgoing = isOutgoing
self.maxMessageWidth = maxMessageWidth self.maxMessageWidth = maxMessageWidth
self.isProxied = isProxied
super.init(frame: .zero) super.init(frame: .zero)
@ -174,7 +176,7 @@ public class ConversationMediaView: UIView {
} }
private func addUploadProgressIfNecessary(_ subview: UIView) -> Bool { private func addUploadProgressIfNecessary(_ subview: UIView) -> Bool {
guard !isClosedGroup else { return false } // Loki: Due to the way proxying works we can't get upload progress for closed group attachments right now guard !isProxied else { return false } // Loki: Due to the way proxying works we can't get upload progress for those attachments right now
guard isOutgoing else { return false } guard isOutgoing else { return false }
guard let attachmentStream = attachment as? TSAttachmentStream else { return false } guard let attachmentStream = attachment as? TSAttachmentStream else { return false }
guard let attachmentId = attachmentStream.uniqueId else { guard let attachmentId = attachmentStream.uniqueId else {

@ -27,14 +27,14 @@ public class MediaAlbumCellView: UIStackView {
items: [ConversationMediaAlbumItem], items: [ConversationMediaAlbumItem],
isOutgoing: Bool, isOutgoing: Bool,
maxMessageWidth: CGFloat, maxMessageWidth: CGFloat,
isClosedGroup: Bool) { isProxied: Bool) {
self.items = items self.items = items
self.itemViews = MediaAlbumCellView.itemsToDisplay(forItems: items).map { self.itemViews = MediaAlbumCellView.itemsToDisplay(forItems: items).map {
let result = ConversationMediaView(mediaCache: mediaCache, let result = ConversationMediaView(mediaCache: mediaCache,
attachment: $0.attachment, attachment: $0.attachment,
isOutgoing: isOutgoing, isOutgoing: isOutgoing,
maxMessageWidth: maxMessageWidth) maxMessageWidth: maxMessageWidth,
result.isClosedGroup = isClosedGroup isProxied: isProxied)
return result return result
} }

@ -799,12 +799,14 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssertDebug(self.viewItem.mediaAlbumItems); OWSAssertDebug(self.viewItem.mediaAlbumItems);
BOOL isClosedGroup = NO; BOOL isProxied = NO;
if ([self.viewItem isKindOfClass:TSOutgoingMessage.class]) { if ([self.viewItem.interaction isKindOfClass:TSOutgoingMessage.class]) {
TSOutgoingMessage *message = (TSOutgoingMessage *)self.viewItem; TSOutgoingMessage *message = (TSOutgoingMessage *)self.viewItem.interaction;
if ([message.thread isKindOfClass:TSGroupThread.class]) { if ([message.thread isKindOfClass:TSGroupThread.class]) {
TSGroupThread *groupThread = (TSGroupThread *)message.thread; TSGroupThread *groupThread = (TSGroupThread *)message.thread;
isClosedGroup = (groupThread.groupModel.groupType == closedGroup); isProxied = (groupThread.groupModel.groupType == closedGroup);
} else if ([message.thread isKindOfClass:TSContactThread.class]) {
isProxied = YES;
} }
} }
@ -813,7 +815,7 @@ NS_ASSUME_NONNULL_BEGIN
items:self.viewItem.mediaAlbumItems items:self.viewItem.mediaAlbumItems
isOutgoing:self.isOutgoing isOutgoing:self.isOutgoing
maxMessageWidth:self.conversationStyle.maxMessageWidth maxMessageWidth:self.conversationStyle.maxMessageWidth
isClosedGroup:isClosedGroup]; isProxied:isProxied];
self.loadCellContentBlock = ^{ self.loadCellContentBlock = ^{
[albumView loadMedia]; [albumView loadMedia];
}; };

@ -46,19 +46,20 @@ internal class LokiFileServerProxy : LokiHTTPClient {
let uncheckedSymmetricKey = try? Curve25519.generateSharedSecret(fromPublicKey: LokiFileServerProxy.fileServerPublicKey, privateKey: keyPair.privateKey) let uncheckedSymmetricKey = try? Curve25519.generateSharedSecret(fromPublicKey: LokiFileServerProxy.fileServerPublicKey, privateKey: keyPair.privateKey)
guard let symmetricKey = uncheckedSymmetricKey else { return Promise(error: Error.symmetricKeyGenerationFailed) } guard let symmetricKey = uncheckedSymmetricKey else { return Promise(error: Error.symmetricKeyGenerationFailed) }
var headers = getCanonicalHeaders(for: request) var headers = getCanonicalHeaders(for: request)
headers["Content-Type"] = "application/json"
return LokiAPI.getRandomSnode().then { [server = self.server, keyPair = self.keyPair, httpSession = self.httpSession] proxy -> Promise<Any> in return LokiAPI.getRandomSnode().then { [server = self.server, keyPair = self.keyPair, httpSession = self.httpSession] proxy -> Promise<Any> in
let url = "\(proxy.address):\(proxy.port)/file_proxy" let url = "\(proxy.address):\(proxy.port)/file_proxy"
print("[Loki] Proxying request to \(server) through \(proxy).") print("[Loki] Proxying file server request to \(server) through \(proxy).")
guard let urlAsString = request.url?.absoluteString, let serverURLEndIndex = urlAsString.range(of: server)?.upperBound, guard let urlAsString = request.url?.absoluteString, let serverURLEndIndex = urlAsString.range(of: server)?.upperBound,
serverURLEndIndex < urlAsString.endIndex else { throw Error.endpointParsingFailed } serverURLEndIndex < urlAsString.endIndex else { throw Error.endpointParsingFailed }
let endpointStartIndex = urlAsString.index(after: serverURLEndIndex) let endpointStartIndex = urlAsString.index(after: serverURLEndIndex)
let endpoint = String(urlAsString[endpointStartIndex..<urlAsString.endIndex]) let endpoint = String(urlAsString[endpointStartIndex..<urlAsString.endIndex])
let parametersAsString: String let parametersAsString: String
if let tsRequest = request as? TSRequest { if let tsRequest = request as? TSRequest {
headers["Content-Type"] = "application/json"
let parametersAsData = try JSONSerialization.data(withJSONObject: tsRequest.parameters, options: []) let parametersAsData = try JSONSerialization.data(withJSONObject: tsRequest.parameters, options: [])
parametersAsString = !tsRequest.parameters.isEmpty ? String(bytes: parametersAsData, encoding: .utf8)! : "null" parametersAsString = !tsRequest.parameters.isEmpty ? String(bytes: parametersAsData, encoding: .utf8)! : "null"
} else { } else {
headers["Content-Type"] = request.allHTTPHeaderFields!["Content-Type"]
if let parametersAsInputStream = request.httpBodyStream, let parametersAsData = try? Data(from: parametersAsInputStream) { if let parametersAsInputStream = request.httpBodyStream, let parametersAsData = try? Data(from: parametersAsInputStream) {
parametersAsString = "{ \"fileUpload\" : \"\(String(data: parametersAsData.base64EncodedData(), encoding: .utf8) ?? "null")\" }" parametersAsString = "{ \"fileUpload\" : \"\(String(data: parametersAsData.base64EncodedData(), encoding: .utf8) ?? "null")\" }"
} else { } else {

Loading…
Cancel
Save