Sfoglia il codice sorgente

coding

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 anni fa
parent
commit
d7c7f25315

+ 1 - 1
iOSClient/AppDelegate.swift

@@ -646,7 +646,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                 accounts.append(NKDataAccountFile(withUrl: account.urlBase, user: account.user, alias: alias))
             }
         }
-        return NKAccountFile().putShareAccounts(at: url, app: NCGlobal.shared.appScheme, items: accounts)
+        return NKAccountFile().putShareAccounts(at: url, app: NCGlobal.shared.appScheme, dataAccounts: accounts)
     }
 
     // MARK: - Account Request

+ 1 - 1
iOSClient/Login/NCLogin.swift

@@ -117,7 +117,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
 
         if NCBrandOptions.shared.use_GroupApps, let dirGroupApps = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroupApps) {
             let url = dirGroupApps.appendingPathComponent(NCGlobal.shared.directoryNextcloudAccounts + "/" + NCGlobal.shared.fileShareAccounts)
-            if FileManager.default.fileExists(atPath: url.path), let shareAccounts = NKAccountFile().getShareAccount(at: url) {
+            if FileManager.default.fileExists(atPath: url.path), let shareAccounts = NKAccountFile().getShareAccount(at: url, application: UIApplication.shared) {
                 var accountTemp = [NKDataAccountFile]()
                 for shareAccount in shareAccounts {
                     if NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "urlBase == %@ AND user == %@", shareAccount.url, shareAccount.user)) == nil {

+ 18 - 8
iOSClient/Networking/NCNetworking.swift

@@ -1574,13 +1574,13 @@ import Photos
             let apps: [String: [Account]]?
         }
 
-        func putShareAccounts(at url: URL, app: String, items: [NKDataAccountFile]) -> Error? {
+        @objc func putShareAccounts(at url: URL, app: String, dataAccounts: [NKDataAccountFile]) -> Error? {
 
             var apps: [String : [Account]] = [:]
             var accounts: [Account] = []
 
-            for item in items {
-                let account = Account(url: item.url, user: item.user, alias: item.alias, avatar: item.avatar)
+            for dataAccount in dataAccounts {
+                let account = Account(url: dataAccount.url, user: dataAccount.user, alias: dataAccount.alias, avatar: dataAccount.avatar)
                 accounts.append(account)
             }
             apps[app] = accounts
@@ -1606,20 +1606,30 @@ import Photos
             return nil
         }
 
-        func getShareAccount(at url: URL) -> [NKDataAccountFile]? {
+        @objc func getShareAccount(at url: URL, application: UIApplication?) -> [NKDataAccountFile]? {
+
+            var dataAccounts: [NKDataAccountFile] = []
 
             do {
                 let data = try Data(contentsOf: url)
                 let json = try JSONDecoder().decode(Apps.self, from: data)
                 if let appsDecoder = json.apps {
-                    for app in appsDecoder {
-                        print("")
+                    for appDecoder in appsDecoder {
+                        let app = appDecoder.key
+                        let accounts = appDecoder.value
+                        if let url = URL(string: app + "://"), let application = application, application.canOpenURL(url) {
+                            for account in accounts {
+                                if dataAccounts.first(where: { $0.url == account.url && $0.user == account.user }) == nil {
+                                    let account = NKDataAccountFile(withUrl: account.url, user: account.user, alias: account.alias, avatar: account.avatar)
+                                    dataAccounts.append(account)
+                                }
+                            }
+                        }
                     }
                 }
             } catch { }
 
-
-            return nil
+            return dataAccounts.isEmpty ? nil : dataAccounts
         }
     }