Marino Faggiana 8 years ago
parent
commit
4a7d13466b
3 changed files with 38 additions and 7 deletions
  1. 9 0
      iOSClient/Main/CCMain.m
  2. 2 0
      iOSClient/Offline/CCSynchronize.h
  3. 27 7
      iOSClient/Offline/CCSynchronize.m

+ 9 - 0
iOSClient/Main/CCMain.m

@@ -2961,6 +2961,15 @@
         [self readFolderWithForced:YES serverUrl:metadataNet.serverUrl];
     else
         [self reloadDatasource:metadataNet.serverUrl fileID:metadataNet.fileID selector:metadataNet.selector];
+    
+    CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", metadata.fileID, app.activeAccount] context:nil];
+    
+    if (metadata.directory) {
+        
+        NSString *dir = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:metadata.fileNameData];
+        
+        [[CCSynchronize sharedSynchronize] addFavoriteFolder:dir];
+    }
 }
 
 - (void)settingFavoriteFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode

+ 2 - 0
iOSClient/Offline/CCSynchronize.h

@@ -35,6 +35,8 @@
 
 - (void)readListingFavorites;
 - (void)readOffline;
+
+- (void)addFavoriteFolder:(NSString *)serverUrl;
 - (void)addOfflineFolder:(NSString *)serverUrl;
 
 - (void)verifyChangeMedatas:(NSArray *)allRecordMetadatas serverUrl:(NSString *)serverUrl account:(NSString *)account offline:(BOOL)offline;

+ 27 - 7
iOSClient/Offline/CCSynchronize.m

@@ -67,6 +67,21 @@
     [[CCActions sharedInstance] listingFavorites:@"" delegate:self];
 }
 
+- (void)addFavoriteFolder:(NSString *)serverUrl
+{
+    NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
+    
+    CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
+    
+    metadataNet.action = actionReadFolder;
+    metadataNet.directoryID = directoryID;
+    metadataNet.priority = NSOperationQueuePriorityVeryHigh;
+    metadataNet.selector = selectorReadFolder;
+    metadataNet.serverUrl = serverUrl;
+    
+    [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
+}
+
 - (void)listingFavoritesSuccess:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas
 {
     // verify active user
@@ -107,9 +122,15 @@
         [CCCoreData addMetadata:metadata activeAccount:app.activeAccount activeUrl:app.activeUrl context:nil];
         
         if (metadata.directory) {
+            
             NSString* serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
-            [self readFolderServerUrl:serverUrl directoryID:metadata.directoryID];
+            serverUrl = [CCUtility stringAppendServerUrl:serverUrl addServerUrl:metadata.fileNameData];
+            NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
+            
+            [self readFolderServerUrl:serverUrl directoryID:directoryID];
+            
         } else {
+            
             [self readFile:metadata];
         }
     }
@@ -174,9 +195,7 @@
     metadataNet.selector = selectorReadFolder;
     metadataNet.serverUrl = serverUrl;
     
-    [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-    
-    NSLog(@"[LOG] Read offline directory : %@", serverUrl);
+    [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];    
 }
 
 // Graphics Animation Offline Folders
@@ -307,12 +326,13 @@
                 
                 dispatch_async(dispatch_get_main_queue(), ^{
                     
-                    NSString *dir = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:metadata.fileNameData];
+                    NSString *serverUrl = [CCUtility stringAppendServerUrl:metadataNet.serverUrl addServerUrl:metadata.fileNameData];
+                    NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
                     
                     [CCCoreData addMetadata:metadata activeAccount:app.activeAccount activeUrl:app.activeUrl context:nil];
                     
-                    [[CCSynchronize sharedSynchronize] addOfflineFolder:dir];
-
+                    [self readFolderServerUrl:serverUrl directoryID:directoryID];
+                    
                 });
                 
             } else {