瀏覽代碼

Merge pull request #2528 from nextcloud/fix/share

Fix/share
Marino Faggiana 1 年之前
父節點
當前提交
e75c6e69d3

+ 2 - 2
ExternalResources/NCApplicationHandle.swift

@@ -32,8 +32,8 @@ class NCApplicationHandle: NSObject {
 
     // class: AppDelegate
     // func nextcloudPushNotificationAction(data: [String: AnyObject])
-    func nextcloudPushNotificationAction(data: [String: AnyObject], completion: @escaping (_ detected: Bool) -> Void) {
-        completion(false)
+    func nextcloudPushNotificationAction(data: [String: AnyObject], completion: @escaping () -> Void) {
+        completion()
     }
 
     // class: AppDelegate

+ 27 - 30
iOSClient/AppDelegate.swift

@@ -230,9 +230,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // Request TouchID, FaceID
         enableTouchFaceID()
         
-        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterApplicationWillEnterForeground)
         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRichdocumentGrabFocus)
-        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSourceNetwork)
+        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSourceNetwork, second: 2)
     }
 
     // L' applicazione si dimetterà dallo stato di attivo
@@ -440,37 +439,35 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     }
 
     func nextcloudPushNotificationAction(data: [String: AnyObject]) {
-        NCApplicationHandle().nextcloudPushNotificationAction(data: data) { detected in
-            if !detected {
-
-                var findAccount: Bool = false
-
-                if let accountPush = data["account"] as? String,
-                   let app = data["app"] as? String,
-                   app == NCGlobal.shared.twofactorNotificatioName {
-                    if accountPush == self.account {
-                        findAccount = true
-                    } else {
-                        let accounts = NCManageDatabase.shared.getAllAccount()
-                        for account in accounts {
-                            if account.account == accountPush {
-                                self.changeAccount(account.account)
-                                findAccount = true
-                            }
+        NCApplicationHandle().nextcloudPushNotificationAction(data: data) {
+
+            var findAccount: Bool = false
+
+            if let accountPush = data["account"] as? String,
+               let app = data["app"] as? String,
+               app == NCGlobal.shared.twoFactorNotificatioName {
+                if accountPush == self.account {
+                    findAccount = true
+                } else {
+                    let accounts = NCManageDatabase.shared.getAllAccount()
+                    for account in accounts {
+                        if account.account == accountPush {
+                            self.changeAccount(account.account)
+                            findAccount = true
                         }
                     }
-                    if findAccount, let viewController = UIStoryboard(name: "NCNotification", bundle: nil).instantiateInitialViewController() as? NCNotification {
-                        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
-                            let navigationController = UINavigationController(rootViewController: viewController)
-                            navigationController.modalPresentationStyle = .fullScreen
-                            self.window?.rootViewController?.present(navigationController, animated: true)
-                        }
-                    } else if !findAccount {
-                        let message = NSLocalizedString("_the_account_", comment: "") + " " + accountPush + " " + NSLocalizedString("_does_not_exist_", comment: "")
-                        let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
-                        alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
-                        self.window?.rootViewController?.present(alertController, animated: true, completion: { })
+                }
+                if findAccount, let viewController = UIStoryboard(name: "NCNotification", bundle: nil).instantiateInitialViewController() as? NCNotification {
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
+                        let navigationController = UINavigationController(rootViewController: viewController)
+                        navigationController.modalPresentationStyle = .fullScreen
+                        self.window?.rootViewController?.present(navigationController, animated: true)
                     }
+                } else if !findAccount {
+                    let message = NSLocalizedString("_the_account_", comment: "") + " " + accountPush + " " + NSLocalizedString("_does_not_exist_", comment: "")
+                    let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert)
+                    alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
+                    self.window?.rootViewController?.present(alertController, animated: true, completion: { })
                 }
             }
         }

+ 2 - 0
iOSClient/Data/NCManageDatabase+Share.swift

@@ -80,6 +80,8 @@ extension NCManageDatabase {
         do {
             let realm = try Realm()
             try realm.write {
+                let result = realm.objects(tableShare.self).filter("account == %@", account)
+                realm.delete(result)
                 for share in shares {
                     let serverUrlPath = home + share.path
                     guard let serverUrl = NCUtilityFileSystem.shared.deleteLastPath(serverUrlPath: serverUrlPath, home: home) else { continue }

+ 1 - 2
iOSClient/NCGlobal.swift

@@ -92,7 +92,7 @@ class NCGlobal: NSObject {
     let appScheme                                   = "nextcloud"
     let talkName                                    = "talk-message"
     let spreedName                                  = "spreed"
-    let twofactorNotificatioName                    = "twofactor_nextcloud_notification"
+    let twoFactorNotificatioName                    = "twofactor_nextcloud_notification"
 
     // Nextcloud version
     //
@@ -321,7 +321,6 @@ class NCGlobal: NSObject {
     // Notification Center
     //
     @objc let notificationCenterApplicationDidEnterBackground   = "applicationDidEnterBackground"
-    let notificationCenterApplicationWillEnterForeground        = "applicationWillEnterForeground"
     let notificationCenterApplicationDidBecomeActive            = "applicationDidBecomeActive"
     let notificationCenterApplicationWillResignActive           = "applicationWillResignActive"
 

+ 1 - 1
iOSClient/Notification/NCNotification.swift

@@ -287,7 +287,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
                         self.notifications.remove(at: index)
                     }
                     self.tableView.reloadData()
-                    if self.navigationController?.presentingViewController != nil, notification.app == NCGlobal.shared.twofactorNotificatioName {
+                    if self.navigationController?.presentingViewController != nil, notification.app == NCGlobal.shared.twoFactorNotificatioName {
                         self.dismiss(animated: true)
                     }
                 } else if error != .success {

+ 22 - 27
iOSClient/Shares/NCShares.swift

@@ -52,40 +52,34 @@ class NCShares: NCCollectionViewCommon {
     override func reloadDataSource(forced: Bool = true) {
         super.reloadDataSource()
 
-        DispatchQueue.global().async {
-            let sharess = NCManageDatabase.shared.getTableShares(account: self.appDelegate.account)
-            var metadatas: [tableMetadata] = []
-            for share in sharess {
-                if let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", self.appDelegate.account, share.serverUrl, share.fileName)) {
-                    if !(metadatas.contains { $0.ocId == metadata.ocId }) {
-                        metadatas.append(metadata)
-                    }
+        let sharess = NCManageDatabase.shared.getTableShares(account: self.appDelegate.account)
+        var metadatas: [tableMetadata] = []
+        for share in sharess {
+            if let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", self.appDelegate.account, share.serverUrl, share.fileName)) {
+                if !(metadatas.contains { $0.ocId == metadata.ocId }) {
+                    metadatas.append(metadata)
                 }
             }
-
-            self.dataSource = NCDataSource(metadatas: metadatas,
-                                           account: self.appDelegate.account,
-                                           sort: self.layoutForView?.sort,
-                                           ascending: self.layoutForView?.ascending,
-                                           directoryOnTop: self.layoutForView?.directoryOnTop,
-                                           favoriteOnTop: true,
-                                           filterLivePhoto: true,
-                                           groupByField: self.groupByField,
-                                           providers: self.providers,
-                                           searchResults: self.searchResults)
-
-            DispatchQueue.main.async {
-                self.refreshControl.endRefreshing()
-                self.collectionView.reloadData()
-            }
         }
+        self.dataSource = NCDataSource(metadatas: metadatas,
+                                       account: self.appDelegate.account,
+                                       sort: self.layoutForView?.sort,
+                                       ascending: self.layoutForView?.ascending,
+                                       directoryOnTop: self.layoutForView?.directoryOnTop,
+                                       favoriteOnTop: true,
+                                       filterLivePhoto: true,
+                                       groupByField: self.groupByField,
+                                       providers: self.providers,
+                                       searchResults: self.searchResults)
+
+
+        self.refreshControl.endRefreshing()
+        self.collectionView.reloadData()
     }
 
     override func reloadDataSourceNetwork(forced: Bool = false) {
         super.reloadDataSourceNetwork(forced: forced)
 
-        if UIApplication.shared.applicationState != .active { return }
-
         isReloadDataSourceNetworkInProgress = true
         collectionView?.reloadData()
 
@@ -95,10 +89,11 @@ class NCShares: NCCollectionViewCommon {
             self.isReloadDataSourceNetworkInProgress = false
 
             if error == .success {
-                NCManageDatabase.shared.deleteTableShare(account: account)
                 if let shares = shares, !shares.isEmpty {
                     let home = NCUtilityFileSystem.shared.getHomeServer(urlBase: self.appDelegate.urlBase, userId: self.appDelegate.userId)
                     NCManageDatabase.shared.addShare(account: self.appDelegate.account, home: home, shares: shares)
+                } else {
+                    NCManageDatabase.shared.deleteTableShare(account: account)
                 }
                 self.reloadDataSource()