From c5a7d39518c7c4f17ae23b585f9b09bab6c4f307 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Sat, 28 Nov 2020 13:57:03 +1100 Subject: [PATCH] Clean --- .../Sending & Receiving/MessageReceiver+Handling.swift | 9 +++++---- .../Quotes/TSQuotedMessage+Conversion.swift | 1 - .../Sending & Receiving/MessageSender+Handling.swift | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift index 2ffa63e37..a1fb885c0 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift @@ -143,8 +143,9 @@ extension MessageReceiver { guard let attachment = VisibleMessage.Attachment.fromProto(proto) else { return nil } return attachment.isValid ? attachment : nil } - var attachmentIDs = storage.persist(attachments, using: transaction) + let attachmentIDs = storage.persist(attachments, using: transaction) message.attachmentIDs = attachmentIDs + var attachmentsToDownload = attachmentIDs // Update profile if needed if let newProfile = message.profile { let profileManager = SSKEnvironment.shared.profileManager @@ -164,7 +165,7 @@ extension MessageReceiver { if message.quote != nil && proto.dataMessage?.quote != nil, let thread = TSThread.fetch(uniqueId: threadID, transaction: transaction) { tsQuotedMessage = TSQuotedMessage(for: proto.dataMessage!, thread: thread, transaction: transaction) if let id = tsQuotedMessage?.thumbnailAttachmentStreamId() ?? tsQuotedMessage?.thumbnailAttachmentPointerId() { - attachmentIDs.append(id) + attachmentsToDownload.append(id) } } // Parse link preview if needed @@ -172,7 +173,7 @@ extension MessageReceiver { if message.linkPreview != nil && proto.dataMessage?.preview.isEmpty == false { owsLinkPreview = try? OWSLinkPreview.buildValidatedLinkPreview(dataMessage: proto.dataMessage!, body: message.text, transaction: transaction) if let id = owsLinkPreview?.imageAttachmentId { - attachmentIDs.append(id) + attachmentsToDownload.append(id) } } // Persist the message @@ -181,7 +182,7 @@ extension MessageReceiver { message.threadID = threadID // Start attachment downloads if needed storage.withAsync({ transaction in - attachmentIDs.forEach { attachmentID in + attachmentsToDownload.forEach { attachmentID in let downloadJob = AttachmentDownloadJob(attachmentID: attachmentID, tsIncomingMessageID: tsIncomingMessageID) if CurrentAppContext().isMainAppAndActive { // This has to be called from the main thread JobQueue.shared.add(downloadJob, using: transaction) diff --git a/SessionMessagingKit/Sending & Receiving/Quotes/TSQuotedMessage+Conversion.swift b/SessionMessagingKit/Sending & Receiving/Quotes/TSQuotedMessage+Conversion.swift index 3bb505360..377317376 100644 --- a/SessionMessagingKit/Sending & Receiving/Quotes/TSQuotedMessage+Conversion.swift +++ b/SessionMessagingKit/Sending & Receiving/Quotes/TSQuotedMessage+Conversion.swift @@ -2,7 +2,6 @@ extension TSQuotedMessage { /// To be used for outgoing messages only. - @objc(from:) public static func from(_ quote: VisibleMessage.Quote?) -> TSQuotedMessage? { guard let quote = quote else { return nil } var attachments: [TSAttachment] = [] diff --git a/SignalUtilitiesKit/Messaging/Sending & Receiving/MessageSender+Handling.swift b/SignalUtilitiesKit/Messaging/Sending & Receiving/MessageSender+Handling.swift index fb3faed8c..681730caf 100644 --- a/SignalUtilitiesKit/Messaging/Sending & Receiving/MessageSender+Handling.swift +++ b/SignalUtilitiesKit/Messaging/Sending & Receiving/MessageSender+Handling.swift @@ -12,6 +12,8 @@ extension MessageSender : SharedSenderKeysDelegate { #endif return } + // Anything added to message.attachmentIDs will be uploaded by an UploadAttachmentJob. Any attachment IDs added to tsMessage will + // make it render as an attachment (not what we want in the case of a link preview or quoted attachment). var streams: [TSAttachmentStream] = [] attachments.forEach { let stream = TSAttachmentStream(contentType: $0.mimeType, byteCount: UInt32($0.dataLength), sourceFilename: $0.sourceFilename,