marinofaggiana 4 жил өмнө
parent
commit
c3946df928

+ 79 - 97
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -279,21 +279,19 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let onlyLocal = userInfo["onlyLocal"] as? Bool {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if onlyLocal {
-                        reloadDataSource()
-                    } else if metadata.fileNameView.lowercased() == k_fileNameRichWorkspace.lowercased() {
-                        reloadDataSourceNetwork(forced: true)
-                    } else {
-                        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()
-                            })
-                        }
+            if let ocId = userInfo["ocId"] as? String, let onlyLocal = userInfo["onlyLocal"] as? Bool, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId)  {
+                if onlyLocal {
+                    reloadDataSource()
+                } else if metadata.fileNameView.lowercased() == k_fileNameRichWorkspace.lowercased() {
+                    reloadDataSourceNetwork(forced: true)
+                } else {
+                    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()
+                        })
                     }
                 }
             }
@@ -304,26 +302,24 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let ocIdNew = userInfo["ocIdNew"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId), let metadataNew = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdNew) {
-                    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 if metadataNew.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                        if let row = dataSource.addMetadata(metadataNew) {
-                            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, let ocIdNew = userInfo["ocIdNew"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId), let metadataNew = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdNew) {
+                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 if metadataNew.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                    if let row = dataSource.addMetadata(metadataNew) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.insertItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.collectionView?.reloadData()
+                        })
                     }
                 }
             }
@@ -352,17 +348,15 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            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()
-                            })
-                        }
+            if let ocId = userInfo["ocId"] as? String, 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()
+                        })
                     }
                 }
             }
@@ -387,12 +381,10 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            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])
-                    }
+            if let ocId = userInfo["ocId"] as? String, 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])
                 }
             }
         }
@@ -402,13 +394,11 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            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])
-                   }
-                }
+            if let ocId = userInfo["ocId"] as? String, let _ = userInfo["errorCode"] as? Int, 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])
+               }
             }
         }
     }
@@ -417,12 +407,10 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            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])
-                    }
+            if let ocId = userInfo["ocId"] as? String, 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,18 +420,16 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            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()
-                            })
-                        }
+            if let ocId = userInfo["ocId"] as? String, 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()
+                        })
                     }
                 }
             }
@@ -454,12 +440,10 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            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()
-                    }
+            if let ocId = userInfo["ocId"] as? String, let ocIdTemp = userInfo["ocIdTemp"] as? String, let _ = userInfo["errorCode"] as? Int, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId)  {
+                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                    dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp)
+                    collectionView?.reloadData()
                 }
             }
         }
@@ -469,20 +453,18 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            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()
-                        }
+            if let ocId = userInfo["ocId"] as? String, 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()
                     }
                 }
             }

+ 68 - 74
iOSClient/Main/NCDetailViewController.swift

@@ -201,29 +201,28 @@ class NCDetailViewController: UIViewController {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let ocIdNew = userInfo["ocIdNew"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId), let metadataNew = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdNew) {
-                    if metadata.account != self.metadata?.account { return }
+            if let ocId = userInfo["ocId"] as? String, let ocIdNew = userInfo["ocIdNew"] as? String,  let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId), let metadataNew = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdNew) {
+                
+                if metadata.account != self.metadata?.account { return }
+                
+                // IMAGE
+                if (metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video || metadata.typeFile == k_metadataTypeFile_audio) {
                     
-                    // IMAGE
-                    if (metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video || metadata.typeFile == k_metadataTypeFile_audio) {
-                        
-                        viewImage()
-                    }
+                    viewImage()
+                }
+                
+                // OTHER
+                if (metadata.typeFile == k_metadataTypeFile_document || metadata.typeFile == k_metadataTypeFile_unknown) && metadataNew.ocId == self.metadata?.ocId {
                     
-                    // OTHER
-                    if (metadata.typeFile == k_metadataTypeFile_document || metadata.typeFile == k_metadataTypeFile_unknown) && metadataNew.ocId == self.metadata?.ocId {
-                        
-                        self.metadata = metadataNew
-                        
-                        // update subview
-                        for view in backgroundView.subviews {
-                            if view is NCViewerNextcloudText {
-                                (view as! NCViewerNextcloudText).metadata = self.metadata
-                            }
-                            else if view is NCViewerRichdocument {
-                                (view as! NCViewerRichdocument).metadata = self.metadata
-                            }
+                    self.metadata = metadataNew
+                    
+                    // update subview
+                    for view in backgroundView.subviews {
+                        if view is NCViewerNextcloudText {
+                            (view as! NCViewerNextcloudText).metadata = self.metadata
+                        }
+                        else if view is NCViewerRichdocument {
+                            (view as! NCViewerRichdocument).metadata = self.metadata
                         }
                     }
                 }
@@ -235,31 +234,30 @@ class NCDetailViewController: UIViewController {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account != self.metadata?.account || metadata.serverUrl != self.metadata?.serverUrl { return }
-                                        
-                    // IMAGE
-                    if (metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video || metadata.typeFile == k_metadataTypeFile_audio) {
-                    
-                        let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
-                        if metadatas.count > 0 {
-                            if self.metadata?.ocId == metadata.ocId {
-                                var index = viewerImageViewController!.index - 1
-                                if index < 0 { index = 0}
-                                self.metadata = metadatas[index]
-                            }
-                            viewImage()
-                        } else {
-                            viewUnload()
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
+                if metadata.account != self.metadata?.account || metadata.serverUrl != self.metadata?.serverUrl { return }
+                                    
+                // IMAGE
+                if (metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video || metadata.typeFile == k_metadataTypeFile_audio) {
+                
+                    let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
+                    if metadatas.count > 0 {
+                        if self.metadata?.ocId == metadata.ocId {
+                            var index = viewerImageViewController!.index - 1
+                            if index < 0 { index = 0}
+                            self.metadata = metadatas[index]
                         }
-                    }
-                    
-                    // OTHER
-                    if (metadata.typeFile == k_metadataTypeFile_document || metadata.typeFile == k_metadataTypeFile_unknown) && metadata.ocId == self.metadata?.ocId {
+                        viewImage()
+                    } else {
                         viewUnload()
                     }
                 }
+                
+                // OTHER
+                if (metadata.typeFile == k_metadataTypeFile_document || metadata.typeFile == k_metadataTypeFile_unknown) && metadata.ocId == self.metadata?.ocId {
+                    viewUnload()
+                }
             }
         }
     }
@@ -268,25 +266,24 @@ class NCDetailViewController: UIViewController {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account != self.metadata?.account || metadata.serverUrl != self.metadata?.serverUrl { return }
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+            
+                if metadata.account != self.metadata?.account || metadata.serverUrl != self.metadata?.serverUrl { return }
+                
+                // IMAGE
+                if (metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video || metadata.typeFile == k_metadataTypeFile_audio) {
                     
-                    // IMAGE
-                    if (metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video || metadata.typeFile == k_metadataTypeFile_audio) {
-                        
-                        viewImage()
-                    }
+                    viewImage()
+                }
+                
+                // OTHER
+                if (metadata.typeFile == k_metadataTypeFile_document || metadata.typeFile == k_metadataTypeFile_unknown) && metadata.ocId == self.metadata?.ocId {
                     
-                    // OTHER
-                    if (metadata.typeFile == k_metadataTypeFile_document || metadata.typeFile == k_metadataTypeFile_unknown) && metadata.ocId == self.metadata?.ocId {
-                        
-                        if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(metadata.ocId) {
-                            self.metadata = metadata
-                            self.navigationController?.navigationBar.topItem?.title = metadata.fileNameView
-                        } else {
-                            viewUnload()
-                        }
+                    if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(metadata.ocId) {
+                        self.metadata = metadata
+                        self.navigationController?.navigationBar.topItem?.title = metadata.fileNameView
+                    } else {
+                        viewUnload()
                     }
                 }
             }
@@ -297,18 +294,17 @@ class NCDetailViewController: UIViewController {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let errorCode = userInfo["errorCode"] as? Int {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account != self.metadata?.account || metadata.serverUrl != self.metadata?.serverUrl { return }
-                    
-                    // IMAGE
-                    if metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video || metadata.typeFile == k_metadataTypeFile_audio && errorCode != 0  {
+            if let ocId = userInfo["ocId"] as? String, let errorCode = userInfo["errorCode"] as? Int, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
 
-                        viewerImageViewController?.reloadContentViews()
-                    }
-                    
-                    progress(0)
+            if metadata.account != self.metadata?.account || metadata.serverUrl != self.metadata?.serverUrl { return }
+                
+                // IMAGE
+                if metadata.typeFile == k_metadataTypeFile_image || metadata.typeFile == k_metadataTypeFile_video || metadata.typeFile == k_metadataTypeFile_audio && errorCode != 0  {
+
+                    viewerImageViewController?.reloadContentViews()
                 }
+                
+                progress(0)
             }
         }
     }
@@ -317,11 +313,9 @@ class NCDetailViewController: UIViewController {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let _ = userInfo["errorCode"] as? Int {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.serverUrl != self.metadata?.serverUrl { return }
-                    progress(0)
-                }
+            if let ocId = userInfo["ocId"] as? String, let _ = userInfo["errorCode"] as? Int, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                if metadata.serverUrl != self.metadata?.serverUrl { return }
+                progress(0)
             }
         }
     }

+ 35 - 37
iOSClient/Media/NCMedia.swift

@@ -397,25 +397,25 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account == appDelegate.account {
-                        
-                        let indexes = self.metadatas.indices.filter { self.metadatas[$0].ocId == metadata.ocId }
-                        let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
-                        self.metadatas = metadatas
-                        
-                        if self.metadatas.count == 0 {
-                            collectionView?.reloadData()
-                        } else if let row = indexes.first {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.deleteItems(at: [indexPath])
-                        }
-                        
-                        self.updateMediaControlVisibility()
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+          
+                if metadata.account == appDelegate.account {
+                    
+                    let indexes = self.metadatas.indices.filter { self.metadatas[$0].ocId == metadata.ocId }
+                    let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
+                    self.metadatas = metadatas
+                    
+                    if self.metadatas.count == 0 {
+                        collectionView?.reloadData()
+                    } else if let row = indexes.first {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.deleteItems(at: [indexPath])
                     }
+                    
+                    self.updateMediaControlVisibility()
                 }
             }
+            
         }
     }
     
@@ -423,25 +423,25 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account == appDelegate.account {
-                        
-                        let indexes = self.metadatas.indices.filter { self.metadatas[$0].ocId == metadata.ocId }
-                        let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
-                        self.metadatas = metadatas
-                        
-                        if self.metadatas.count == 0 {
-                            collectionView?.reloadData()
-                        } else if let row = indexes.first {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.deleteItems(at: [indexPath])
-                        }
-                        
-                        self.updateMediaControlVisibility()
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+     
+                if metadata.account == appDelegate.account {
+                    
+                    let indexes = self.metadatas.indices.filter { self.metadatas[$0].ocId == metadata.ocId }
+                    let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
+                    self.metadatas = metadatas
+                    
+                    if self.metadatas.count == 0 {
+                        collectionView?.reloadData()
+                    } else if let row = indexes.first {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.deleteItems(at: [indexPath])
                     }
+                    
+                    self.updateMediaControlVisibility()
                 }
             }
+            
         }
     }
     
@@ -449,11 +449,9 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account == appDelegate.account {
-                        self.reloadDataSource()
-                    }
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                if metadata.account == appDelegate.account {
+                    self.reloadDataSource()
                 }
             }
         }

+ 95 - 98
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -42,116 +42,115 @@ import Foundation
     @objc func downloadedFile(_ notification: NSNotification) {
             
         if let userInfo = notification.userInfo as NSDictionary? {
-            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 }
+            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, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+            
+                if metadata.account != appDelegate.account { return }
+                
+                if errorCode == 0 {
                     
-                    if errorCode == 0 {
-                        
-                        let fileURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
+                    let fileURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
+                    
+                    switch selector {
+                    case selectorLoadFileQuickLook:
                         
-                        switch selector {
-                        case selectorLoadFileQuickLook:
-                            
-                            let fileNamePath = NSTemporaryDirectory() + metadata.fileNameView
-                            CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: fileNamePath)
+                        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) {
-                                    
-                                    openIn(fileURL: fileURL, selector: selector)
-                                    
-                                } else if metadata.typeFile == k_metadataTypeFile_compress || metadata.typeFile == k_metadataTypeFile_unknown {
-
-                                    openIn(fileURL: fileURL, selector: selector)
-                                    
-                                } else if metadata.typeFile == k_metadataTypeFile_imagemeter {
-                                    
-                                    openIn(fileURL: fileURL, selector: selector)
-                                    
-                                } else {
-                                    
-                                    segueMetadata(metadata)
-                                }
-                            }
-                            
-                        case selectorOpenIn, selectorOpenInDetail:
-                            
-                            if UIApplication.shared.applicationState == UIApplication.State.active {
+                        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) {
                                 
                                 openIn(fileURL: fileURL, selector: selector)
-                            }
-                            
-                        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 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_compress || metadata.typeFile == k_metadataTypeFile_unknown {
+
+                                openIn(fileURL: fileURL, selector: selector)
                                 
-                            } else if metadata.typeFile == k_metadataTypeFile_video && status == PHAuthorizationStatus.authorized {
+                            } else if metadata.typeFile == k_metadataTypeFile_imagemeter {
                                 
-                                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))
-                                }
+                                openIn(fileURL: fileURL, selector: selector)
                                 
-                            } 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))
+                                segueMetadata(metadata)
                             }
-                           
-                        default:
+                        }
+                        
+                    case selectorOpenIn, selectorOpenInDetail:
+                        
+                        if UIApplication.shared.applicationState == UIApplication.State.active {
                             
-                            break
+                            openIn(fileURL: fileURL, selector: selector)
                         }
-                                
-                    } else {
                         
-                        // File do not exists on server, remove in local
-                        if (errorCode == k_CCErrorResourceNotFound || errorCode == k_CCErrorBadServerResponse) {
+                    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 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))
+                            }
                             
-                            do {
-                                try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
-                            } catch { }
+                        } else if metadata.typeFile == k_metadataTypeFile_video && status == PHAuthorizationStatus.authorized {
                             
-                            NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                            NCManageDatabase.sharedInstance.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                            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 {
                             
-                            NCContentPresenter.shared.messageNotification("_download_file_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                            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))
                         }
+                       
+                    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)
                     }
                 }
             }
@@ -227,13 +226,11 @@ import Foundation
     @objc func uploadedFile(_ notification: NSNotification) {
     
         if let userInfo = notification.userInfo as NSDictionary? {
-            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)
-                            }
+            if let ocId = userInfo["ocId"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String, 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)
                         }
                     }
                 }