From aa68e91a4df0260211f8638547387e91a143c30f Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 8 Apr 2021 09:51:52 +1000 Subject: [PATCH] Fix attachment download resumption --- .../DownloadAttachmentModal.swift | 20 +++++++++---------- .../Database/Storage+Jobs.swift | 1 + .../Jobs/AttachmentDownloadJob.swift | 5 ++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Session/Conversations/Views & Modals/DownloadAttachmentModal.swift b/Session/Conversations/Views & Modals/DownloadAttachmentModal.swift index a9b6bcd8a..1e0bf7362 100644 --- a/Session/Conversations/Views & Modals/DownloadAttachmentModal.swift +++ b/Session/Conversations/Views & Modals/DownloadAttachmentModal.swift @@ -37,17 +37,17 @@ final class DownloadAttachmentModal : Modal { messageLabel.numberOfLines = 0 messageLabel.lineBreakMode = .byWordWrapping messageLabel.textAlignment = .center - // Unblock button - let unblockButton = UIButton() - unblockButton.set(.height, to: Values.mediumButtonHeight) - unblockButton.layer.cornerRadius = Modal.buttonCornerRadius - unblockButton.backgroundColor = Colors.buttonBackground - unblockButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize) - unblockButton.setTitleColor(Colors.text, for: UIControl.State.normal) - unblockButton.setTitle("Download", for: UIControl.State.normal) - unblockButton.addTarget(self, action: #selector(trust), for: UIControl.Event.touchUpInside) + // Download button + let downloadButton = UIButton() + downloadButton.set(.height, to: Values.mediumButtonHeight) + downloadButton.layer.cornerRadius = Modal.buttonCornerRadius + downloadButton.backgroundColor = Colors.buttonBackground + downloadButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize) + downloadButton.setTitleColor(Colors.text, for: UIControl.State.normal) + downloadButton.setTitle("Download", for: UIControl.State.normal) + downloadButton.addTarget(self, action: #selector(trust), for: UIControl.Event.touchUpInside) // Button stack view - let buttonStackView = UIStackView(arrangedSubviews: [ cancelButton, unblockButton ]) + let buttonStackView = UIStackView(arrangedSubviews: [ cancelButton, downloadButton ]) buttonStackView.axis = .horizontal buttonStackView.spacing = Values.mediumSpacing buttonStackView.distribution = .fillEqually diff --git a/SessionMessagingKit/Database/Storage+Jobs.swift b/SessionMessagingKit/Database/Storage+Jobs.swift index d5c520dde..9f1362bd5 100644 --- a/SessionMessagingKit/Database/Storage+Jobs.swift +++ b/SessionMessagingKit/Database/Storage+Jobs.swift @@ -88,6 +88,7 @@ extension Storage { let jobs = getAttachmentDownloadJobs(for: tsMessageID) jobs.forEach { job in job.delegate = JobQueue.shared + job.isDeferred = false job.execute() } } diff --git a/SessionMessagingKit/Jobs/AttachmentDownloadJob.swift b/SessionMessagingKit/Jobs/AttachmentDownloadJob.swift index eee699cc8..8953ed17b 100644 --- a/SessionMessagingKit/Jobs/AttachmentDownloadJob.swift +++ b/SessionMessagingKit/Jobs/AttachmentDownloadJob.swift @@ -36,13 +36,12 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject public init?(coder: NSCoder) { guard let attachmentID = coder.decodeObject(forKey: "attachmentID") as! String?, let tsMessageID = coder.decodeObject(forKey: "tsIncomingMessageID") as! String?, - let id = coder.decodeObject(forKey: "id") as! String?, - let isDeferred = coder.decodeObject(forKey: "isDeferred") as! Bool? else { return nil } + let id = coder.decodeObject(forKey: "id") as! String? else { return nil } self.attachmentID = attachmentID self.tsMessageID = tsMessageID self.id = id self.failureCount = coder.decodeObject(forKey: "failureCount") as! UInt? ?? 0 - self.isDeferred = isDeferred + self.isDeferred = coder.decodeBool(forKey: "isDeferred") } public func encode(with coder: NSCoder) {