mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-09 04:46:35 +10:00
use uploadImagesQueue to upload feed images
This commit is contained in:
@@ -753,9 +753,10 @@ class NewFeedViewController: SegueViewController {
|
||||
|
||||
case .Default:
|
||||
|
||||
let uploadImagesGroup = dispatch_group_create()
|
||||
let uploadImagesQueue = NSOperationQueue()
|
||||
var uploadAttachmentOperations = [UploadAttachmentOperation]()
|
||||
//let uploadImagesGroup = dispatch_group_create()
|
||||
|
||||
//var uploadImageInfos = [UploadImageInfo]()
|
||||
var uploadAttachmentIDs = [String]()
|
||||
|
||||
let mediaImagesCount = mediaImages.count
|
||||
@@ -783,7 +784,7 @@ class NewFeedViewController: SegueViewController {
|
||||
|
||||
if let image = image.resizeToSize(fixedSize, withInterpolationQuality: CGInterpolationQuality.High), imageData = UIImageJPEGRepresentation(image, 0.95) {
|
||||
|
||||
dispatch_group_enter(uploadImagesGroup)
|
||||
//dispatch_group_enter(uploadImagesGroup)
|
||||
|
||||
let source: UploadAttachment.Source = .Data(imageData)
|
||||
|
||||
@@ -791,6 +792,14 @@ class NewFeedViewController: SegueViewController {
|
||||
|
||||
let uploadAttachment = UploadAttachment(type: .Feed, source: source, fileExtension: .JPEG, metaDataString: metaDataString)
|
||||
|
||||
let operation = UploadAttachmentOperation(uploadAttachment: uploadAttachment)
|
||||
operation.completionBlock = {
|
||||
if let uploadAttachmentID = operation.uploadAttachmentID {
|
||||
uploadAttachmentIDs.append(uploadAttachmentID)
|
||||
}
|
||||
}
|
||||
uploadAttachmentOperations.append(operation)
|
||||
/*
|
||||
tryUploadAttachment(uploadAttachment, failureHandler: { (reason, errorMessage) in
|
||||
|
||||
defaultFailureHandler(reason, errorMessage: errorMessage)
|
||||
@@ -808,38 +817,18 @@ class NewFeedViewController: SegueViewController {
|
||||
dispatch_group_leave(uploadImagesGroup)
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
let fileExtension: FileExtension = .JPEG
|
||||
|
||||
s3UploadFileOfKind(.Feed, withFileExtension: fileExtension, inFilePath: nil, orFileData: imageData, mimeType: fileExtension.mimeType, failureHandler: { (reason, errorMessage) in
|
||||
|
||||
defaultFailureHandler(reason, errorMessage: errorMessage)
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
uploadErrorMessage = errorMessage
|
||||
dispatch_group_leave(uploadImagesGroup)
|
||||
}
|
||||
|
||||
}, completion: { s3UploadParams in
|
||||
|
||||
// Prepare meta data
|
||||
|
||||
let metaDataString = metaDataStringOfImage(image, needBlurThumbnail: false)
|
||||
|
||||
let uploadImageInfo = UploadImageInfo(s3UploadParams: s3UploadParams, metaDataString: metaDataString)
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
uploadImageInfos.append(uploadImageInfo)
|
||||
|
||||
dispatch_group_leave(uploadImagesGroup)
|
||||
}
|
||||
})
|
||||
*/
|
||||
}
|
||||
})
|
||||
|
||||
dispatch_group_notify(uploadImagesGroup, dispatch_get_main_queue()) { [weak self] in
|
||||
for i in 1..<uploadAttachmentOperations.count {
|
||||
let previousOperation = uploadAttachmentOperations[i-1]
|
||||
let currentOperation = uploadAttachmentOperations[i]
|
||||
|
||||
currentOperation.addDependency(previousOperation)
|
||||
}
|
||||
|
||||
let uploadFinishOperation = NSBlockOperation { [weak self] in
|
||||
|
||||
guard uploadAttachmentIDs.count == mediaImagesCount else {
|
||||
let message = uploadErrorMessage ?? NSLocalizedString("Upload failed!", comment: "")
|
||||
@@ -850,14 +839,36 @@ class NewFeedViewController: SegueViewController {
|
||||
|
||||
if !uploadAttachmentIDs.isEmpty {
|
||||
|
||||
/*
|
||||
let imageInfosData = uploadImageInfos.map({
|
||||
[
|
||||
"file": $0.s3UploadParams.key,
|
||||
"metadata": $0.metaDataString ?? "",
|
||||
]
|
||||
let imageInfos: [JSONDictionary] = uploadAttachmentIDs.map({
|
||||
["id": $0]
|
||||
})
|
||||
*/
|
||||
|
||||
attachments = imageInfos
|
||||
|
||||
kind = .Image
|
||||
}
|
||||
|
||||
tryCreateFeed()
|
||||
}
|
||||
|
||||
if let lastUploadAttachmentOperation = uploadAttachmentOperations.last {
|
||||
uploadFinishOperation.addDependency(lastUploadAttachmentOperation)
|
||||
}
|
||||
|
||||
uploadImagesQueue.addOperations(uploadAttachmentOperations, waitUntilFinished: false)
|
||||
uploadImagesQueue.addOperation(uploadFinishOperation)
|
||||
|
||||
/*
|
||||
dispatch_group_notify(uploadImagesGroup, dispatch_get_main_queue()) { [weak self] in
|
||||
|
||||
guard uploadAttachmentIDs.count == mediaImagesCount else {
|
||||
let message = uploadErrorMessage ?? NSLocalizedString("Upload failed!", comment: "")
|
||||
self?.uploadState = .Failed(message: message)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if !uploadAttachmentIDs.isEmpty {
|
||||
|
||||
let imageInfos: [JSONDictionary] = uploadAttachmentIDs.map({
|
||||
["id": $0]
|
||||
@@ -870,6 +881,7 @@ class NewFeedViewController: SegueViewController {
|
||||
|
||||
tryCreateFeed()
|
||||
}
|
||||
*/
|
||||
|
||||
case .SocialWork(let socialWork):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user