Browse Source

change message metadata -> ocId

marinofaggiana 4 years ago
parent
commit
b61985d566

+ 6 - 7
iOSClient/CCGlobal.h

@@ -319,16 +319,15 @@
 #define k_notificationCenter_reloadDataSource               @"reloadDataSource"                 // userInfo: ocId?, serverUrl?
 #define k_notificationCenter_reloadDataSourceNetworkForced  @"reloadDataSourceNetworkForced"    // userInfo: serverUrl?
 
-#define k_notificationCenter_mediaFileNotFound              @"mediaFileNotFound"                // userInfo: metadata
 #define k_notificationCenter_changeStatusFolderE2EE         @"changeStatusFolderE2EE"           // userInfo: serverUrl
 
-#define k_notificationCenter_downloadStartFile              @"downloadStartFile"                // userInfo: metadata
-#define k_notificationCenter_downloadedFile                 @"downloadedFile"                   // userInfo: metadata, selector, errorCode, errorDescription
-#define k_notificationCenter_downloadCancelFile             @"downloadCancelFile"               // userInfo: metadata
+#define k_notificationCenter_downloadStartFile              @"downloadStartFile"                // userInfo: ocId
+#define k_notificationCenter_downloadedFile                 @"downloadedFile"                   // userInfo: ocId, selector, errorCode, errorDescription
+#define k_notificationCenter_downloadCancelFile             @"downloadCancelFile"               // userInfo: ocId
 
-#define k_notificationCenter_uploadStartFile                @"uploadStartFile"                  // userInfo: metadata
-#define k_notificationCenter_uploadedFile                   @"uploadedFile"                     // userInfo: metadata, ocIdTemp, errorCode, errorDescription
-#define k_notificationCenter_uploadCancelFile               @"uploadCancelFile"                 // userInfo: metadata
+#define k_notificationCenter_uploadStartFile                @"uploadStartFile"                  // userInfo: ocId
+#define k_notificationCenter_uploadedFile                   @"uploadedFile"                     // userInfo: ocId, ocIdTemp, errorCode, errorDescription
+#define k_notificationCenter_uploadCancelFile               @"uploadCancelFile"                 // userInfo: ocId
 
 #define k_notificationCenter_progressTask                   @"progressTask"                     // userInfo: account, ocId, serverUrl, status, progress, totalBytes, totalBytesExpected
 

+ 51 - 43
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -404,11 +404,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata {
-                
-                if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
-                    let indexPath = IndexPath(row: row, section: 0)
-                    collectionView?.reloadItems(at: [indexPath])
+            if let ocId = userInfo["ocId"] as? String {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.reloadItems(at: [indexPath])
+                    }
                 }
             }
         }
@@ -418,12 +419,13 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata, let _ = userInfo["errorCode"] as? Int {
-                
-               if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
-                   let indexPath = IndexPath(row: row, section: 0)
-                   collectionView?.reloadItems(at: [indexPath])
-               }
+            if let ocId = userInfo["ocId"] as? String, let _ = userInfo["errorCode"] as? Int {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                   if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
+                       let indexPath = IndexPath(row: row, section: 0)
+                       collectionView?.reloadItems(at: [indexPath])
+                   }
+                }
             }
         }
     }
@@ -432,11 +434,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata {
-               
-                if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
-                    let indexPath = IndexPath(row: row, section: 0)
-                    collectionView?.reloadItems(at: [indexPath])
+            if let ocId = userInfo["ocId"] as? String {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.reloadItems(at: [indexPath])
+                    }
                 }
             }
         }
@@ -446,16 +449,18 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata {
-                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                    
-                    if let row = dataSource.addMetadata(metadata) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.performBatchUpdates({
-                            collectionView?.insertItems(at: [indexPath])
-                        }, completion: { (_) in
-                            self.collectionView?.reloadData()
-                        })
+            if let ocId = userInfo["ocId"] as? String {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                        
+                        if let row = dataSource.addMetadata(metadata) {
+                            let indexPath = IndexPath(row: row, section: 0)
+                            collectionView?.performBatchUpdates({
+                                collectionView?.insertItems(at: [indexPath])
+                            }, completion: { (_) in
+                                self.collectionView?.reloadData()
+                            })
+                        }
                     }
                 }
             }
@@ -466,11 +471,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata, let ocIdTemp = userInfo["ocIdTemp"] as? String, let _ = userInfo["errorCode"] as? Int {
-                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                   
-                    dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp)
-                    collectionView?.reloadData()
+            if let ocId = userInfo["ocId"] as? String, let ocIdTemp = userInfo["ocIdTemp"] as? String, let _ = userInfo["errorCode"] as? Int {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                        dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp)
+                        collectionView?.reloadData()
+                    }
                 }
             }
         }
@@ -480,18 +486,20 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata {
-                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                    
-                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.performBatchUpdates({
-                            collectionView?.deleteItems(at: [indexPath])
-                        }, completion: { (_) in
-                            self.collectionView?.reloadData()
-                        })
-                    } else {
-                        self.reloadDataSource()
+            if let ocId = userInfo["ocId"] as? String {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                        
+                        if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
+                            let indexPath = IndexPath(row: row, section: 0)
+                            collectionView?.performBatchUpdates({
+                                collectionView?.deleteItems(at: [indexPath])
+                            }, completion: { (_) in
+                                self.collectionView?.reloadData()
+                            })
+                        } else {
+                            self.reloadDataSource()
+                        }
                     }
                 }
             }

+ 0 - 1
iOSClient/Media/NCMedia.swift

@@ -100,7 +100,6 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         
         // Notification
         NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_deleteFile), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_mediaFileNotFound), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: k_notificationCenter_changeTheming), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_moveFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_renameFile), object: nil)

+ 11 - 10
iOSClient/Networking/NCNetworking.swift

@@ -230,7 +230,8 @@ import Queuer
         } else {
             if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
                 NCManageDatabase.sharedInstance.setMetadataSession(ocId: ocId, session: "", sessionError: "", sessionSelector: "", sessionTaskIdentifier: 0, status: Int(k_metadataStatusNormal))
-                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadCancelFile, userInfo: ["metadata":metadata])
+                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadCancelFile, userInfo: ["ocId":metadata.ocId])
+                
             }
         }
     }
@@ -253,7 +254,7 @@ import Queuer
             self.downloadRequest[fileNameLocalPath] = request
             
             NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, status: Int(k_metadataStatusDownloading))
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadStartFile, userInfo: ["metadata":metadata])
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadStartFile, userInfo: ["ocId":metadata.ocId])
             
         }, taskHandler: { (_) in
             
@@ -294,7 +295,7 @@ import Queuer
             }
             
             self.downloadRequest[fileNameLocalPath] = nil
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadedFile, userInfo: ["metadata":metadata, "selector":selector, "errorCode":errorCode, "errorDescription":errorDescription])
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadedFile, userInfo: ["ocId":metadata.ocId, "selector":selector, "errorCode":errorCode, "errorDescription":errorDescription])
             
             completion(errorCode)
         }
@@ -392,7 +393,7 @@ import Queuer
             #if !EXTENSION
             CCGraphics.createNewImage(from: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, typeFile: metadata.typeFile)
             #endif
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadStartFile, userInfo: ["metadata":metadata])
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadStartFile, userInfo: ["ocId":metadata.ocId])
             
         }, progressHandler: { (progress) in
             
@@ -428,7 +429,7 @@ import Queuer
             CCGraphics.createNewImage(from: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, typeFile: metadata.typeFile)
             #endif
             
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadStartFile, userInfo: ["metadata":metadata])
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadStartFile, userInfo: ["ocId":metadata.ocId])
             
             completion(0, "")
             
@@ -510,7 +511,7 @@ import Queuer
                 #endif                
                 
                 NCCommunicationCommon.shared.writeLog("Upload complete " + serverUrl + "/" + fileName + ", result: success(\(size) bytes)")
-                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["metadata":metadata, "ocIdTemp":ocIdTemp, "errorCode":errorCode, "errorDescription":""])
+                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["ocId":metadata.ocId, "ocIdTemp":ocIdTemp, "errorCode":errorCode, "errorDescription":""])
                 
             } else {
                 
@@ -527,7 +528,7 @@ import Queuer
                         NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                     }
                     
-                    NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadCancelFile, userInfo: ["metadata":metadata])
+                    NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadCancelFile, userInfo: ["ocId":metadata.ocId])
                 
                 } else if errorCode == 401 || errorCode == 403 {
                     
@@ -552,7 +553,7 @@ import Queuer
                     NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: errorDescription, sessionTaskIdentifier: 0, status: Int(k_metadataStatusUploadError))
                 }
                 
-                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["metadata":metadata, "ocIdTemp":ocIdTemp, "errorCode":errorCode, "errorDescription":""])
+                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["ocId":metadata.ocId, "ocIdTemp":ocIdTemp, "errorCode":errorCode, "errorDescription":""])
             }
             
             // Delete
@@ -656,7 +657,7 @@ import Queuer
             } else {
                 CCUtility.removeFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
                 NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadCancelFile, userInfo: ["metadata":metadata])
+                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadCancelFile, userInfo: ["ocId":metadata.ocId])
             }
             
             completion()
@@ -686,7 +687,7 @@ import Queuer
                     }
                     catch { }
                     NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                    NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadCancelFile, userInfo: ["metadata":metadata])
+                    NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadCancelFile, userInfo: ["ocId":metadata.ocId])
                 }
             }
             completion()

+ 7 - 7
iOSClient/Networking/NCNetworkingE2EE.swift

@@ -205,7 +205,7 @@ import Alamofire
         if metadata.size > Double(k_max_filesize_E2EE) {
             NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))
 
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["metadata":metadata, "ocIdTemp":ocIdTemp, "errorCode":k_CCErrorInternalError, "errorDescription":"E2E Error file too big"])
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["ocId":metadata.ocId, "ocIdTemp":ocIdTemp, "errorCode":k_CCErrorInternalError, "errorDescription":"E2E Error file too big"])
             completion(Int(k_CCErrorInternalError), "E2E Error file too big")
             return
         }
@@ -225,7 +225,7 @@ import Alamofire
         if NCEndToEndEncryption.sharedManager()?.encryptFileName(metadata.fileNameView, fileNameIdentifier: metadata.fileName, directory: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId), key: &key, initializationVector: &initializationVector, authenticationTag: &authenticationTag) == false {
             
             NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", ocIdTemp))
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["metadata":metadata, "ocIdTemp":ocIdTemp, "errorCode":k_CCErrorInternalError, "errorDescription":"_e2e_error_create_encrypted_"])
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["ocId":metadata.ocId, "ocIdTemp":ocIdTemp, "errorCode":k_CCErrorInternalError, "errorDescription":"_e2e_error_create_encrypted_"])
             completion(Int(k_CCErrorInternalError), "_e2e_error_create_encrypted_")
             return
         }
@@ -269,7 +269,7 @@ import Alamofire
                     NCNetworking.shared.uploadRequest[fileNameLocalPathRequest] = request
                     NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: nil, sessionSelector: nil, sessionTaskIdentifier: nil, status: Int(k_metadataStatusUploading))
                     
-                    NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadStartFile, userInfo: ["metadata":metadata])
+                    NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadStartFile, userInfo: ["ocId":metadata.ocId])
                 
                 }, taskHandler: { (_) in
                     
@@ -286,7 +286,7 @@ import Alamofire
                     
                         CCUtility.removeFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
                         NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                        NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["metadata":metadata, "ocIdTemp":ocIdTemp, "errorCode":errorCode, "errorDescription":""])
+                        NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["ocId":metadata.ocId, "ocIdTemp":ocIdTemp, "errorCode":errorCode, "errorDescription":""])
 
                     } else if errorCode == 0 && ocId != nil {
                         
@@ -310,7 +310,7 @@ import Alamofire
                         
                         CCGraphics.createNewImage(from: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, typeFile: metadata.typeFile)
                         
-                        NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["metadata":metadata, "ocIdTemp":ocIdTemp ,"errorCode":errorCode, "errorDescription":""])
+                        NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["ocId":metadata.ocId, "ocIdTemp":ocIdTemp ,"errorCode":errorCode, "errorDescription":""])
                                                                                     
                     } else {
                         
@@ -329,7 +329,7 @@ import Alamofire
                             NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: errorDescription, sessionTaskIdentifier: 0, status: Int(k_metadataStatusUploadError))
                         }
                         
-                        NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["metadata":metadata, "ocIdTemp":ocIdTemp, "errorCode":errorCode, "errorDescription":""])
+                        NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["ocId":metadata.ocId, "ocIdTemp":ocIdTemp, "errorCode":errorCode, "errorDescription":""])
                     }
                     
                     NCNetworkingE2EE.shared.unlock(account: metadata.account, serverUrl: serverUrl) { (_, _, _, _) in }
@@ -342,7 +342,7 @@ import Alamofire
                 if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdTemp) {
                     NCManageDatabase.sharedInstance.setMetadataSession(ocId: metadata.ocId, session: nil, sessionError: errorDescription, sessionTaskIdentifier: 0, status: Int(k_metadataStatusUploadError))
 
-                    NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["metadata":metadata, "ocIdTemp":ocIdTemp, "errorCode":errorCode, "errorDescription":errorDescription ?? ""])
+                    NotificationCenter.default.postOnMainThread(name: k_notificationCenter_uploadedFile, userInfo: ["ocId":metadata.ocId, "ocIdTemp":ocIdTemp, "errorCode":errorCode, "errorDescription":errorDescription ?? ""])
                 }
                 
                 completion(errorCode, errorDescription ?? "")

+ 105 - 103
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -42,125 +42,126 @@ import Foundation
     @objc func downloadedFile(_ notification: NSNotification) {
             
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata, let selector = userInfo["selector"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String {
-        
-                if metadata.account != appDelegate.account { return }
-                
-                if errorCode == 0 {
+            if let ocId = userInfo["ocId"] as? String, let selector = userInfo["selector"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if metadata.account != appDelegate.account { return }
                     
-                    let fileURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
-                    documentController = UIDocumentInteractionController(url: fileURL)
-                    documentController?.delegate = self
-
-                    switch selector {
-                    case selectorLoadFileQuickLook:
+                    if errorCode == 0 {
                         
-                        let fileNamePath = NSTemporaryDirectory() + metadata.fileNameView
-                        CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: fileNamePath)
+                        let fileURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
+                        documentController = UIDocumentInteractionController(url: fileURL)
+                        documentController?.delegate = self
 
-                        viewerQuickLook = NCViewerQuickLook.init()
-                        viewerQuickLook?.quickLook(url: URL(fileURLWithPath: fileNamePath))
-                        
-                    case selectorLoadFileView:
-                        
-                        if UIApplication.shared.applicationState == UIApplication.State.active {
-                                                        
-                            if metadata.contentType.contains("opendocument") && !NCUtility.shared.isRichDocument(metadata) {
+                        switch selector {
+                        case selectorLoadFileQuickLook:
+                            
+                            let fileNamePath = NSTemporaryDirectory() + metadata.fileNameView
+                            CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: fileNamePath)
+
+                            viewerQuickLook = NCViewerQuickLook.init()
+                            viewerQuickLook?.quickLook(url: URL(fileURLWithPath: fileNamePath))
+                            
+                        case selectorLoadFileView:
+                            
+                            if UIApplication.shared.applicationState == UIApplication.State.active {
+                                                            
+                                if metadata.contentType.contains("opendocument") && !NCUtility.shared.isRichDocument(metadata) {
+                                    
+                                    if let view = appDelegate.window?.rootViewController?.view {
+                                        documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
+                                    }
+                                    
+                                } else if metadata.typeFile == k_metadataTypeFile_compress || metadata.typeFile == k_metadataTypeFile_unknown {
+
+                                    if let view = appDelegate.window?.rootViewController?.view {
+                                        documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
+                                    }
+                                    
+                                } else if metadata.typeFile == k_metadataTypeFile_imagemeter {
+                                    
+                                    if let view = appDelegate.window?.rootViewController?.view {
+                                        documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
+                                    }
+                                    
+                                } else {
+                                    
+                                    NCViewer.shared.view(viewController: self.appDelegate.activeViewController, metadata: metadata, metadatas: [metadata])
+                                }
+                            }
+                            
+                        case selectorOpenIn:
+                            
+                            if UIApplication.shared.applicationState == UIApplication.State.active {
                                 
                                 if let view = appDelegate.window?.rootViewController?.view {
                                     documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
                                 }
-                                
-                            } else if metadata.typeFile == k_metadataTypeFile_compress || metadata.typeFile == k_metadataTypeFile_unknown {
+                            }
+                            
+                        case selectorLoadCopy:
+                            
+                            var items = UIPasteboard.general.items
+                            
+                            do {
+                                let etagPasteboard = try NSKeyedArchiver.archivedData(withRootObject: metadata.ocId, requiringSecureCoding: false)
+                                items.append([k_metadataKeyedUnarchiver:etagPasteboard])
+                            } catch {
+                                print("error")
+                            }
+                            
+                            UIPasteboard.general.setItems(items, options: [:])
+                            
+                        case selectorLoadOffline:
+                            
+                            NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: true)
+                           
+                        case selectorSaveAlbum:
+                            
+                            let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+                            let status = PHPhotoLibrary.authorizationStatus()
 
-                                if let view = appDelegate.window?.rootViewController?.view {
-                                    documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
+                            if metadata.typeFile == k_metadataTypeFile_image && status == PHAuthorizationStatus.authorized {
+                                
+                                if let image = UIImage.init(contentsOfFile: fileNamePath) {
+                                    UIImageWriteToSavedPhotosAlbum(image, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
+                                } else {
+                                    NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
                                 }
                                 
-                            } else if metadata.typeFile == k_metadataTypeFile_imagemeter {
+                            } else if metadata.typeFile == k_metadataTypeFile_video && status == PHAuthorizationStatus.authorized {
                                 
-                                if let view = appDelegate.window?.rootViewController?.view {
-                                    documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
+                                if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath) {
+                                    UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
+                                } else {
+                                    NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
                                 }
                                 
-                            } else {
+                            } else if status != PHAuthorizationStatus.authorized {
                                 
-                                NCViewer.shared.view(viewController: self.appDelegate.activeViewController, metadata: metadata, metadatas: [metadata]) 
+                                NCContentPresenter.shared.messageNotification("_access_photo_not_enabled_", description: "_access_photo_not_enabled_msg_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
                             }
-                        }
-                        
-                    case selectorOpenIn:
-                        
-                        if UIApplication.shared.applicationState == UIApplication.State.active {
                             
-                            if let view = appDelegate.window?.rootViewController?.view {
-                                documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
-                            }
-                        }
-                        
-                    case selectorLoadCopy:
-                        
-                        var items = UIPasteboard.general.items
-                        
-                        do {
-                            let etagPasteboard = try NSKeyedArchiver.archivedData(withRootObject: metadata.ocId, requiringSecureCoding: false)
-                            items.append([k_metadataKeyedUnarchiver:etagPasteboard])
-                        } catch {
-                            print("error")
+                        default:
+                            
+                            break
                         }
+                                
+                    } else {
                         
-                        UIPasteboard.general.setItems(items, options: [:])
-                        
-                    case selectorLoadOffline:
-                        
-                        NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: true)
-                       
-                    case selectorSaveAlbum:
-                        
-                        let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
-                        let status = PHPhotoLibrary.authorizationStatus()
-
-                        if metadata.typeFile == k_metadataTypeFile_image && status == PHAuthorizationStatus.authorized {
-                            
-                            if let image = UIImage.init(contentsOfFile: fileNamePath) {
-                                UIImageWriteToSavedPhotosAlbum(image, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
-                            } else {
-                                NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
-                            }
+                        // File do not exists on server, remove in local
+                        if (errorCode == k_CCErrorResourceNotFound || errorCode == k_CCErrorBadServerResponse) {
                             
-                        } else if metadata.typeFile == k_metadataTypeFile_video && status == PHAuthorizationStatus.authorized {
+                            do {
+                                try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
+                            } catch { }
                             
-                            if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath) {
-                                UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
-                            } else {
-                                NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
-                            }
+                            NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                            NCManageDatabase.sharedInstance.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                             
-                        } else if status != PHAuthorizationStatus.authorized {
+                        } else {
                             
-                            NCContentPresenter.shared.messageNotification("_access_photo_not_enabled_", description: "_access_photo_not_enabled_msg_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
+                            NCContentPresenter.shared.messageNotification("_download_file_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
                         }
-                        
-                    default:
-                        
-                        break
-                    }
-                            
-                } else {
-                    
-                    // File do not exists on server, remove in local
-                    if (errorCode == k_CCErrorResourceNotFound || errorCode == k_CCErrorBadServerResponse) {
-                        
-                        do {
-                            try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
-                        } catch { }
-                        
-                        NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                        NCManageDatabase.sharedInstance.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                        
-                    } else {
-                        
-                        NCContentPresenter.shared.messageNotification("_download_file_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
                     }
                 }
             }
@@ -183,7 +184,7 @@ import Foundation
         
         if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
             
-            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadedFile, userInfo: ["metadata": metadata, "selector": selector, "errorCode": 0, "errorDescription": "" ])
+            NotificationCenter.default.postOnMainThread(name: k_notificationCenter_downloadedFile, userInfo: ["ocId": metadata.ocId, "selector": selector, "errorCode": 0, "errorDescription": "" ])
                                     
         } else {
             
@@ -203,12 +204,13 @@ import Foundation
     @objc func uploadedFile(_ notification: NSNotification) {
     
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String {
-                                                
-                if metadata.account == appDelegate.account {
-                    if errorCode != 0 {
-                        if errorCode != -999 && errorCode != 401 && errorDescription != "" {
-                            NCContentPresenter.shared.messageNotification("_upload_file_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
+            if let ocId = userInfo["ocId"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if metadata.account == appDelegate.account {
+                        if errorCode != 0 {
+                            if errorCode != -999 && errorCode != 401 && errorDescription != "" {
+                                NCContentPresenter.shared.messageNotification("_upload_file_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                            }
                         }
                     }
                 }

+ 49 - 45
iOSClient/Transfers/NCTransfers.swift

@@ -85,15 +85,16 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata {
-
-                if let row = dataSource.addMetadata(metadata) {
-                    let indexPath = IndexPath(row: row, section: 0)
-                    collectionView?.performBatchUpdates({
-                        collectionView?.insertItems(at: [indexPath])
-                    }, completion: { (_) in
-                        self.reloadDataSource()
-                    })
+            if let ocId = userInfo["ocId"] as? String {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if let row = dataSource.addMetadata(metadata) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.insertItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.reloadDataSource()
+                        })
+                    }
                 }
             }
         }
@@ -103,31 +104,33 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata, let ocIdTemp = userInfo["ocIdTemp"] as? String, let errorCode = userInfo["errorCode"] as? Int {
-                if errorCode == 0 {
-                    
-                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.performBatchUpdates({
-                            collectionView?.deleteItems(at: [indexPath])
-                        }, completion: { (_) in
-                            self.collectionView?.reloadData()
-                        })
-                    } else {
-                        reloadDataSource()
-                    }
-                    
-                } else if errorCode != NSURLErrorCancelled {
-                    
-                    if let row = dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.performBatchUpdates({
-                            collectionView?.reloadItems(at: [indexPath])
-                        }, completion: { (_) in
-                            self.collectionView?.reloadData()
-                        })
-                    } else {
-                        reloadDataSource()
+            if let ocId = userInfo["ocId"] as? String, let ocIdTemp = userInfo["ocIdTemp"] as? String, let errorCode = userInfo["errorCode"] as? Int {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if  errorCode == 0 {
+                        
+                        if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
+                            let indexPath = IndexPath(row: row, section: 0)
+                            collectionView?.performBatchUpdates({
+                                collectionView?.deleteItems(at: [indexPath])
+                            }, completion: { (_) in
+                                self.collectionView?.reloadData()
+                            })
+                        } else {
+                            reloadDataSource()
+                        }
+                        
+                    } else if errorCode != NSURLErrorCancelled {
+                        
+                        if let row = dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp) {
+                            let indexPath = IndexPath(row: row, section: 0)
+                            collectionView?.performBatchUpdates({
+                                collectionView?.reloadItems(at: [indexPath])
+                            }, completion: { (_) in
+                                self.collectionView?.reloadData()
+                            })
+                        } else {
+                            reloadDataSource()
+                        }
                     }
                 }
             }
@@ -138,17 +141,18 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata {
-                    
-                if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
-                    let indexPath = IndexPath(row: row, section: 0)
-                    collectionView?.performBatchUpdates({
-                        collectionView?.deleteItems(at: [indexPath])
-                    }, completion: { (_) in
-                        self.collectionView?.reloadData()
-                    })
-                } else {
-                    self.reloadDataSource()
+            if let ocId = userInfo["ocId"] as? String {
+                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.deleteItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.collectionView?.reloadData()
+                        })
+                    } else {
+                        self.reloadDataSource()
+                    }
                 }
             }
         }

+ 4 - 4
iOSClient/Utility/CCUtility.m

@@ -1404,7 +1404,7 @@
     PHFetchResult *result = [PHAsset fetchAssetsWithLocalIdentifiers:@[metadata.assetLocalIdentifier] options:nil];
     if (!result.count) {
         if (notification) {
-            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadedFile object:nil userInfo:@{@"metadata": metadata, @"errorCode": @(k_CCErrorInternalError), @"errorDescription": @"_err_asset_not_found_"}];
+            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadedFile object:nil userInfo:@{@"ocId": metadata.ocId, @"errorCode": @(k_CCErrorInternalError), @"errorDescription": @"_err_asset_not_found_"}];
         }
         
         completion(nil, nil);
@@ -1432,7 +1432,7 @@
                 
                 if (error) {
                     if (notification) {
-                        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadedFile object:nil userInfo:@{@"metadata": metadata, @"errorCode": @(error.code), @"errorDescription": [NSString stringWithFormat:@"Image request iCloud failed [%@]", error.description]}];
+                        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadedFile object:nil userInfo:@{@"ocId": metadata.ocId, @"errorCode": @(error.code), @"errorDescription": [NSString stringWithFormat:@"Image request iCloud failed [%@]", error.description]}];
                     }
                     
                     completion(nil, nil);
@@ -1491,7 +1491,7 @@
                 
                 if (error) {
                     if (notification) {
-                        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadedFile object:nil userInfo:@{@"metadata": metadata, @"errorCode": @(error.code), @"errorDescription": [NSString stringWithFormat:@"Video request iCloud failed [%@]", error.description]}];
+                        [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadedFile object:nil userInfo:@{@"ocId": metadata.ocId, @"errorCode": @(error.code), @"errorDescription": [NSString stringWithFormat:@"Video request iCloud failed [%@]", error.description]}];
                     }
                     
                     completion(nil, nil);
@@ -1514,7 +1514,7 @@
                         if (error) {
                             
                             if (notification) {
-                                [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadedFile object:nil userInfo:@{@"metadata": metadata, @"errorCode": @(error.code), @"errorDescription": [NSString stringWithFormat:@"Video request iCloud failed [%@]", error.description]}];
+                                [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_uploadedFile object:nil userInfo:@{@"ocId": metadata.ocId, @"errorCode": @(error.code), @"errorDescription": [NSString stringWithFormat:@"Video request iCloud failed [%@]", error.description]}];
                             }
                             
                             completion(nil, nil);