                     break
                 }
             }
-
-//            if progressReporter.downloadTasks.filter({ $0 == downloadTask }).count > 0 {
-//                progressReporter.progress[].completedUnitCount += bytesWritten
-//
-//                progressReporter.reportProgressAction?(progressReporter.progress.fractionCompleted)
-//
-//                println("progressReporter.progress.completedUnitCount: \(progressReporter.progress.completedUnitCount)")
-//            }
-        }
-
-
-        //let progress: Double = Double(totalBytesWritten) / Double(totalBytesExpectedToWrite)
-
-        //reportProgress(progress, ofDownloadTask: downloadTask)
-
-        //println("downloadTask progress \(progress)")
-    }
-
-//    func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didResumeAtOffset fileOffset: Int64, expectedTotalBytes: Int64) {
-//
-//        println("fuck")
-//        
-//        for progressReporter in progressReporters {
-//            if progressReporter.downloadTasks.filter({ $0 == downloadTask }).count > 0 {
-//                if progressReporter.progress.totalUnitCount == -1 {
-//                    progressReporter.progress.totalUnitCount = expectedTotalBytes
-//                } else {
-//                    progressReporter.progress.totalUnitCount += expectedTotalBytes
-//                }
-//            }
-//
-//            println("progressReporter.progress.totalUnitCount: \(progressReporter.progress.totalUnitCount)")
-//        }
-//    }
+        }
+    }
+
 }
 

            }

            var progress = [NSProgress]()

            for _ in downloadTasks {
                progress.append(NSProgress())
            }

            let progressReporter = ProgressReporter(downloadTasks: downloadTasks, reportProgressAction: reportProgress, finishedActions: [attachmentFinishedAction, thumbnailFinishedAction], progress: progress)

            sharedDownloader.progressReporters.append(progressReporter)

            //downloadTask.resume()
            downloadTasks.map { $0.resume() }
        }

        /*
        if mediaType == MessageMediaType.Video.rawValue {

            let thumbnailURLString = message.thumbnailURLString

            if !thumbnailURLString.isEmpty && message.localThumbnailName.isEmpty, let URL = NSURL(string: thumbnailURLString) {

                let downloadTask = sharedDownloader.session.downloadTaskWithURL(URL, completionHandler: { location, response, error in

                    if let location = location, data = NSData(contentsOfURL: location) {

                        let fileName = NSUUID().UUIDString

                        dispatch_async(dispatch_get_main_queue()) {
                            let realm = Realm()

                            if let message = messageWithMessageID(messageID, inRealm: realm) {

                                if message.localThumbnailName.isEmpty {

                                    if let fileURL = NSFileManager.saveMessageImageData(data, withName: fileName) {

                                        self.updateThumbnailOfMessage(message, withThumbnailFileName: fileName, inRealm: realm)

                                        if let image = UIImage(data: data) {
                                            imageFinished?(image)
                                        }
                                    }
                                }
                            }
                        }
                    }
                })
                
                downloadTask.resume()
            }
        }
        */
    }
}



extension YepDownloader: NSURLSessionDownloadDelegate {

    private func handleData(data: NSData, ofDownloadTask downloadTask: NSURLSessionDownloadTask) {

        for progressReporter in progressReporters {

