Marino Faggiana 8 жил өмнө
parent
commit
e4278befa1

+ 6 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.h

@@ -466,6 +466,12 @@ typedef enum {
 
 - (void)search:(NSString *)path fileName:(NSString *)fileName depth:(NSString *)depth withUserSessionToken:(NSString *)token 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;
 
+///-----------------------------------
+/// @name Setting favorite
+///-----------------------------------
+
+- (void)settingFavoriteServer:(NSString *)serverPath andFileOrFolderPath:(NSString *)filePath favorite:(BOOL)favorite withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest;
+
 
 #pragma mark - OC API Calls
 

+ 29 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.m

@@ -649,6 +649,35 @@
     }];
 }
 
+///-----------------------------------
+/// @name Setting favorite
+///-----------------------------------
+- (void)settingFavoriteServer:(NSString *)serverPath andFileOrFolderPath:(NSString *)filePath favorite:(BOOL)favorite withUserSessionToken:(NSString *)token onCommunication:(OCCommunication *)sharedOCCommunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer, NSString *token)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer)) failureRequest {
+    
+    if (!token){
+        token = @"no token";
+    }
+    
+    serverPath = [NSString stringWithFormat:@"%@/remote.php/dav/files/%@/%@", serverPath, _user, filePath];
+    serverPath = [serverPath encodeString:NSUTF8StringEncoding];
+    
+    OCWebDAVClient *request = [OCWebDAVClient new];
+    request = [self getRequestWithCredentials:request];
+    
+    [request settingFavorite:serverPath favorite:favorite onCommunication:sharedOCCommunication withUserSessionToken:token success:^(NSHTTPURLResponse *response, id responseObject, NSString *token) {
+        
+        if (successRequest) {
+            //Return success
+            successRequest(response, request.redirectedServer, token);
+        }
+        
+    } failure:^(NSHTTPURLResponse *response, id responseData, NSError *error, NSString *token) {
+        
+        NSLog(@"Failure");
+        failureRequest(response, error, token, request.redirectedServer);
+    }];
+}
+
 #pragma mark - OC API Calls
 
 - (NSString *) getCurrentServerVersion {

+ 6 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h

@@ -186,6 +186,12 @@ extern NSString * _Nullable OCWebDAVModificationDateKey;
 
 - (void)search:(NSString * _Nonnull)path fileName:(NSString * _Nonnull)fileName depth:(NSString * _Nonnull)depth user:(NSString * _Nonnull)user onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication withUserSessionToken:(NSString * _Nonnull)token success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nonnull, NSString * _Nonnull token))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nullable responseObject, NSError * _Nonnull, NSString * _Nonnull token))failure;
 
+/**
+ 
+ */
+
+- (void)settingFavorite:(NSString * _Nonnull)serverFilePath favorite:(BOOL)favorite onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication withUserSessionToken:(NSString * _Nonnull)token success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nonnull, NSString * _Nonnull token))success failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nullable responseObject, NSError * _Nonnull, NSString * _Nonnull token))failure;
+
 /**
  Creates an `NSURLSessionDownloadTask` with the specified request for a local file.
  

+ 19 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -299,6 +299,25 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     [operation resume];
 }
 
+- (void)settingFavorite:(NSString * _Nonnull)serverFilePath favorite:(BOOL)favorite onCommunication:(OCCommunication *)sharedOCCommunication withUserSessionToken:(NSString *)token success:(void(^)(NSHTTPURLResponse *, id, NSString *token))success failure:(void(^)(NSHTTPURLResponse *, id  _Nullable responseObject, NSError *, NSString *token))failure {
+    
+    NSParameterAssert(success);
+    
+    _requestMethod = @"PROPPATCH";
+    
+    NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:serverFilePath parameters:nil];
+    
+    NSString *body = [NSString stringWithFormat:@"<?xml version=\"1.0\"?><d:propertyupdate xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\"><d:set><d:prop><oc:favorite>%d</oc:favorite></d:prop></d:set></d:propertyupdate>", [NSNumber numberWithBool:favorite]];
+                      
+    [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
+    
+    [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
+    
+    OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication withUserSessionToken:token success:success failure:failure];
+    [self setRedirectionBlockOnDatataskWithOCCommunication:sharedOCCommunication andSessionManager:sharedOCCommunication.networkSessionManager];
+    [operation resume];
+}
+
 - (NSURLSessionDownloadTask *)downloadWithSessionPath:(NSString *)remoteSource toPath:(NSString *)localDestination defaultPriority:(BOOL)defaultPriority onCommunication:(OCCommunication *)sharedOCCommunication progress:(void(^)(NSProgress *progress))downloadProgress success:(void(^)(NSURLResponse *response, NSURL *filePath))success failure:(void(^)(NSURLResponse *response, NSError *error))failure{
     
     NSMutableURLRequest *request = [self requestWithMethod:@"GET" path:remoteSource parameters:nil];

+ 36 - 0
iOSClient/Actions/CCActions.swift

@@ -49,6 +49,11 @@ import Foundation
     func downloadThumbnailSuccess(_ metadataNet: CCMetadataNet)
 }
 
+@objc protocol CCActionsSettingFavoriteDelegate  {
+    
+    func settingFavoriteSuccess(_ metadataNet: CCMetadataNet)
+    func settingFavoriteFailure(_ metadataNet: CCMetadataNet, message: NSString, errorCode: NSInteger)
+}
 
 class CCActions: NSObject {
     
@@ -370,6 +375,37 @@ class CCActions: NSObject {
         NSLog("[LOG] Thumbnail Error \(metadataNet.fileName!) \(message) error %\(errorCode))")
     }
 
+    // --------------------------------------------------------------------------------------------
+    // MARK: Setting Favorite
+    // --------------------------------------------------------------------------------------------
+    
+    func settingFavorite(_ metadata: CCMetadata, favorite: Bool, delegate: AnyObject) {
+        
+        let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
+        let serverUrl = CCCoreData.getServerUrl(fromDirectoryID: metadata.directoryID, activeAccount: appDelegate.activeAccount)
+        
+        metadataNet.action = actionSettingFavorite
+        metadataNet.delegate = delegate
+        metadataNet.fileID = metadata.fileID
+        metadataNet.fileName = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: serverUrl, activeUrl: appDelegate.activeUrl)
+        metadataNet.options = "\(favorite)"
+        metadataNet.priority = Operation.QueuePriority.normal.rawValue
+        metadataNet.selector = selectorAddFavorite
+        metadataNet.serverUrl = serverUrl;
+        
+        appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+    }
+    
+    func settingFavoriteSuccess(_ metadataNet: CCMetadataNet) {
+        
+        metadataNet.delegate?.settingFavoriteSuccess(metadataNet)
+    }
+    
+    func settingFavoriteFailure(_ metadataNet: CCMetadataNet, message: NSString, errorCode: NSInteger) {
+        
+        metadataNet.delegate?.settingFavoriteFailure(metadataNet, message: message, errorCode: errorCode)
+    }
+
 }
 
 

+ 3 - 1
iOSClient/CCGlobal.h

@@ -153,8 +153,9 @@ extern NSString *const BKPasscodeKeychainServiceName;
 #define k_uploadSessionID                               @"ID_UPLOAD_"
 
 // Metadata.Net SELECTOR
-#define selectorAddOffline                              @"addOffline"
+#define selectorAddFavorite                             @"addFavorite"
 #define selectorAddLocal                                @"addLocal"
+#define selectorAddOffline                              @"addOffline"
 #define selectorCreateFolder                            @"createFolder"
 #define selectorDecryptFile                             @"decryptFile"
 #define selectorDelete                                  @"delete"
@@ -212,6 +213,7 @@ extern NSString *const BKPasscodeKeychainServiceName;
 #define actionReadFolder                                @"readFolder"
 #define actionReadShareServer                           @"readShareServer"
 #define actionSearch                                    @"search"
+#define actionSettingFavorite                           @"settingFavorite"
 #define actionShare                                     @"share"
 #define actionShareWith                                 @"shareWith"
 #define actionUnShare                                   @"unShare"

+ 49 - 7
iOSClient/Main/CCMain.m

@@ -1237,6 +1237,12 @@
         [self reloadDatasource:serverUrl fileID:metadata.fileID selector:selector];
     }
     
+    // add Favorite
+    if ([selector isEqualToString:selectorAddFavorite]) {
+        
+        [[CCActions sharedInstance] settingFavorite:metadata favorite:YES delegate:self];
+    }
+    
     // add Offline
     if ([selector isEqualToString:selectorAddOffline]) {
         [CCCoreData setOfflineLocalFileID:metadata.fileID offline:YES activeAccount:app.activeAccount];
@@ -2919,21 +2925,37 @@
     }
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Favorite =====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)addFavorite:(CCMetadata *)metadata
+{
+    NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
+    
+    [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddFavorite selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
+    
+    NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
+    if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
+}
+
+- (void)removeFavorite:(CCMetadata *)metadata
+{
+    //[CCCoreData setOfflineLocalFileID:metadata.fileID offline:NO activeAccount:app.activeAccount];
+    
+    //NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
+    //if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Offline =====
 #pragma --------------------------------------------------------------------------------------------
 
 - (void)addOffline:(CCMetadata *)metadata
 {
-    if (metadata.errorPasscode || !metadata.uuid) return;
-    
     NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
     
-    if ([metadata.type isEqualToString: k_metadataType_file])
-        [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddOffline selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
-    
-    if ([metadata.type isEqualToString: k_metadataType_template])
-        [CCCoreData setOfflineLocalFileID:metadata.fileID offline:YES activeAccount:app.activeAccount];
+    [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddOffline selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
     
     NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
     if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
@@ -2947,6 +2969,7 @@
     if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
 }
 
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Local =====
 #pragma --------------------------------------------------------------------------------------------
@@ -4400,6 +4423,25 @@
                                     }];
         }
         
+        if (!_metadata.cryptated) {
+            
+            [actionSheet addButtonWithTitle:@"favorite"
+                                      image:[UIImage imageNamed:image_actionSheetOffline]
+                            backgroundColor:[UIColor whiteColor]
+                                     height: 50.0
+                                       type:AHKActionSheetButtonTypeDefault
+                                    handler:^(AHKActionSheet *as) {
+                                        
+                                        // close swipe
+                                        [self setEditing:NO animated:YES];
+                                        
+                                        
+                                        [self addFavorite:_metadata];
+                                        
+                                    }];
+        }
+
+        
         [actionSheet addButtonWithTitle:NSLocalizedString(@"_add_local_", nil)
                                   image:[UIImage imageNamed:image_actionSheetLocal]
                         backgroundColor:[UIColor whiteColor]

+ 33 - 0
iOSClient/Networking/OCNetworking.m

@@ -450,6 +450,39 @@
     }];
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Setting Favorite =====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)settingFavorite
+{
+    OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
+    
+    [communication setCredentialsWithUser:_activeUser andPassword:_activePassword];
+    [communication setUserAgent:[CCUtility getUserAgent]];
+        
+    [communication settingFavoriteServer:_activeUrl andFileOrFolderPath:_metadataNet.fileName favorite:YES withUserSessionToken:nil onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer, NSString *token) {
+        
+        [self complete];
+        
+    } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *token, NSString *redirectedServer) {
+        
+        NSInteger errorCode = response.statusCode;
+        if (errorCode == 0)
+            errorCode = error.code;
+        
+        //if ([self.delegate respondsToSelector:@selector(searchFailure:message:errorCode:)])
+        //    [self.delegate searchFailure:_metadataNet message:[error.userInfo valueForKey:@"NSLocalizedDescription"] errorCode:errorCode];
+        
+        // Request trusted certificated
+        if ([error code] == NSURLErrorServerCertificateUntrusted)
+            [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:(UIViewController *)self.delegate delegate:self];
+        
+        [self complete];
+    }];
+
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Create Folder =====
 #pragma --------------------------------------------------------------------------------------------