marinofaggiana 5 жил өмнө
parent
commit
dd783c1de4

+ 2 - 1
iOSClient/AppDelegate.h

@@ -144,8 +144,9 @@
 // Login View
 - (void)openLoginView:(UIViewController *)viewController delegate:(id)delegate loginType:(NSInteger)loginType selector:(NSInteger)selector;
 
-// Setting Active Account
+// Setting Account
 - (void)settingActiveAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl activeUser:(NSString *)activeUser activeUserID:(NSString *)activeUserID activePassword:(NSString *)activePassword;
+- (void)deleteAccount:(NSString *)account withChangeUser:(BOOL)withChangeUser;
 
 // Quick Actions - ShotcutItem
 - (void)configDynamicShortcutItems;

+ 20 - 1
iOSClient/AppDelegate.m

@@ -433,7 +433,7 @@ PKPushRegistry *pushRegistry;
 }
 
 #pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Setting Active Account for all APP =====
+#pragma mark ===== Account =====
 #pragma --------------------------------------------------------------------------------------------
 
 - (void)settingActiveAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl activeUser:(NSString *)activeUser activeUserID:(NSString *)activeUserID activePassword:(NSString *)activePassword
@@ -448,6 +448,25 @@ PKPushRegistry *pushRegistry;
     [CCNetworking sharedNetworking].delegate = [NCNetworkingMain sharedInstance];
 }
 
+- (void)deleteAccount:(NSString *)account withChangeUser:(BOOL)withChangeUser
+{
+    [self unsubscribingNextcloudServerPushNotification:account url:self.activeUrl withSubscribing:false];
+    [self settingActiveAccount:nil activeUrl:nil activeUser:nil activeUserID:nil activePassword:nil];
+    
+    [[NCUtility sharedInstance] removeAccountOnDBKeychain:account];
+    
+    if (withChangeUser) {
+        NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
+        if ([listAccount count] > 0) {
+            tableAccount *newAccount = listAccount[0];
+            [self settingActiveAccount:newAccount.account activeUrl:newAccount.url activeUser:newAccount.user activeUserID:newAccount.userID activePassword:[CCUtility getPassword:newAccount.account]];
+            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
+        } else {
+            [self openLoginView:self.window.rootViewController delegate:self loginType:k_login_Add_Forced selector:k_intro_login];
+        }
+    }
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== PushNotification & PushKit Delegate =====
 #pragma --------------------------------------------------------------------------------------------

+ 5 - 11
iOSClient/Networking/OCNetworking.m

@@ -2409,24 +2409,18 @@
     if (capabilities != nil && capabilities.versionMajor >= k_nextcloud_version_17_0) {
         [[OCNetworking sharedManager] getRemoteWipeStatusWithAccount:account completion:^(NSString *account, BOOL wipe, NSString *message, NSInteger errorCode) {
             
-            if (wipe == false) {
-                [CCUtility setPassword:account password:nil];
-            } else {
-                // remove account
+            if (wipe) {
                 
 #ifndef EXTENSION
-                AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-                
-                [appDelegate unsubscribingNextcloudServerPushNotification:account url:appDelegate.activeUrl withSubscribing:false];
-                [appDelegate settingActiveAccount:nil activeUrl:nil activeUser:nil activeUserID:nil activePassword:nil];
+                [(AppDelegate *)[[UIApplication sharedApplication] delegate] deleteAccount:account withChangeUser:true];
 #endif
-                [[NCUtility sharedInstance] removeAccountOnDBKeychain:account];
-
-                // new account
+            } else {
                 
+                [CCUtility setPassword:account password:nil];
             }
         }];
     } else {
+        
         [CCUtility setPassword:account password:nil];
     }
 }

+ 1 - 5
iOSClient/Settings/CCManageAccount.m

@@ -407,11 +407,7 @@
         NSString *account = tableAccount.account;
         
         if (account) {
-            
-            [appDelegate unsubscribingNextcloudServerPushNotification:account url:tableAccount.url withSubscribing:false];
-            [appDelegate settingActiveAccount:nil activeUrl:nil activeUser:nil activeUserID:nil activePassword:nil];
-            
-            [[NCUtility sharedInstance] removeAccountOnDBKeychain:account];
+            [appDelegate deleteAccount:account withChangeUser:false];
         }
         
         NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];