marinofaggiana 3 years ago
parent
commit
0102ceecc7

+ 10 - 6
Share/NCShareExtension.swift

@@ -178,7 +178,11 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         
         if serverUrl == "" {
         
-            setAccount()
+            guard let activeAccount = NCManageDatabase.shared.getActiveAccount() else {
+                extensionContext?.completeRequest(returningItems: extensionContext?.inputItems, completionHandler: nil)
+                return
+            }
+            setAccount(account: activeAccount.account)
             
             getFilesExtensionContext { (filesName, error) in
                 DispatchQueue.main.async {
@@ -206,9 +210,9 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
     
     // MARK: -
 
-    func setAccount() {
+    func setAccount(account: String) {
         
-        guard let activeAccount = NCManageDatabase.shared.getActiveAccount() else {
+        guard let activeAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else {
             extensionContext?.completeRequest(returningItems: extensionContext?.inputItems, completionHandler: nil)
             return
         }
@@ -259,7 +263,7 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
             
         if serverUrl == NCUtilityFileSystem.shared.getHomeServer(urlBase: activeAccount.urlBase, account: activeAccount.account) {
              
-            let activeAccount = NCManageDatabase.shared.getActiveAccount()
+
             var title = "  "
             if activeAccount?.alias == "" {
                 title = title + (activeAccount?.user ?? "")
@@ -449,8 +453,8 @@ class NCShareExtension: UIViewController, NCListCellDelegate, NCEmptyDataSetDele
         }
     }
     
-    func changeAccountRequestAddAccount() {
-        setAccount()
+    func changeAccountRequestAddAccount(account: String) {
+        setAccount(account: account)
     }
     
     @objc func profileButtonTapped(sender: Any) {

+ 3 - 4
iOSClient/Account Request/NCAccountRequest.swift

@@ -26,13 +26,13 @@ import NCCommunication
 
 public protocol NCAccountRequestDelegate {
     func accountRequestAddAccount()
-    func changeAccountRequestAddAccount()
+    func changeAccountRequestAddAccount(account: String)
 }
 
 // optional func
 public extension NCAccountRequestDelegate {
     func accountRequestAddAccount() {}
-    func changeAccountRequestAddAccount() {}
+    func changeAccountRequestAddAccount(account: String) {}
 }
 
 class NCAccountRequest: UIViewController {
@@ -166,9 +166,8 @@ extension NCAccountRequest: UITableViewDelegate {
             let account = accounts[indexPath.row]
             let activeAccount = NCManageDatabase.shared.getActiveAccount()
             if account.account != activeAccount?.account {
-                NCManageDatabase.shared.setAccountActive(account.account)
                 dismiss(animated: true) {
-                    self.delegate?.changeAccountRequestAddAccount()
+                    self.delegate?.changeAccountRequestAddAccount(account: account.account)
                 }
             } else {
                 dismiss(animated: true)

+ 2 - 1
iOSClient/AppDelegate.swift

@@ -612,7 +612,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     
     // MARK: - Account Request
     
-    func changeAccountRequestAddAccount() {
+    func changeAccountRequestAddAccount(account: String) {
+        NCManageDatabase.shared.setAccountActive(account)
         if let activeAccount = NCManageDatabase.shared.getActiveAccount() {
             
             NCOperationQueue.shared.cancelAllQueue()

+ 2 - 1
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -663,7 +663,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         self.collectionView.reloadData()
     }
     
-    func changeAccountRequestAddAccount() {
+    func changeAccountRequestAddAccount(account: String) {
+        NCManageDatabase.shared.setAccountActive(account)
         if let activeAccount = NCManageDatabase.shared.getActiveAccount() {
             
             NCOperationQueue.shared.cancelAllQueue()