Marino Faggiana 6 жил өмнө
parent
commit
1e01e50696

+ 3 - 13
iOSClient/Database/NCDatabase.swift

@@ -289,27 +289,17 @@ class tableTag: Object {
     }
 }
 
+/*
 class tableTrash: Object {
     
     @objc dynamic var account = ""
-    @objc dynamic var assetLocalIdentifier = ""
     @objc dynamic var date = NSDate()
     @objc dynamic var directory: Bool = false
-    @objc dynamic var directoryID = ""
-    @objc dynamic var e2eEncrypted: Bool = false
-    @objc dynamic var etag = ""
-    @objc dynamic var favorite: Bool = false
     @objc dynamic var fileID = ""
     @objc dynamic var fileName = ""
-    @objc dynamic var fileNameView = ""
+    @objc dynamic var filePath = ""
     @objc dynamic var iconName = ""
-    @objc dynamic var permissions = ""
-    @objc dynamic var session = ""
-    @objc dynamic var sessionError = ""
-    @objc dynamic var sessionSelector = ""
-    @objc dynamic var sessionTaskIdentifier: Int = 0
     @objc dynamic var size: Double = 0
-    @objc dynamic var status: Int = 0
     @objc dynamic var thumbnailExists: Bool = false
     @objc dynamic var typeFile = ""
     @objc dynamic var trashbinFileName = ""
@@ -320,4 +310,4 @@ class tableTrash: Object {
         return "fileID"
     }
 }
-
+*/

+ 2 - 2
iOSClient/Database/NCManageDatabase.swift

@@ -57,7 +57,7 @@ class NCManageDatabase: NSObject {
         let config = Realm.Configuration(
         
             fileURL: dirGroup?.appendingPathComponent("\(k_appDatabaseNextcloud)/\(k_databaseDefault)"),
-            schemaVersion: 29,
+            schemaVersion: 28,
             
             // 10 : Version 2.18.0
             // 11 : Version 2.18.2
@@ -78,7 +78,7 @@ class NCManageDatabase: NSObject {
             // 26 : Version 2.22.0.4
             // 27 : Version 2.22.0.7
             // 28 : Version 2.22.3.5
-            // 29 : Version 2.23.5.2
+            // 29 : Version 2.22.5.2
             
             migrationBlock: { migration, oldSchemaVersion in
                 // We haven’t migrated anything yet, so oldSchemaVersion == 0

+ 1 - 1
iOSClient/Library/OCCommunicationLib/OCCommunication.h

@@ -953,7 +953,7 @@ typedef enum {
 
 #pragma mark - Trash
 
-- (void)listingTrash:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest;
+- (void)listingTrash:(NSString *)serverUrl path:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest;
 
 @end
 

+ 5 - 4
iOSClient/Library/OCCommunicationLib/OCCommunication.m

@@ -2812,14 +2812,15 @@
 
 #pragma mark - Trash
 
-- (void)listingTrash:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest
+- (void)listingTrash:(NSString *)serverUrl path:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest
 {
-    path = [path encodeString:NSUTF8StringEncoding];
-    
     OCWebDAVClient *request = [OCWebDAVClient new];
     request = [self getRequestWithCredentials:request];
     
-    [request listTrash:path userID:_userID onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
+    NSString *userID = [_userID stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
+    NSString *serverPath = [NSString stringWithFormat:@"%@%@/%@trashbin/%@/trash", serverUrl, k_dav, path, userID];
+    
+    [request listTrash:serverPath onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
         
         OCXMLParser *parser = [OCXMLParser new];
         [parser initParserWithData:responseObject];

+ 1 - 1
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h

@@ -663,6 +663,6 @@ extern NSString * _Nullable OCWebDAVModificationDateKey;
 /// Trash
 ///-----------------------------------
 
-- (void)listTrash:(NSString *)path userID:(NSString *)userID onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response, NSString *token))success failure:(void(^)(NSHTTPURLResponse *response, id  _Nullable responseObject, NSError *, NSString *token))failure;
+- (void)listTrash:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response, NSString *token))success failure:(void(^)(NSHTTPURLResponse *response, id  _Nullable responseObject, NSError *, NSString *token))failure;
 
 @end

+ 3 - 10
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -1208,15 +1208,13 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
 
 #pragma mark - Trash
 
-- (void)listTrash:(NSString *)path userID:(NSString *)userID onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response, NSString *token))success failure:(void(^)(NSHTTPURLResponse *response, id  _Nullable responseObject, NSError *, NSString *token))failure
+- (void)listTrash:(NSString *)path onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response, NSString *token))success failure:(void(^)(NSHTTPURLResponse *response, id  _Nullable responseObject, NSError *, NSString *token))failure
 {
     NSParameterAssert(success);
     
     _requestMethod = @"PROPFIND";
     
-    userID = [userID stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
-
-    NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:[NSString stringWithFormat:@"%@/trashbin/%@/trash", path, userID] parameters:nil timeout:k_timeout_webdav];
+    NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:path parameters:nil timeout:k_timeout_webdav];
     
     NSString *body = [NSString stringWithFormat: @""
                       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
@@ -1224,13 +1222,8 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
                       "<D:prop>"
                       "<D:resourcetype/>"
                       "<D:getlastmodified/>"
-                      "<oc:size/>"
-                      "<oc:favorite/>"
-                      "<oc:fileid/>"
+                      "<id xmlns=\"http://owncloud.org/ns\"/>"
                       "<D:getcontentlength/>"
-                      "<D:getetag/>"
-                      "<oc:permissions/>"
-                      "<nc:is-encrypted/>"
                       "<nc:trashbin-filename/>"
                       "<nc:trashbin-original-location/>"
                       "<nc:trashbin-deletion-time/>"

+ 1 - 1
iOSClient/Networking/OCNetworking.h

@@ -76,7 +76,7 @@
 - (void)createLinkRichdocumentsWithFileID:(NSString *)fileID success:(void(^)(NSString *link))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 - (void)createAssetRichdocumentsWithFileName:(NSString *)fileName serverUrl:(NSString *)serverUrl success:(void(^)(NSString *link))success failure:(void (^)(NSString *message, NSInteger errorCode))failure;
 
-- (void)listingTrash:(void(^)(NSArray *metadatas))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;
 
 @end
 

+ 47 - 6
iOSClient/Networking/OCNetworking.m

@@ -2270,22 +2270,63 @@
 }
 
 #pragma --------------------------------------------------------------------------------------------
-#pragma mark =====  Trash OCS API =====
+#pragma mark =====  Trash =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)listingTrash:(void(^)(NSArray *items))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
 {
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
     
     [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
-    NSString *path = [_activeUrl stringByAppendingString:k_dav];
+    //NSString *path = [_activeUrl stringByAppendingString:k_dav];
 
-    [communication listingTrash:path onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token) {
-        NSLog(@"ok");
+    [communication listingTrash:serverUrl path:path onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer, NSString *token) {
+        
+        // Test active account
+        tableAccount *recordAccount = [[NCManageDatabase sharedInstance] getAccountActive];
+        if (![recordAccount.account isEqualToString:account]) {
+            
+            failure(NSLocalizedStringFromTable(@"_error_user_not_available_", @"Error", nil), k_CCErrorUserNotAvailble);
+            
+        } else {
+            
+            // Check items > 0
+            if ([items count] == 0) {
+                
+#ifndef EXTENSION
+                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];
+#endif
+                failure(NSLocalizedStringFromTable(@"Read Folder WebDAV : [items NULL] please fix", @"Server error", nil), k_CCErrorInternalError);
+                
+            } else {
+                
+               
+              
+            }
+        }
+        
     } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer) {
-        NSLog(@"error");
+        
+        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"];
+        
+        // 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);
     }];
 }
 

+ 2 - 1
iOSClient/Trash/NCTrash.swift

@@ -11,13 +11,14 @@ import Foundation
 class NCTrash: UICollectionViewController {
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    var path = ""
 
     override func viewDidLoad() {
         super.viewDidLoad()
 
         let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: appDelegate.activeUser, withUserID: appDelegate.activeUserID, withPassword: appDelegate.activePassword, withUrl: appDelegate.activeUrl)
         
-        ocNetworking?.listingTrash({ (item) in
+        ocNetworking?.listingTrash(appDelegate.activeUrl, path: path, account: appDelegate.activeAccount, success: { (item) in
             
         }, failure: { (message, errorCode) in