This commit is contained in:
nielsandriesse 2020-11-28 13:57:03 +11:00
parent d39e155e1c
commit c5a7d39518
3 changed files with 7 additions and 5 deletions

View File

@ -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)

View File

@ -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] = []

View File

@ -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,