Browse Source

listingTrash add account

Marino Faggiana 6 years ago
parent
commit
2f0544da64

+ 1 - 1
iOSClient/Main/CCMain.m

@@ -2081,7 +2081,7 @@
 - (void)openWindowShare:(tableMetadata *)metadata
 {
     OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-    [ocNetworking readShareServerWithAccount:appDelegate.activeAccount completion:^(NSString *account, NSArray *items, NSString *message, NSInteger errorCode) {
+    [ocNetworking readShareWithAccount:appDelegate.activeAccount completion:^(NSString *account, NSArray *items, NSString *message, NSInteger errorCode) {
         
         [_hud hideHud];
         

+ 5 - 5
iOSClient/Networking/NCService.swift

@@ -58,7 +58,7 @@ class NCService: NSObject, OCNetworkingDelegate {
         }
         
         let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
-        ocNetworking?.getCapabilitiesOfServer(appDelegate.activeAccount, completion: { (account, capabilities, message, errorCode) in
+        ocNetworking?.getCapabilitiesWithAccount(appDelegate.activeAccount, completion: { (account, capabilities, message, errorCode) in
             
             if (errorCode == 0 && self.appDelegate.activeAccount == account!) {
                 
@@ -118,7 +118,7 @@ class NCService: NSObject, OCNetworkingDelegate {
                 // Read Notification
                 if (capabilities!.isNotificationServerEnabled) {
                     
-                    ocNetworking?.getNotificationServer(account!, completion: { (account, listOfNotifications, message, errorCode) in
+                    ocNetworking?.getNotificationWithAccount(account!, completion: { (account, listOfNotifications, message, errorCode) in
                         
                         if (errorCode == 0 && account! == self.appDelegate.activeAccount) {
                             
@@ -190,7 +190,7 @@ class NCService: NSObject, OCNetworkingDelegate {
                 // Read External Sites
                 if (capabilities!.isExternalSitesServerEnabled) {
                     
-                    ocNetworking?.getExternalSitesServer(account!, completion: { (account, listOfExternalSites, message, errorCode) in
+                    ocNetworking?.getExternalSites(withAccount: account!, completion: { (account, listOfExternalSites, message, errorCode) in
                         
                         if (errorCode == 0 && account! == self.appDelegate.activeAccount) {
                             
@@ -222,7 +222,7 @@ class NCService: NSObject, OCNetworkingDelegate {
                     
                     self.appDelegate.sharesID.removeAllObjects()
                     
-                    ocNetworking?.readShareServer(withAccount: account!, completion: { (account, items, message, errorCode) in
+                    ocNetworking?.readShare(withAccount: account!, completion: { (account, items, message, errorCode) in
                         
                         if errorCode == 0 && account! == self.appDelegate.activeAccount {
                             
@@ -261,7 +261,7 @@ class NCService: NSObject, OCNetworkingDelegate {
         }
         
         let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
-        ocNetworking?.getUserProfile(appDelegate.activeAccount, completion: { (account, userProfile, message, errorCode) in
+        ocNetworking?.getUserProfile(withAccount: appDelegate.activeAccount, completion: { (account, userProfile, message, errorCode) in
             
             if (errorCode == 0 && account! == self.appDelegate.activeAccount) {
                 

+ 7 - 7
iOSClient/Networking/OCNetworking.h

@@ -67,7 +67,7 @@
 
 - (void)moveFileOrFolderWithAccount:(NSString *)account fileName:(NSString *)fileName fileNameTo:(NSString *)fileNameTo completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
 
-- (void)readShareServerWithAccount:(NSString *)account completion:(void (^)(NSString *account, NSArray *items, NSString *message, NSInteger errorCode))completion;
+- (void)readShareWithAccount:(NSString *)account completion:(void (^)(NSString *account, NSArray *items, NSString *message, NSInteger errorCode))completion;
 
 - (void)settingFavoriteWithAccount:(NSString *)account fileName:(NSString *)fileName favorite:(BOOL)favorite completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
 
@@ -75,15 +75,15 @@
 
 - (void)getActivityWithAccount:(NSString *)account completion:(void(^)(NSString *account, NSArray *listOfActivity, NSString *message, NSInteger errorCode))completion;
 
-- (void)getExternalSitesServer:(NSString *)account completion:(void (^)(NSString *account, NSArray *listOfExternalSites, NSString *message, NSInteger errorCode))completion;
+- (void)getExternalSitesWithAccount:(NSString *)account completion:(void (^)(NSString *account, NSArray *listOfExternalSites, NSString *message, NSInteger errorCode))completion;
 
-- (void)getCapabilitiesOfServer:(NSString *)account completion:(void (^)(NSString *account, OCCapabilities *capabilities, NSString *message, NSInteger errorCode))completion;
+- (void)getCapabilitiesWithAccount:(NSString *)account completion:(void (^)(NSString *account, OCCapabilities *capabilities, NSString *message, NSInteger errorCode))completion;
 
-- (void)getNotificationServer:(NSString *)account completion:(void (^)(NSString *account, NSArray *listOfNotifications, NSString *message, NSInteger errorCode))completion;
+- (void)getNotificationWithAccount:(NSString *)account completion:(void (^)(NSString *account, NSArray *listOfNotifications, NSString *message, NSInteger errorCode))completion;
 
-- (void)setNotificationServer:(NSString *)account serverUrl:(NSString *)serverUrl type:(NSString *)type completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
+- (void)setNotificationWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl type:(NSString *)type completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
 
-- (void)getUserProfile:(NSString *)account completion:(void (^)(NSString *account, OCUserProfile *userProfile, NSString *message, NSInteger errorCode))completion;
+- (void)getUserProfileWithAccount:(NSString *)account completion:(void (^)(NSString *account, OCUserProfile *userProfile, NSString *message, NSInteger errorCode))completion;
 
 - (void)subscribingPushNotificationServer:(NSString *)url pushToken:(NSString *)pushToken Hash:(NSString *)pushTokenHash devicePublicKey:(NSString *)devicePublicKey success:(void(^)(NSString *deviceIdentifier, NSString *deviceIdentifierSignature, NSString *publicKey))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 
@@ -97,7 +97,7 @@
 
 - (void)createAssetRichdocumentsWithFileName:(NSString *)fileName serverUrl:(NSString *)serverUrl success:(void(^)(NSString *link))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 
-- (void)listingTrash:(NSString *)serverUrl path:(NSString *)path account:(NSString *)account success:(void(^)(NSArray *items))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
+- (void)listingTrashWithAccount:(NSString *)account path:(NSString *)path serverUrl:(NSString *)serverUrl completion:(void (^)(NSString *account, NSArray *items, NSString *message, NSInteger errorCode))completion;
 
 - (void)emptyTrash:(void (^)(NSString *message, NSInteger errorCode))completion;
 

+ 42 - 46
iOSClient/Networking/OCNetworking.m

@@ -1122,7 +1122,7 @@
 #pragma mark ===== Shared =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)readShareServerWithAccount:(NSString *)account completion:(void (^)(NSString *account, NSArray *items, NSString *message, NSInteger errorCode))completion
+- (void)readShareWithAccount:(NSString *)account completion:(void (^)(NSString *account, NSArray *items, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -1507,7 +1507,7 @@
 #pragma mark ===== External Sites =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)getExternalSitesServer:(NSString *)account completion:(void (^)(NSString *account, NSArray *listOfExternalSites, NSString *message, NSInteger errorCode))completion
+- (void)getExternalSitesWithAccount:(NSString *)account completion:(void (^)(NSString *account, NSArray *listOfExternalSites, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -1590,7 +1590,7 @@
 #pragma mark ===== Notification =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)getNotificationServer:(NSString *)account completion:(void (^)(NSString *account, NSArray *listOfNotifications, NSString *message, NSInteger errorCode))completion
+- (void)getNotificationWithAccount:(NSString *)account completion:(void (^)(NSString *account, NSArray *listOfNotifications, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -1631,7 +1631,7 @@
     }];
 }
 
-- (void)setNotificationServer:(NSString *)account serverUrl:(NSString *)serverUrl type:(NSString *)type completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
+- (void)setNotificationWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl type:(NSString *)type completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -1794,7 +1794,7 @@
 #pragma mark =====  User Profile =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)getUserProfile:(NSString *)account completion:(void (^)(NSString *account, OCUserProfile *userProfile, NSString *message, NSInteger errorCode))completion
+- (void)getUserProfileWithAccount:(NSString *)account completion:(void (^)(NSString *account, OCUserProfile *userProfile, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -1836,7 +1836,7 @@
 #pragma mark ===== Capabilities =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)getCapabilitiesOfServer:(NSString *)account completion:(void (^)(NSString *account, OCCapabilities *capabilities, NSString *message, NSInteger errorCode))completion
+- (void)getCapabilitiesWithAccount:(NSString *)account completion:(void (^)(NSString *account, OCCapabilities *capabilities, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
@@ -2259,64 +2259,60 @@
 #pragma mark =====  Trash =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)listingTrash:(NSString *)serverUrl path:(NSString *)path account:(NSString *)account success:(void(^)(NSArray *items))success failure:(void (^)(NSString *message, NSInteger errorCode))failure
+- (void)listingTrashWithAccount:(NSString *)account path:(NSString *)path serverUrl:(NSString *)serverUrl completion:(void (^)(NSString *account, NSArray *items, NSString *message, NSInteger errorCode))completion
 {
+    tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
+    if (tableAccount == nil) {
+        completion(account, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
+    }
+    
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
     
-    [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
+    [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:tableAccount.password];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
     [communication listingTrash:[serverUrl stringByAppendingString:path] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer) {
         
-        // Test active account
-        tableAccount *recordAccount = [[NCManageDatabase sharedInstance] getAccountActive];
-        if (![recordAccount.account isEqualToString:account]) {
-            
-            failure(NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
-            
-        } else {
-            
-            // Check items > 0
-            if ([items count] == 0) {
+        // Check items > 0
+        if ([items count] == 0) {
                 
 #ifndef EXTENSION
-                AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
+            AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
                 
-                [appDelegate messageNotification:@"Server error" description:@"Read Folder WebDAV : [items NULL] please fix" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
+            [appDelegate messageNotification:@"Server error" description:@"Read Folder WebDAV : [items NULL] please fix" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
 #endif
-                failure(NSLocalizedString(@"Read Folder WebDAV : [items NULL] please fix", nil), k_CCErrorInternalError);
+            completion(account, nil, NSLocalizedString(@"Read Folder WebDAV : [items NULL] please fix", nil), k_CCErrorInternalError);
                 
-            } else {
+        } else {
                 
-                NSMutableArray *listTrash = [NSMutableArray new];
+            NSMutableArray *listTrash = [NSMutableArray new];
                 
-                //OCFileDto *itemDtoFolder = [items objectAtIndex:0];
+            //OCFileDto *itemDtoFolder = [items objectAtIndex:0];
 
-                if ([items count] > 1) {
-                    for (NSUInteger i=1; i < [items count]; i++) {
+            if ([items count] > 1) {
+                for (NSUInteger i=1; i < [items count]; i++) {
                         
-                        OCFileDto *itemDto = [items objectAtIndex:i];
-                        tableTrash *trash = [tableTrash new];
+                    OCFileDto *itemDto = [items objectAtIndex:i];
+                    tableTrash *trash = [tableTrash new];
                         
-                        trash.account = account;
-                        trash.date = [NSDate dateWithTimeIntervalSince1970:itemDto.date];
-                        trash.directory = itemDto.isDirectory;
-                        trash.fileID = itemDto.ocId;
-                        trash.fileName = itemDto.fileName;
-                        trash.filePath = itemDto.filePath;
-                        trash.size = itemDto.size;
-                        trash.trashbinFileName = itemDto.trashbinFileName;
-                        trash.trashbinOriginalLocation = itemDto.trashbinOriginalLocation;
-                        trash.trashbinDeletionTime = [NSDate dateWithTimeIntervalSince1970:itemDto.trashbinDeletionTime];
-
-                        [CCUtility insertTypeFileIconName:trash.trashbinFileName metadata:(tableMetadata *)trash];
-
-                        [listTrash addObject:trash];
-                    }
+                    trash.account = account;
+                    trash.date = [NSDate dateWithTimeIntervalSince1970:itemDto.date];
+                    trash.directory = itemDto.isDirectory;
+                    trash.fileID = itemDto.ocId;
+                    trash.fileName = itemDto.fileName;
+                    trash.filePath = itemDto.filePath;
+                    trash.size = itemDto.size;
+                    trash.trashbinFileName = itemDto.trashbinFileName;
+                    trash.trashbinOriginalLocation = itemDto.trashbinOriginalLocation;
+                    trash.trashbinDeletionTime = [NSDate dateWithTimeIntervalSince1970:itemDto.trashbinDeletionTime];
+
+                    [CCUtility insertTypeFileIconName:trash.trashbinFileName metadata:(tableMetadata *)trash];
+
+                    [listTrash addObject:trash];
                 }
-                
-                success(listTrash);
             }
+                
+            completion(account, listTrash, nil, 0);
         }
         
     } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
@@ -2336,7 +2332,7 @@
         // Activity
         [[NCManageDatabase sharedInstance] addActivityClient:_activeUrl fileID:@"" action:k_activityDebugActionUnsubscribingServerPush selector:@"" note:[error.userInfo valueForKey:@"NSLocalizedDescription"] type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:_activeUrl];
         
-        failure(message, errorCode);
+        completion(account, nil,message, errorCode);
     }];
 }
 

+ 2 - 2
iOSClient/Notification/CCNotification.swift

@@ -85,7 +85,7 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
                 tableView.setEditing(false, animated: true)
 
                 let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
-                ocNetworking?.setNotificationServer(self.appDelegate.activeAccount, serverUrl: "\(self.appDelegate.activeUrl!)/\(k_url_acces_remote_notification_api)/\(notification.idNotification)", type: "DELETE", completion: { (account, message, errorCode) in
+                ocNetworking?.setNotificationWithAccount(self.appDelegate.activeAccount, serverUrl: "\(self.appDelegate.activeUrl!)/\(k_url_acces_remote_notification_api)/\(notification.idNotification)", type: "DELETE", completion: { (account, message, errorCode) in
                     
                     if (errorCode == 0 && account! == self.appDelegate.activeAccount) {
                         
@@ -130,7 +130,7 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
                             tableView.setEditing(false, animated: true)
 
                             let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
-                            ocNetworking?.setNotificationServer(self.appDelegate.activeAccount, serverUrl: (actionNotification as! OCNotificationsAction).link, type: (actionNotification as! OCNotificationsAction).type, completion: { (account, message, errorCode) in
+                            ocNetworking?.setNotificationWithAccount(self.appDelegate.activeAccount, serverUrl: (actionNotification as! OCNotificationsAction).link, type: (actionNotification as! OCNotificationsAction).type, completion: { (account, message, errorCode) in
                                 
                                 if (errorCode == 0 && account! == self.appDelegate.activeAccount) {
                                     

+ 10 - 12
iOSClient/Trash/NCTrash.swift

@@ -456,23 +456,21 @@ class NCTrash: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
     
     @objc func loadListingTrash() {
         
-        let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: appDelegate.activeUser, withUserID: appDelegate.activeUserID, withPassword: appDelegate.activePassword, withUrl: appDelegate.activeUrl)
-        
-        ocNetworking?.listingTrash(appDelegate.activeUrl, path:path, account: appDelegate.activeAccount, success: { (item) in
+        let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
+        ocNetworking?.listingTrash(withAccount: appDelegate.activeAccount, path: path, serverUrl: appDelegate.activeUrl, completion: { (account, item, message, errorCode) in
             
             self.refreshControl.endRefreshing()
 
-            NCManageDatabase.sharedInstance.deleteTrash(filePath: self.path, account: self.appDelegate.activeAccount)
-            NCManageDatabase.sharedInstance.addTrashs(item as! [tableTrash])
-            
-            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
-                self.loadDatasource()
+            if (errorCode == 0 && account == self.appDelegate.activeAccount) {
+                
+                NCManageDatabase.sharedInstance.deleteTrash(filePath: self.path, account: self.appDelegate.activeAccount)
+                NCManageDatabase.sharedInstance.addTrashs(item as! [tableTrash])
+                
+            } else if (errorCode != 0) {
+                self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
             }
             
-        }, failure: { (message, errorCode) in
-            
-            self.refreshControl.endRefreshing()
-            print("error " + message!)
+            self.loadDatasource()
         })
     }