diff --git a/Session/Signal/AppDelegate.m b/Session/Signal/AppDelegate.m index 338fac2b4..238397962 100644 --- a/Session/Signal/AppDelegate.m +++ b/Session/Signal/AppDelegate.m @@ -217,6 +217,10 @@ static NSTimeInterval launchStartedAt; [SNConfiguration performMainSetup]; + if (CurrentAppContext().isMainApp) { + [SNJobQueue resumePendingJobs]; + } + [LKAppearanceUtilities switchToSessionAppearance]; if (CurrentAppContext().isRunningTests) { diff --git a/SessionMessagingKit/Jobs/AttachmentUploadJob.swift b/SessionMessagingKit/Jobs/AttachmentUploadJob.swift index b504272e8..6caf85c4b 100644 --- a/SessionMessagingKit/Jobs/AttachmentUploadJob.swift +++ b/SessionMessagingKit/Jobs/AttachmentUploadJob.swift @@ -2,7 +2,7 @@ import SessionUtilitiesKit public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/NSCoding conformance is needed for YapDatabase compatibility public var delegate: JobDelegate? - private let attachmentID: String + public let attachmentID: String private let threadID: String public var id: String? public var failureCount: UInt = 0 diff --git a/SessionMessagingKit/Jobs/MessageSendJob.swift b/SessionMessagingKit/Jobs/MessageSendJob.swift index 467c9e00c..1c9a9b2ea 100644 --- a/SessionMessagingKit/Jobs/MessageSendJob.swift +++ b/SessionMessagingKit/Jobs/MessageSendJob.swift @@ -77,6 +77,7 @@ public final class MessageSendJob : NSObject, Job, NSCoding { // NSObject/NSCodi } if !attachmentsToUpload.isEmpty { delegate?.postpone(self); return } // Wait for all attachments to upload before continuing } + // FIXME: This doesn't yet handle the attachment side of link previews, quotes, etc. storage.withAsync({ transaction in // Intentionally capture self Threading.workQueue.async { MessageSender.send(self.message, to: self.destination, using: transaction).done(on: Threading.workQueue) { diff --git a/SessionMessagingKit/Messages/Visible Messages/VisibleMessage.swift b/SessionMessagingKit/Messages/Visible Messages/VisibleMessage.swift index e0339d25f..3cd5fab53 100644 --- a/SessionMessagingKit/Messages/Visible Messages/VisibleMessage.swift +++ b/SessionMessagingKit/Messages/Visible Messages/VisibleMessage.swift @@ -55,7 +55,14 @@ public final class VisibleMessage : Message { dataMessage = SNProtoDataMessage.builder() } if let text = text { dataMessage.setBody(text) } - // TODO: Attachments + let attachments = attachmentIDs.compactMap { TSAttachmentStream.fetch(uniqueId: $0) } + if !attachments.allSatisfy({ $0.isUploaded }) { + #if DEBUG + preconditionFailure("Sending a message before all associated attachments have been uploaded.") + #endif + } + let attachmentProtos = attachments.compactMap { TSAttachmentStream.buildProto(forAttachmentId: $0.uniqueId!) } + dataMessage.setAttachments(attachmentProtos) if let quote = quote, let quoteProto = quote.toProto() { dataMessage.setQuote(quoteProto) } if let linkPreview = linkPreview, let linkPreviewProto = linkPreview.toProto() { dataMessage.setPreview([ linkPreviewProto ]) } // TODO: Contact diff --git a/SignalUtilitiesKit/Database/Storage/Storage+Jobs.swift b/SignalUtilitiesKit/Database/Storage/Storage+Jobs.swift index 12a223fc6..60c18412f 100644 --- a/SignalUtilitiesKit/Database/Storage/Storage+Jobs.swift +++ b/SignalUtilitiesKit/Database/Storage/Storage+Jobs.swift @@ -25,6 +25,16 @@ extension Storage { } public func getAttachmentUploadJob(for attachmentID: String) -> AttachmentUploadJob? { - return nil // TODO: Implement + var result: [AttachmentUploadJob] = [] + Storage.read { transaction in + transaction.enumerateRows(inCollection: AttachmentUploadJob.collection) { _, object, _, _ in + guard let job = object as? AttachmentUploadJob, job.attachmentID == attachmentID else { return } + result.append(job) + } + } + #if DEBUG + assert(result.isEmpty || result.count == 1) + #endif + return result.first } }