                             let realm = Realm()
 
                             if let message = messageWithMessageID(messageID, inRealm: realm) {
-
-                                switch mediaType {
-
-                                case MessageMediaType.Image.rawValue:
-
-                                    if let fileURL = NSFileManager.saveMessageImageData(data, withName: fileName) {
-                                        self.updateAttachmentOfMessage(message, withAttachmentFileName: fileName, inRealm: realm)
-                                    }
-
-                                case MessageMediaType.Video.rawValue:
-
-                                    if let fileURL = NSFileManager.saveMessageVideoData(data, withName: fileName) {
-                                        self.updateAttachmentOfMessage(message, withAttachmentFileName: fileName, inRealm: realm)
-                                    }
-
-                                case MessageMediaType.Audio.rawValue:
-                                    
-                                    if let fileURL = NSFileManager.saveMessageAudioData(data, withName: fileName) {
-                                        self.updateAttachmentOfMessage(message, withAttachmentFileName: fileName, inRealm: realm)
-                                    }
-
-                                default:
-                                    break
+                                if let fileURL = NSFileManager.saveMessageImageData(data, withName: fileName) {
+                                    self.updateThumbnailOfMessage(message, withThumbnailFileName: fileName, inRealm: realm)
                                 }
                             }
                         }
                     }
                 })
-
+                
                 downloadTask.resume()
             }
         }
-
-        if mediaType == MessageMediaType.Video.rawValue {
-
-            let thumbnailURLString = message.thumbnailURLString
-
-            if !thumbnailURLString.isEmpty && message.localThumbnailName.isEmpty {
-
-                if let URL = NSURL(string: thumbnailURLString) {
-
-                    let downloadTask = sharedDownloader.session.downloadTaskWithURL(URL, completionHandler: { location, response, error in
-
-                        if let 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 let fileURL = NSFileManager.saveMessageImageData(data, withName: fileName) {
-                                        self.updateThumbnailOfMessage(message, withThumbnailFileName: fileName, inRealm: realm)
-                                    }
-                                }
-                            }
-                        }
-                    })
-
-                    downloadTask.resume()
-                }
-            }
-        }
     }
-
 }
 
 extension YepDownloader: NSURLSessionDelegate {
 
 }
 
+extension YepDownloader: NSURLSessionDownloadDelegate {
+
+    private func reportProgress(progress: Double, ofDownloadTask downloadTask: NSURLSessionDownloadTask) {
+        progressReporters.filter({ $0.downloadTask == downloadTask }).map({ $0.reportProgressAction?(progress) })
+    }
+
+    private func handleData(data: NSData, ofDownloadTask downloadTask: NSURLSessionDownloadTask) {
+        progressReporters.filter({ $0.downloadTask == downloadTask }).map({ $0.finishedAction(data) })
+    }
+
+    func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) {
+
+        if let data = NSData(contentsOfURL: location) {
+            handleData(data, ofDownloadTask: downloadTask)
+        }
+
+        reportProgress(1.0, ofDownloadTask: downloadTask)
+
+        println("didFinishDownloadingToURL")
+    }
+
+    func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
+
+        let progress: Double = Double(totalBytesWritten) / Double(totalBytesExpectedToWrite)
+
+        reportProgress(progress, ofDownloadTask: downloadTask)
+
+        println("downloadTask progress \(progress)")
+    }
+}
+


        if downloadState == MessageDownloadState.Downloaded.rawValue {
            reportProgress?(1.0)
        }
        
        if !attachmentURLString.isEmpty {

            if let URL = NSURL(string: attachmentURLString) {

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

                    if let data = NSData(contentsOfURL: location) {

                        reportProgress?(1.0)

                        let fileName = NSUUID().UUIDString



    struct ProgressReporter {

        let downloadTask: NSURLSessionDownloadTask

        typealias ReportAction = Double -> Void

        let reportProgressAction: ReportAction?

        let finishedAction: NSData -> Void
    }

    var progressReporters = [ProgressReporter]()

    class func downloadAttachmentsOfMessage(message: Message, reportProgress: ProgressReporter.ReportAction?) {

