Marino Faggiana 7 жил өмнө
parent
commit
9a35a56856

+ 2 - 75
iOSClient/Main/CCMain.m

@@ -982,32 +982,6 @@
 
 #pragma mark -
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ==== External Sites ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)getExternalSitesServerSuccessFailure:(CCMetadataNet *)metadataNet listOfExternalSites:(NSArray *)listOfExternalSites message:(NSString *)message errorCode:(NSInteger)errorCode
-{
-    // Check Active Account
-    if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
-        return;
-    
-    if (errorCode == 0) {
-        
-        [[NCManageDatabase sharedInstance] deleteExternalSites];
-        
-        for (OCExternalSites *tableExternalSites in listOfExternalSites)
-            [[NCManageDatabase sharedInstance] addExternalSites:tableExternalSites];
-        
-    } else {
-        
-        NSString *error = [NSString stringWithFormat:@"Get external site failure error %d, %@", (int)errorCode, message];
-        NSLog(@"[LOG] %@", error);
-        
-        [[NCManageDatabase sharedInstance] addActivityClient:@"" fileID:@"" action:k_activityDebugActionCapabilities selector:@"Get External Sites Server" note:error type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:appDelegate.activeUrl];
-    }
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ==== Activity ====
 #pragma --------------------------------------------------------------------------------------------
@@ -1104,53 +1078,6 @@
     }
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ==== User Profile  ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)getUserProfileSuccessFailure:(CCMetadataNet *)metadataNet userProfile:(OCUserProfile *)userProfile message:(NSString *)message errorCode:(NSInteger)errorCode
-{
-    // Check Active Account
-    if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
-        return;
-    
-    if (errorCode == 0) {
-    
-        // Update User (+ userProfile.id) & active account & account network
-        tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountUserProfile:userProfile];
-        if (tableAccount) {
-            [[CCNetworking sharedNetworking] settingAccount];
-            [appDelegate settingActiveAccount:tableAccount.account activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:tableAccount.password];
-        } else {
-            [appDelegate messageNotification:@"Account" description:@"Internal error : account not found on DB" visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
-        }
-
-        // Required userd ID (search + favorite)
-        [appDelegate.activePhotos readPhotoVideo];
-        [appDelegate.activeFavorites readListingFavorites];
-        
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-            
-            NSString *address = [NSString stringWithFormat:@"%@/index.php/avatar/%@/128", appDelegate.activeUrl, appDelegate.activeUser];
-            //UIImage *avatar = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]]; DEPRECATED iOS9
-            UIImage *avatar = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[address stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]]]];
-            if (avatar)
-                [UIImagePNGRepresentation(avatar) writeToFile:[NSString stringWithFormat:@"%@/avatar.png", appDelegate.directoryUser] atomically:YES];
-            else
-                [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/avatar.png", appDelegate.directoryUser] error:nil];
-            
-            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"changeUserProfile" object:nil];
-        });
-        
-    } else {
-        
-        NSString *error = [NSString stringWithFormat:@"Get user profile failure error %d, %@", (int)errorCode, message];
-        NSLog(@"[LOG] %@", error);
-        
-        [[NCManageDatabase sharedInstance] addActivityClient:@"" fileID:@"" action:k_activityDebugActionCapabilities selector:@"Get user profile Server" note:error type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:appDelegate.activeUrl];
-    }
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ==== Capabilities  ====
 #pragma --------------------------------------------------------------------------------------------
@@ -1201,13 +1128,13 @@
         
         // Read User Profile
         metadataNet.action = actionGetUserProfile;
-        [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
+        [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:NCService.sharedInstance metadataNet:metadataNet];
         
         // Read External Sites
         if (capabilities.isExternalSitesServerEnabled) {
             
             metadataNet.action = actionGetExternalSitesServer;
-            [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
+            [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:NCService.sharedInstance metadataNet:metadataNet];
         }
         
         // Read Share

+ 31 - 12
iOSClient/Networking/NCService.swift

@@ -31,9 +31,6 @@ class NCService: NSObject, OCNetworkingDelegate, CCLoginDelegate, CCLoginDelegat
         let instance = NCService()
         return instance
     }()
-
-    //MARK: -
-    //MARK: middlewarePing
     
      @objc func middlewarePing() {
        
@@ -51,9 +48,6 @@ class NCService: NSObject, OCNetworkingDelegate, CCLoginDelegate, CCLoginDelegat
         //appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
     }
     
-    //MARK: -
-    //MARK: requestServerCapabilities
-    
     func getCapabilitiesOfServerSuccessFailure(_ metadataNet: CCMetadataNet!, capabilities: OCCapabilities?, message: String?, errorCode: Int) {
         
         // Check Active Account
@@ -113,9 +107,6 @@ class NCService: NSObject, OCNetworkingDelegate, CCLoginDelegate, CCLoginDelegat
         metadataNet.action = actionGetCapabilities;
         appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
     }
-
-    //MARK: -
-    //MARK: requestServerCapabilities
     
     @objc func getUserProfileSuccessFailure(_ metadataNet: CCMetadataNet!, userProfile: OCUserProfile?, message: String?, errorCode: Int) {
         
@@ -141,20 +132,24 @@ class NCService: NSObject, OCNetworkingDelegate, CCLoginDelegate, CCLoginDelegat
             
             DispatchQueue.global(qos: .default).async {
                 
-                guard let imageData = try? Data(contentsOf: URL(string: "\(self.appDelegate.activeUrl)/index.php/avatar/\(self.appDelegate.activeUser)/128")!) else {
+                let address = "\(self.appDelegate.activeUrl!)/index.php/avatar/\(self.appDelegate.activeUser!)/128"
+                guard let imageData = try? Data(contentsOf: URL(string: address)!) else {
                     NotificationCenter.default.post(name: NSNotification.Name(rawValue: "changeUserProfile"), object: nil)
                     return
                 }
                 
                 guard let avatar = UIImage(data: imageData) else {
-                    try? FileManager.default.removeItem(atPath: "\(self.appDelegate.directoryUser)/avatar.png")
+                    let fileName = "\(self.appDelegate.directoryUser!)/avatar.png"
+                    try? FileManager.default.removeItem(atPath: fileName)
                     NotificationCenter.default.post(name: NSNotification.Name(rawValue: "changeUserProfile"), object: nil)
                     return
                 }
                 
                 if let data = UIImagePNGRepresentation(avatar) {
-                    try? data.write(to: URL(string:"\(self.appDelegate.directoryUser)/avatar.png")!)
+                    let fileName = "\(self.appDelegate.directoryUser!)/avatar.png"
+                    try? data.write(to: URL(fileURLWithPath: fileName))
                 }
+                
                 NotificationCenter.default.post(name: NSNotification.Name(rawValue: "changeUserProfile"), object: nil)
             }
             
@@ -167,6 +162,30 @@ class NCService: NSObject, OCNetworkingDelegate, CCLoginDelegate, CCLoginDelegat
         }
     }
     
+    @objc func getExternalSitesServerSuccessFailure(_ metadataNet: CCMetadataNet!, listOfExternalSites: [Any]?, message: String?, errorCode: Int) {
+        
+        // Check Active Account
+        if (metadataNet.account != appDelegate.activeAccount) {
+            return;
+        }
+        
+        if (errorCode == 0) {
+            
+            NCManageDatabase.sharedInstance.deleteExternalSites()
+            
+            for externalSites in listOfExternalSites! {
+                NCManageDatabase.sharedInstance.addExternalSites(externalSites as! OCExternalSites)
+            }
+            
+        } else {
+         
+            let error = "Get external site failure error \(errorCode) \(message!)"
+            print("[LOG] \(error)")
+            
+            NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionCapabilities, selector: "Get external site Server", note: error, type: k_activityTypeFailure, verbose: true, activeUrl: appDelegate.activeUrl)
+        }
+    }
+    
     //MARK: -
     //MARK: Delegate : Login