From fa43f2f8347b6557626ef9bcfe312d89e8b4c5e2 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 4 Feb 2020 11:34:39 +1100 Subject: [PATCH] WIP --- .../Cells/ConversationMediaView.swift | 8 +++++--- .../ConversationView/Cells/MediaAlbumCellView.swift | 6 +++--- .../ConversationView/Cells/OWSMessageBubbleView.m | 12 +++++++----- .../src/Loki/API/LokiFileServerProxy.swift | 5 +++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift b/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift index f14674811..b725b8ad3 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift +++ b/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift @@ -28,7 +28,7 @@ public class ConversationMediaView: UIView { private let maxMessageWidth: CGFloat private var loadBlock: (() -> Void)? private var unloadBlock: (() -> Void)? - var isClosedGroup = false + private let isProxied: Bool // MARK: - LoadState @@ -91,11 +91,13 @@ public class ConversationMediaView: UIView { public required init(mediaCache: NSCache, attachment: TSAttachment, isOutgoing: Bool, - maxMessageWidth: CGFloat) { + maxMessageWidth: CGFloat, + isProxied: Bool) { self.mediaCache = mediaCache self.attachment = attachment self.isOutgoing = isOutgoing self.maxMessageWidth = maxMessageWidth + self.isProxied = isProxied super.init(frame: .zero) @@ -174,7 +176,7 @@ public class ConversationMediaView: UIView { } 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 let attachmentStream = attachment as? TSAttachmentStream else { return false } guard let attachmentId = attachmentStream.uniqueId else { diff --git a/Signal/src/ViewControllers/ConversationView/Cells/MediaAlbumCellView.swift b/Signal/src/ViewControllers/ConversationView/Cells/MediaAlbumCellView.swift index 6e0930818..c1f0085cc 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/MediaAlbumCellView.swift +++ b/Signal/src/ViewControllers/ConversationView/Cells/MediaAlbumCellView.swift @@ -27,14 +27,14 @@ public class MediaAlbumCellView: UIStackView { items: [ConversationMediaAlbumItem], isOutgoing: Bool, maxMessageWidth: CGFloat, - isClosedGroup: Bool) { + isProxied: Bool) { self.items = items self.itemViews = MediaAlbumCellView.itemsToDisplay(forItems: items).map { let result = ConversationMediaView(mediaCache: mediaCache, attachment: $0.attachment, isOutgoing: isOutgoing, - maxMessageWidth: maxMessageWidth) - result.isClosedGroup = isClosedGroup + maxMessageWidth: maxMessageWidth, + isProxied: isProxied) return result } diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index 8bea3119f..8ebbb2e57 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -799,12 +799,14 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssertDebug(self.viewItem.mediaAlbumItems); - BOOL isClosedGroup = NO; - if ([self.viewItem isKindOfClass:TSOutgoingMessage.class]) { - TSOutgoingMessage *message = (TSOutgoingMessage *)self.viewItem; + BOOL isProxied = NO; + if ([self.viewItem.interaction isKindOfClass:TSOutgoingMessage.class]) { + TSOutgoingMessage *message = (TSOutgoingMessage *)self.viewItem.interaction; if ([message.thread isKindOfClass:TSGroupThread.class]) { 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 isOutgoing:self.isOutgoing maxMessageWidth:self.conversationStyle.maxMessageWidth - isClosedGroup:isClosedGroup]; + isProxied:isProxied]; self.loadCellContentBlock = ^{ [albumView loadMedia]; }; diff --git a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift index 52a6de39a..02114eed8 100644 --- a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift +++ b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift @@ -46,19 +46,20 @@ internal class LokiFileServerProxy : LokiHTTPClient { let uncheckedSymmetricKey = try? Curve25519.generateSharedSecret(fromPublicKey: LokiFileServerProxy.fileServerPublicKey, privateKey: keyPair.privateKey) guard let symmetricKey = uncheckedSymmetricKey else { return Promise(error: Error.symmetricKeyGenerationFailed) } 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 in 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, serverURLEndIndex < urlAsString.endIndex else { throw Error.endpointParsingFailed } let endpointStartIndex = urlAsString.index(after: serverURLEndIndex) let endpoint = String(urlAsString[endpointStartIndex..