|
|
@ -54,11 +54,15 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
|
|
|
|
let temporaryFilePath = URL(fileURLWithPath: OWSTemporaryDirectoryAccessibleAfterFirstAuth() + UUID().uuidString)
|
|
|
|
let temporaryFilePath = URL(fileURLWithPath: OWSTemporaryDirectoryAccessibleAfterFirstAuth() + UUID().uuidString)
|
|
|
|
let handleFailure: (Swift.Error) -> Void = { error in // Intentionally capture self
|
|
|
|
let handleFailure: (Swift.Error) -> Void = { error in // Intentionally capture self
|
|
|
|
OWSFileSystem.deleteFile(temporaryFilePath.absoluteString)
|
|
|
|
OWSFileSystem.deleteFile(temporaryFilePath.absoluteString)
|
|
|
|
|
|
|
|
if let error = error as? Error, case .noAttachment = error {
|
|
|
|
storage.withAsync({ transaction in
|
|
|
|
storage.withAsync({ transaction in
|
|
|
|
storage.setAttachmentState(to: .failed, for: pointer, associatedWith: self.tsIncomingMessageID, using: transaction)
|
|
|
|
storage.setAttachmentState(to: .failed, for: pointer, associatedWith: self.tsIncomingMessageID, using: transaction)
|
|
|
|
}, completion: { })
|
|
|
|
}, completion: { })
|
|
|
|
|
|
|
|
self.handlePermanentFailure(error: error)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
self.handleFailure(error: error)
|
|
|
|
self.handleFailure(error: error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
FileServerAPI.downloadAttachment(from: pointer.downloadURL).done(on: DispatchQueue.global(qos: .userInitiated)) { data in
|
|
|
|
FileServerAPI.downloadAttachment(from: pointer.downloadURL).done(on: DispatchQueue.global(qos: .userInitiated)) { data in
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
try data.write(to: temporaryFilePath, options: .atomic)
|
|
|
|
try data.write(to: temporaryFilePath, options: .atomic)
|
|
|
@ -94,6 +98,10 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
|
|
|
|
delegate?.handleJobSucceeded(self)
|
|
|
|
delegate?.handleJobSucceeded(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func handlePermanentFailure(error: Swift.Error) {
|
|
|
|
|
|
|
|
delegate?.handleJobFailedPermanently(self, with: error)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private func handleFailure(error: Swift.Error) {
|
|
|
|
private func handleFailure(error: Swift.Error) {
|
|
|
|
delegate?.handleJobFailed(self, with: error)
|
|
|
|
delegate?.handleJobFailed(self, with: error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|