|
|
@ -48,10 +48,17 @@ public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/N
|
|
|
|
guard !stream.isUploaded else { return handleSuccess() } // Should never occur
|
|
|
|
guard !stream.isUploaded else { return handleSuccess() } // Should never occur
|
|
|
|
let openGroup = Configuration.shared.storage.getOpenGroup(for: threadID)
|
|
|
|
let openGroup = Configuration.shared.storage.getOpenGroup(for: threadID)
|
|
|
|
let server = openGroup?.server ?? FileServerAPI.server
|
|
|
|
let server = openGroup?.server ?? FileServerAPI.server
|
|
|
|
|
|
|
|
// FIXME: A lot of what's currently happening in FileServerAPI should really be happening here
|
|
|
|
FileServerAPI.uploadAttachment(stream, with: attachmentID, to: server).done(on: DispatchQueue.global(qos: .userInitiated)) { // Intentionally capture self
|
|
|
|
FileServerAPI.uploadAttachment(stream, with: attachmentID, to: server).done(on: DispatchQueue.global(qos: .userInitiated)) { // Intentionally capture self
|
|
|
|
self.handleSuccess()
|
|
|
|
self.handleSuccess()
|
|
|
|
}.catch(on: DispatchQueue.global(qos: .userInitiated)) { error in
|
|
|
|
}.catch(on: DispatchQueue.global(qos: .userInitiated)) { error in
|
|
|
|
self.handleFailure(error: error)
|
|
|
|
if let error = error as? Error, case .noAttachment = error {
|
|
|
|
|
|
|
|
self.handlePermanentFailure(error: error)
|
|
|
|
|
|
|
|
} else if let error = error as? DotNetAPI.Error, !error.isRetryable {
|
|
|
|
|
|
|
|
self.handlePermanentFailure(error: error)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
self.handleFailure(error: error)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -59,7 +66,11 @@ public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/N
|
|
|
|
delegate?.handleJobSucceeded(self)
|
|
|
|
delegate?.handleJobSucceeded(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private func handleFailure(error: Error) {
|
|
|
|
private func handlePermanentFailure(error: Swift.Error) {
|
|
|
|
|
|
|
|
delegate?.handleJobFailedPermanently(self, with: error)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func handleFailure(error: Swift.Error) {
|
|
|
|
delegate?.handleJobFailed(self, with: error)
|
|
|
|
delegate?.handleJobFailed(self, with: error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|