marinofaggiana 5 жил өмнө
parent
commit
b8a7f1f2a8

+ 1 - 1
iOSClient/AppDelegate.h

@@ -106,8 +106,8 @@
 
 @property (nonatomic, strong) NSMutableDictionary *listMainVC;
 @property (nonatomic, strong) NSMutableDictionary *listProgressMetadata;
-
 @property (nonatomic, strong) NSMutableArray *filterocId;
+@property (nonatomic, strong) NSMutableArray *arrayDeleteMetadata;
 
 @property (nonatomic) UIUserInterfaceStyle preferredUserInterfaceStyle API_AVAILABLE(ios(12.0));
 

+ 23 - 1
iOSClient/AppDelegate.m

@@ -80,9 +80,10 @@
     // Background Fetch
     [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
 
-    // Initialization List
+    // Initialization List & Array
     self.listProgressMetadata = [[NSMutableDictionary alloc] init];
     self.listMainVC = [[NSMutableDictionary alloc] init];
+    self.arrayDeleteMetadata = [NSMutableArray new];
     
     // Push Notification
     [application registerForRemoteNotifications];
@@ -176,6 +177,9 @@
     // init home
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_initializeMain object:nil userInfo:nil];
     
+    // Observer
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteFile:) name:k_notificationCenter_deleteFile object:nil];
+
     return YES;
 }
 
@@ -646,6 +650,24 @@
     return [token copy];
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ==== NotificationCenter ====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)deleteFile:(NSNotification *)notification
+{
+    if (self.arrayDeleteMetadata.count > 0) {
+        tableMetadata *metadata = self.arrayDeleteMetadata.firstObject;
+        [self.arrayDeleteMetadata removeObjectAtIndex:0];
+        tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", metadata.account]];
+        if (account) {
+            [[NCNetworking sharedInstance] deleteMetadata:metadata user:account.user userID:account.userID password:[CCUtility getPassword:metadata.account] url:account.url completion:^(NSInteger errorCode, NSString *errorDescription) { }];
+        } else {
+            [self deleteFile:[NSNotification new]];
+        }
+    }
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Quick Actions - ShotcutItem =====
 #pragma --------------------------------------------------------------------------------------------

+ 2 - 0
iOSClient/Favorites/CCFavorites.m

@@ -127,6 +127,8 @@
 
 - (void)deleteFile:(NSNotification *)notification
 {
+    if (self.view.window == nil) { return; }
+
     NSDictionary *userInfo = notification.userInfo;
     tableMetadata *metadata = userInfo[@"metadata"];
     if (metadata) {

+ 8 - 8
iOSClient/Main/CCMain.m

@@ -435,10 +435,12 @@
 
 - (void)deleteFile:(NSNotification *)notification
 {
+    if (self.view.window == nil) { return; }
+    
     NSDictionary *userInfo = notification.userInfo;
     tableMetadata *metadata = userInfo[@"metadata"];
+    
     if ([metadata.serverUrl isEqualToString:self.serverUrl]) {
-        
         if ([metadata.fileNameView.lowercaseString isEqualToString:k_fileNameRichWorkspace.lowercaseString]) {
             [self readFileReloadFolder];
         } else {
@@ -1435,20 +1437,18 @@
     if (_isSelectedMode && [_selectedocIdsMetadatas count] == 0)
         return;
      
-    NSArray *metadatas;
     if ([_selectedocIdsMetadatas count] > 0) {
-        metadatas = [_selectedocIdsMetadatas allValues];
+        [appDelegate.arrayDeleteMetadata addObjectsFromArray:[_selectedocIdsMetadatas allValues]];
     } else {
-        metadatas = [[NSArray alloc] initWithObjects:self.metadata, nil];
+        [appDelegate.arrayDeleteMetadata addObject:self.metadata];
     }
     
+    [[NCNetworking sharedInstance] deleteMetadata:appDelegate.arrayDeleteMetadata.firstObject user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl completion:^(NSInteger errorCode, NSString *errorDescription) { }];
+    [appDelegate.arrayDeleteMetadata removeObjectAtIndex:0];
+    
     // remove optimization
     _dateReadDataSource = nil;
     
-    for (tableMetadata *metadata in metadatas) {
-        [[NCNetworking sharedInstance] deleteMetadata:metadata user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword url:appDelegate.activeUrl completion:^(NSInteger errorCode, NSString *errorDescription) { }];
-    }
-
     // End Select Table View
     [self tableViewSelect:false];
 }

+ 0 - 116
iOSClient/Main/NCMainCommon.swift

@@ -936,122 +936,6 @@ class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewController
         return true
     }
     
-    //MARK: -
-    /*
-    @objc func deleteFile(metadatas: NSArray, e2ee: Bool, serverUrl: String, folderocId: String, completion: @escaping (_ errorCode: Int, _ message: String)->()) {
-        
-        var copyMetadatas = [tableMetadata]()
-        
-        for metadata in metadatas {
-            copyMetadatas.append(tableMetadata.init(value: metadata))
-        }
-        
-        if e2ee {
-            DispatchQueue.global().async {
-                let error = NCNetworkingEndToEnd.sharedManager().lockFolderEncrypted(onServerUrl: serverUrl, ocId: folderocId, user: self.appDelegate.activeUser, userID: self.appDelegate.activeUserID, password: self.appDelegate.activePassword, url: self.appDelegate.activeUrl)
-                DispatchQueue.main.async {
-                    if error == nil {
-                        self.delete(metadatas: copyMetadatas, serverUrl:serverUrl, e2ee: e2ee, completion: completion)
-                    } else {
-                        NCContentPresenter.shared.messageNotification("_delete_", description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
-                        return
-                    }
-                }
-            }
-        } else {
-            delete(metadatas: copyMetadatas, serverUrl: serverUrl, e2ee: e2ee) { (errorCode, message) in
-                if errorCode != 0 {
-                    NCContentPresenter.shared.messageNotification("_delete_", description: message, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
-                }
-                completion(errorCode, message)
-            }
-        }
-    }
-    
-    private func delete(metadatas: [tableMetadata], serverUrl: String, e2ee: Bool, completion: @escaping (_ errorCode: Int, _ message: String)->()) {
-        
-        var count: Int = 0
-        var completionErrorCode: Int = 0
-        var completionMessage = ""
-                
-        for metadata in metadatas {
-            
-            // verify permission
-            let permission = NCUtility.sharedInstance.permissionsContainsString(metadata.permissions, permissions: k_permission_can_delete)
-            if metadata.permissions != "" && permission == false {
-                completion(Int(k_CCErrorInternalError), "_no_permission_delete_file_")
-                return
-            }
-            
-            self.appDelegate.filterocId.add(metadata.ocId)
-            
-            let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
-                   
-            NCCommunication.sharedInstance.deleteFileOrFolder(serverUrlFileName, account: appDelegate.activeAccount) { (account, errorCode, errorDescription) in
-                
-                if account == self.appDelegate.activeAccount {
-                    
-                    count += 1
-
-                    if errorCode == 0 || errorCode == kOCErrorServerPathNotFound {
-                        
-                        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))
-                        
-                        if metadata.directory {
-                            NCManageDatabase.sharedInstance.deleteDirectoryAndSubDirectory(serverUrl: CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName), account: metadata.account)
-                        }
-                        
-                        if (e2ee) {
-                            NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameIdentifier == %@", metadata.account, serverUrl, metadata.fileName))
-                        }
-                        
-                        // Rich Workspace
-                        if metadata.fileNameView.lowercased() == k_fileNameRichWorkspace.lowercased() {
-                            self.appDelegate.activeMain.readFileReloadFolder()
-                        }
-                        
-                        self.appDelegate.filterocId.remove(metadata.ocId)
-                        
-                    } else {
-                        
-                        completionErrorCode = errorCode
-                        completionMessage = ""
-                        if errorDescription != nil {
-                            completionMessage = errorDescription!
-                        }
-                        
-                        self.appDelegate.filterocId.remove(metadata.ocId)
-                    }
-                    
-                    // Message
-                    let userInfo: [String : Any] = ["metadata": metadata, "errorCode": Int(errorCode), "errorDescription": completionMessage]
-                    NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_deleteFile), object: nil, userInfo: userInfo)
-                    
-                    if count == metadatas.count {
-                        if e2ee {
-                            DispatchQueue.global().async {
-                                NCNetworkingEndToEnd.sharedManager().rebuildAndSendMetadata(onServerUrl: serverUrl, account: self.appDelegate.activeAccount, user: self.appDelegate.activeUser, userID: self.appDelegate.activeUserID, password: self.appDelegate.activePassword, url: self.appDelegate.activeUrl)
-                                DispatchQueue.main.async {
-                                    completion(completionErrorCode, completionMessage)
-                                }
-                            }
-                        } else {
-                            completion(completionErrorCode, completionMessage)
-                        }
-                    }
-                }
-            }
-        }
-        
-        self.reloadDatasource(ServerUrl: serverUrl, ocId: nil, action: k_action_NULL)
-    }
-    */
-    
     @objc func editPhoto(_ metadata: tableMetadata, viewController: UIViewController) {
         guard let path = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) else {
             return

+ 7 - 2
iOSClient/Media/NCMedia.swift

@@ -574,12 +574,17 @@ extension NCMedia {
         if (appDelegate.activeAccount == nil || appDelegate.activeAccount.count == 0 || appDelegate.maintenanceMode == true) {
             return
         }
-                
+        
+        // copy in arrayDeleteMetadata
         for ocId in selectocId {
             if let metadata = NCManageDatabase.sharedInstance.getMedia(predicate: NSPredicate(format: "ocId == %@", ocId)) {
-                NCNetworking.sharedInstance.deleteMetadata(metadata, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
+                appDelegate.arrayDeleteMetadata.add(metadata)
             }
         }
+        if let metadata = appDelegate.arrayDeleteMetadata.firstObject {
+            appDelegate.arrayDeleteMetadata.removeObject(at: 0)
+            NCNetworking.sharedInstance.deleteMetadata(metadata as! tableMetadata, user: appDelegate.activeUser, userID: appDelegate.activeUserID, password: appDelegate.activePassword, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
+        }
     }
     
     func search(lteDate: Date, gteDate: Date, addPast: Bool, insertPrevius: Int,setDistantPast: Bool, debug: String) {