clean attachment download job

This commit is contained in:
ryanzhao 2021-08-25 16:39:30 +10:00
parent f99fa58acc
commit 70e38e11d8
1 changed files with 0 additions and 11 deletions

View File

@ -60,10 +60,6 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
// MARK: Running
public func execute() {
execute(completion: nil)
}
public func execute(completion: (() -> Void)?) {
if let id = id {
JobQueue.currentlyExecutingJobs.insert(id)
}
@ -71,11 +67,9 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
if TSAttachment.fetch(uniqueId: attachmentID) is TSAttachmentStream {
// FIXME: It's not clear * how * this happens, but apparently we can get to this point
// from time to time with an already downloaded attachment.
completion?()
return handleSuccess()
}
guard let pointer = TSAttachment.fetch(uniqueId: attachmentID) as? TSAttachmentPointer else {
completion?()
return handleFailure(error: Error.noAttachment)
}
let storage = SNMessagingKitConfiguration.shared.storage
@ -98,10 +92,8 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
storage.setAttachmentState(to: .failed, for: pointer, associatedWith: self.tsMessageID, using: transaction)
}, completion: { })
// This usually indicates a file that has expired on the server, so there's no need to retry.
completion?()
self.handlePermanentFailure(error: error)
} else {
completion?()
self.handleFailure(error: error)
}
}
@ -111,7 +103,6 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
}
OpenGroupAPIV2.download(file, from: v2OpenGroup.room, on: v2OpenGroup.server).done(on: DispatchQueue.global(qos: .userInitiated)) { data in
self.handleDownloadedAttachment(data: data, temporaryFilePath: temporaryFilePath, pointer: pointer, failureHandler: handleFailure)
completion?()
}.catch(on: DispatchQueue.global()) { error in
handleFailure(error)
}
@ -122,7 +113,6 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
let useOldServer = pointer.downloadURL.contains(FileServerAPIV2.oldServer)
FileServerAPIV2.download(file, useOldServer: useOldServer).done(on: DispatchQueue.global(qos: .userInitiated)) { data in
self.handleDownloadedAttachment(data: data, temporaryFilePath: temporaryFilePath, pointer: pointer, failureHandler: handleFailure)
completion?()
}.catch(on: DispatchQueue.global()) { error in
handleFailure(error)
}
@ -172,4 +162,3 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
delegate?.handleJobFailed(self, with: error)
}
}