Przeglądaj źródła

replace old readFile in NCNetworkingSync

Marino Faggiana 7 lat temu
rodzic
commit
dad2069fd5

+ 14 - 19
iOSClient/Actions/CCActions.swift

@@ -205,29 +205,24 @@ class CCActions: NSObject {
             return
         }
         
-        DispatchQueue.global(qos: .userInitiated).async {
+        // Verify if exists the fileName TO
         
-            // Verify if exists the fileName TO
-            var items: NSArray?
-        
-            guard NCNetworkingSync.sharedManager().readFile("\(String(describing: serverUrl))/\(fileName)", user: self.appDelegate.activeUser, userID: self.appDelegate.activeUserID, password: self.appDelegate.activePassword, items: &items) != nil else {
+        let ocNetworking = OCnetworking.init(delegate: nil, metadataNet: nil, withUser: self.appDelegate.activeUser, withUserID: self.appDelegate.activeUserID, withPassword: self.appDelegate.activePassword, withUrl: self.appDelegate.activeUrl)
+
+        ocNetworking?.readFile(withServerUrl: serverUrl, fileName: fileName, account: self.appDelegate.activeAccount, success: { (metadata) in
                 
-                DispatchQueue.main.async {
-                    
-                    let alertController = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_file_already_exists_", comment: ""), preferredStyle: UIAlertControllerStyle.alert)
+            let alertController = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_file_already_exists_", comment: ""), preferredStyle: UIAlertControllerStyle.alert)
                 
-                    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
-                        (result : UIAlertAction) -> Void in
-                    }
+            let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
+                (result : UIAlertAction) -> Void in
+            }
                 
-                    alertController.addAction(okAction)
+            alertController.addAction(okAction)
                 
-                    delegate.present(alertController, animated: true, completion: nil)
-                }
+            delegate.present(alertController, animated: true, completion: nil)
+                
+        }, failure: { (message, errorCode) in
                 
-                return;
-            }
-        
             metadataNet.action = actionMoveFileOrFolder
             metadataNet.delegate = delegate
             metadataNet.fileID = metadata.fileID
@@ -237,9 +232,9 @@ class CCActions: NSObject {
             metadataNet.selector = selectorRename
             metadataNet.serverUrl = serverUrl
             metadataNet.serverUrlTo = serverUrl
-            
+                
             self.appDelegate.addNetworkingOperationQueue(self.appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
-        }
+        })
     }
     
     @objc func renameSuccess(_ metadataNet: CCMetadataNet) {

+ 56 - 69
iOSClient/Login/CCLogin.m

@@ -363,71 +363,6 @@
     }
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark == Login ==
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)loginCloudUrl:(NSString *)url user:(NSString *)user password:(NSString *)password
-{
-    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:self metadataNet:nil withUser:user withUserID:user withPassword:password withUrl:nil];
-    
-    dispatch_async(dispatch_get_main_queue(), ^{
-        self.login.enabled = NO;
-        self.loadingBaseUrl.hidden = NO;
-    });
-    
-    [ocNetworking checkServer:[NSString stringWithFormat:@"%@%@", url, webDAV] success:^{
-        
-        // account
-        NSString *account = [NSString stringWithFormat:@"%@ %@", user, url];
-        
-        if (_loginType == loginModifyPasswordUser) {
-            
-            // Change Password
-            tableAccount *tbAccount = [[NCManageDatabase sharedInstance] setAccountPassword:account password:password];
-            
-            // Setting appDelegate active account
-            [appDelegate settingActiveAccount:tbAccount.account activeUrl:tbAccount.url activeUser:tbAccount.user activeUserID:tbAccount.userID activePassword:tbAccount.password];
-            
-            [self.delegate loginSuccess:_loginType];
-            
-            [self dismissViewControllerAnimated:YES completion:nil];
-            
-        } else {
-            
-            [[NCManageDatabase sharedInstance] deleteAccount:account];
-            [[NCManageDatabase sharedInstance] addAccount:account url:url user:user password:password loginFlow:false];
-            
-            tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:account];
-            
-            // Setting appDelegate active account
-            [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:tableAccount.password];
-            
-            [self.delegate loginSuccess:_loginType];
-            
-            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-                [self dismissViewControllerAnimated:YES completion:nil];
-            });
-        }
-                
-    } failure:^(NSString *message, NSInteger errorCode) {
-        
-        if (errorCode != NSURLErrorServerCertificateUntrusted) {
-            
-            NSString *messageAlert = [NSString stringWithFormat:@"%@.\n%@", NSLocalizedStringFromTable(@"_not_possible_connect_to_server_", @"Error", nil), message];
-            
-            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:messageAlert preferredStyle:UIAlertControllerStyleAlert];
-            UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-            
-            [alertController addAction:okAction];
-            [self presentViewController:alertController animated:YES completion:nil];
-        }
-        
-        self.login.enabled = YES;
-        self.loadingBaseUrl.hidden = YES;
-    }];
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark == TextField ==
 #pragma --------------------------------------------------------------------------------------------
@@ -495,10 +430,62 @@
         NSString *url = self.baseUrl.text;
         NSString *user = self.user.text;
         NSString *password = self.password.text;
-        
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-            [self loginCloudUrl:url user:user password:password];
-        });
+        OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:self metadataNet:nil withUser:user withUserID:user withPassword:password withUrl:nil];
+
+        self.login.enabled = NO;
+        self.loadingBaseUrl.hidden = NO;
+
+        [ocNetworking checkServer:[NSString stringWithFormat:@"%@%@", url, webDAV] success:^{
+            
+            // account
+            NSString *account = [NSString stringWithFormat:@"%@ %@", user, url];
+            
+            if (_loginType == loginModifyPasswordUser) {
+                
+                // Change Password
+                tableAccount *tbAccount = [[NCManageDatabase sharedInstance] setAccountPassword:account password:password];
+                
+                // Setting appDelegate active account
+                [appDelegate settingActiveAccount:tbAccount.account activeUrl:tbAccount.url activeUser:tbAccount.user activeUserID:tbAccount.userID activePassword:tbAccount.password];
+                
+                [self.delegate loginSuccess:_loginType];
+                
+                [self dismissViewControllerAnimated:YES completion:nil];
+                
+            } else {
+                
+                [[NCManageDatabase sharedInstance] deleteAccount:account];
+                [[NCManageDatabase sharedInstance] addAccount:account url:url user:user password:password loginFlow:false];
+                
+                tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:account];
+                
+                // Setting appDelegate active account
+                [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:tableAccount.password];
+                
+                [self.delegate loginSuccess:_loginType];
+                
+                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+                    [self dismissViewControllerAnimated:YES completion:nil];
+                });
+            }
+            
+        } failure:^(NSString *message, NSInteger errorCode) {
+            
+            if (errorCode != NSURLErrorServerCertificateUntrusted) {
+                
+                NSString *messageAlert = [NSString stringWithFormat:@"%@.\n%@", NSLocalizedStringFromTable(@"_not_possible_connect_to_server_", @"Error", nil), message];
+                
+                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:messageAlert preferredStyle:UIAlertControllerStyleAlert];
+                UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+                
+                [alertController addAction:okAction];
+                [self presentViewController:alertController animated:YES completion:nil];
+            }
+            
+            self.login.enabled = YES;
+            self.loadingBaseUrl.hidden = YES;
+        }];
+
     }
 }
 

+ 21 - 31
iOSClient/Main/CCMain.m

@@ -1987,32 +1987,24 @@
     NSString *directoryIDTo = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrlTo];
     if (!directoryIDTo) return;
     
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-        
-        NSArray *items;
+    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
 
-        NSError *error = [[NCNetworkingSync sharedManager] readFile:[NSString stringWithFormat:@"%@/%@", serverUrlTo, metadata.fileName] user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword items:&items];
+    [ocNetworking readFileWithServerUrl:serverUrlTo fileName:metadata.fileName account:appDelegate.activeAccount success:^(tableMetadata *metadata) {
+    
+        UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
+        }];
+        [alert addAction:ok];
+        [self presentViewController:alert animated:YES completion:nil];
+        
+        // End Select Table View
+        [self tableViewSelect:NO];
+        
+        // reload Datasource
+        [self readFileReloadFolder];
+        
+    } failure:^(NSString *message, NSInteger errorCode) {
     
-        if(!error) {
-                
-            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-                    
-                UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
-                UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
-                }];
-                [alert addAction:ok];
-                [self presentViewController:alert animated:YES completion:nil];
-            
-                // End Select Table View
-                [self tableViewSelect:NO];
-            
-                // reload Datasource
-                [self readFileReloadFolder];
-            });
-            
-            return;
-        }
-            
         CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
         
         metadataNet.action = actionMoveFileOrFolder;
@@ -2027,15 +2019,13 @@
         metadataNet.selector = selectorMove;
         metadataNet.serverUrl = serverUrl;
         metadataNet.serverUrlTo = serverUrlTo;
-            
+        
         [_queueSelector addObject:metadataNet.selector];
-            
+        
         [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
-    
-        dispatch_async(dispatch_get_main_queue(), ^{
-            [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
-        });
-    });
+        
+        [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
+    }];
 }
 
 // DELEGATE : Move

+ 0 - 2
iOSClient/Networking/NCNetworkingSync.h

@@ -13,8 +13,6 @@
 
 + (NCNetworkingSync *)sharedManager;
 
-- (NSError *)readFile:(NSString *)filePathName user:(NSString *)user userID:(NSString *)userID password:(NSString *)password items:(NSArray **)items;
-- (NSError *)readFolder:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password items:(NSArray **)items;
 - (NSError *)createFolder:(NSString *)folderPathName user:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url encrypted:(BOOL)encrypted fileID:(NSString **)fileID;
 
 // ===== End-to-End Encryption =====

+ 0 - 61
iOSClient/Networking/NCNetworkingSync.m

@@ -37,67 +37,6 @@
 #pragma mark ============================
 #pragma --------------------------------------------------------------------------------------------
 
-- (NSError *)readFile:(NSString *)filePathName user:(NSString *)user userID:(NSString *)userID password:(NSString *)password items:(NSArray  **)items
-{
-    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
-    
-    __block NSError *returnError = nil;
-    __block NSArray *returnItems = nil;
-    
-    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
-    
-    [communication setCredentialsWithUser: user andUserID: userID andPassword: password];
-    [communication setUserAgent:[CCUtility getUserAgent]];
-    
-    [communication readFile:filePathName onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer) {
-        
-        returnItems = items;
-        dispatch_semaphore_signal(semaphore);
-        
-    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
-        
-        returnError = [self getError:response error:error descriptionDefault:@"_error_"];
-        dispatch_semaphore_signal(semaphore);
-    }];
-    
-    while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
-        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
-    
-    *items = returnItems;
-    return returnError;
-}
-
-- (NSError *)readFolder:(NSString *)serverUrl user:(NSString *)user userID:(NSString *)userID password:(NSString *)password items:(NSArray  **)items
-{
-    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
-
-    __block NSError *returnError = nil;
-    __block NSArray *returnItems = nil;
-    
-    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
-    
-    [communication setCredentialsWithUser:user andUserID:userID andPassword:password];
-    [communication setUserAgent:[CCUtility getUserAgent]];
-    
-    [communication readFolder:serverUrl depth:0 withUserSessionToken:nil onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token) {
-        
-        returnItems = items;
-        dispatch_semaphore_signal(semaphore);
-
-    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer) {
-
-        returnError = [self getError:response error:error descriptionDefault:@"_error_"];
-        dispatch_semaphore_signal(semaphore);
-
-    }];
-    
-    while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER))
-        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
-    
-    *items = returnItems;
-    return returnError;
-}
-
 - (NSError *)createFolder:(NSString *)folderPathName user:(NSString *)user userID:(NSString *)userID password:(NSString *)password url:(NSString *)url encrypted:(BOOL)encrypted fileID:(NSString **)fileID
 {
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;

+ 1 - 0
iOSClient/Networking/OCNetworking.h

@@ -47,6 +47,7 @@
 - (NSURLSessionTask *)uploadFileNameServerUrl:(NSString *)fileNameServerUrl fileNameLocalPath:(NSString *)fileNameLocalPath communication:(OCCommunication *)communication success:(void(^)(NSString *fileID, NSString *etag, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 - (void)downloadThumbnailWithDimOfThumbnail:(NSString *)dimOfThumbnail fileName:(NSString *)fileName fileNameLocal:(NSString *)fileNameLocal success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 - (void)readFolderWithServerUrl:(NSString *)serverUrl depth:(NSString *)depth account:(NSString *)account success:(void(^)(NSArray *metadatas, tableMetadata *metadataFolder, NSString *directoryID))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
+- (void)readFileWithServerUrl:(NSString *)serverUrl fileName:(NSString *)fileName account:(NSString *)account success:(void(^)(tableMetadata *metadata))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 - (void)deleteFileOrFolder:(NSString *)fileName serverUrl:(NSString *)serverUrl success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 - (void)createFolder:(NSString *)fileName serverUrl:(NSString *)serverUrl account:(NSString *)account success:(void(^)(NSString *fileID, NSDate *date))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 - (void)moveFileOrFolder:(NSString *)fileName fileNameTo:(NSString *)fileNameTo success:(void (^)(void))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;

+ 104 - 1
iOSClient/Networking/OCNetworking.m

@@ -1238,7 +1238,7 @@
 
 - (void)readFile
 {
-    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+    /*OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
     
     NSString *fileName;
     
@@ -1331,6 +1331,109 @@
         
         [self complete];
     }];
+    */
+    [self readFileWithServerUrl:_metadataNet.serverUrl fileName:_metadataNet.fileName account:_metadataNet.account success:^(tableMetadata *metadata) {
+        
+        if([self.delegate respondsToSelector:@selector(readFileSuccessFailure:metadata:message:errorCode:)])
+            [self.delegate readFileSuccessFailure:_metadataNet metadata:metadata message:nil errorCode:0];
+        
+        [self complete];
+
+    } failure:^(NSString *message, NSInteger errorCode) {
+        
+         if ([self.delegate respondsToSelector:@selector(readFileSuccessFailure:metadata:message:errorCode:)])
+             [self.delegate readFileSuccessFailure:_metadataNet metadata:nil message:message errorCode:errorCode];
+
+        [self complete];
+
+    }];
+}
+
+- (void)readFileWithServerUrl:(NSString *)serverUrl fileName:(NSString *)fileName account:(NSString *)account success:(void(^)(tableMetadata *metadata))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
+{
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+ 
+    if (fileName) {
+        fileName = [NSString stringWithFormat:@"%@/%@", serverUrl, fileName];
+    } else {
+        fileName = @".";
+        fileName = serverUrl;
+    }
+    
+    [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
+    [communication setUserAgent:[CCUtility getUserAgent]];
+    
+    [communication readFile:fileName onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer) {
+        
+        // Test active account
+        tableAccount *recordAccount = [[NCManageDatabase sharedInstance] getAccountActive];
+        if (![recordAccount.account isEqualToString:account]) {
+            
+            failure(NSLocalizedStringFromTable(@"_error_user_not_available_", @"Error", nil), k_CCErrorUserNotAvailble);
+            
+        } else {
+            
+            BOOL isFolderEncrypted = [CCUtility isFolderEncrypted:serverUrl account:account];
+
+            if ([items count] > 0) {
+                
+                tableMetadata *metadata = [tableMetadata new];
+                
+                OCFileDto *itemDto = [items objectAtIndex:0];
+                
+                NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
+                if (directoryID) {
+                    
+                    NSString *autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
+                    NSString *autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:_activeUrl];
+                    
+                    NSString *directoryUser = [CCUtility getDirectoryActiveUser:_activeUser activeUrl:_activeUrl];
+                    
+                    metadata = [CCUtility trasformedOCFileToCCMetadata:itemDto fileName:fileName serverUrl:serverUrl directoryID:directoryID autoUploadFileName:autoUploadFileName autoUploadDirectory:autoUploadDirectory activeAccount:account directoryUser:directoryUser isFolderEncrypted:isFolderEncrypted];
+                    
+                    success(metadata);
+                    
+                } else {
+                    
+                    failure(NSLocalizedStringFromTable(@"Directory not found", @"Error", nil), k_CCErrorInternalError);
+                }
+            }
+            
+            // BUG 1038 item == 0
+            else {
+                
+#ifndef EXTENSION
+                AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
+                
+                [appDelegate messageNotification:@"Server error" description:@"Read File WebDAV : [items NULL] please fix" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
+#endif
+                failure(NSLocalizedStringFromTable(@"Read File WebDAV : [items NULL] please fix", @"Error", nil), k_CCErrorInternalError);
+            }
+        }
+        
+    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
+        
+        NSString *message;
+        
+        NSInteger errorCode = response.statusCode;
+        if (errorCode == 0 || (errorCode >= 200 && errorCode < 300))
+            errorCode = error.code;
+        
+        // Error
+        if (errorCode == 503)
+            message = NSLocalizedStringFromTable(@"_server_error_retry_", @"Error", nil);
+        else
+            message = [error.userInfo valueForKey:@"NSLocalizedDescription"];
+        
+        // Request trusted certificated
+        if ([error code] == NSURLErrorServerCertificateUntrusted)
+            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:(UIViewController *)self.delegate delegate:self];
+        
+        // Activity
+        [[NCManageDatabase sharedInstance] addActivityClient:serverUrl fileID:@"" action:k_activityDebugActionReadFolder selector:@"" note:[error.userInfo valueForKey:@"NSLocalizedDescription"] type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:_activeUrl];
+        
+        failure(message, errorCode);
+    }];
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 12 - 19
iOSClient/Photos/CCPhotos.m

@@ -666,30 +666,23 @@
     // account.dateSearchContentTypeImageVideo
     
     NSString *startDirectory = [[NCManageDatabase sharedInstance] getAccountStartDirectoryPhotosTab:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]];
-
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-        
-        NSArray *items;
-        NSError *error = [[NCNetworkingSync sharedManager] readFile:startDirectory user:appDelegate.activeUser userID:appDelegate.activeUserID password:appDelegate.activePassword items:&items];
-        
-        if (error == nil && items.count > 0) {
+    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:self metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
+    
+    [ocNetworking readFileWithServerUrl:startDirectory fileName:nil account:appDelegate.activeAccount success:^(tableMetadata *metadata) {
         
-            OCFileDto *fileStartDirectory = items[0];
+        if (![metadata.etag isEqualToString:[_saveEtagForStartDirectory objectForKey:startDirectory]]) {
+            
+            [[CCActions sharedInstance] search:startDirectory fileName:@"" etag:metadata.etag depth:@"infinity" date:[NSDate distantPast] contenType:@[@"image/%", @"video/%"] selector:selectorSearchContentType delegate:self];
+            [self searchInProgress:YES];
+            [self editingModeNO];
             
-            if (![fileStartDirectory.etag isEqualToString:[_saveEtagForStartDirectory objectForKey:startDirectory]]) {
-                
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    [[CCActions sharedInstance] search:startDirectory fileName:@"" etag:fileStartDirectory.etag depth:@"infinity" date:[NSDate distantPast] contenType:@[@"image/%", @"video/%"] selector:selectorSearchContentType delegate:self];
-                    [self searchInProgress:YES];
-                    [self editingModeNO];
-                });
-            } else {
-                [self reloadDatasourceFromSearch:YES];
-            }
         } else {
             [self reloadDatasourceFromSearch:YES];
         }
-    });
+        
+    } failure:^(NSString *message, NSInteger errorCode) {
+        [self reloadDatasourceFromSearch:YES];
+    }];
 }
 
 #pragma --------------------------------------------------------------------------------------------