Browse Source

build 5

Signed-off-by: Marino Faggiana <8616947+marinofaggiana@users.noreply.github.com>
Marino Faggiana 1 năm trước cách đây
mục cha
commit
08d2e48da9

+ 5 - 6
iOSClient/AppDelegate.swift

@@ -135,7 +135,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
             NCBrandColor.shared.settingThemingColor(account: activeAccount.account)
 
-            NCMediaCache.shared.createCache(account: self.account)
+            DispatchQueue.global().async { NCMediaCache.shared.createCache(account: activeAccount.account) }
 
         } else {
 
@@ -269,7 +269,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Create share accounts \(error.localizedDescription)")
         }
 
-        NCNetworking.shared.cancelSessions(inBackground: false)
+        NCNetworking.shared.cancel(inBackground: false)
 
         presentPasscode { }
 
@@ -279,7 +279,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     // L'applicazione terminerà
     func applicationWillTerminate(_ application: UIApplication) {
 
-        NCNetworking.shared.cancelSessions(inBackground: false)
+        NCNetworking.shared.cancel(inBackground: false)
 
         if UIApplication.shared.backgroundRefreshStatus == .available {
 
@@ -576,10 +576,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
     @objc func changeAccount(_ account: String, userProfile: NKUserProfile?) {
 
+        NCNetworking.shared.cancel(inBackground: false)
         guard let tableAccount = NCManageDatabase.shared.setAccountActive(account) else { return }
 
-        NCNetworking.shared.cancelSessions(inBackground: false)
-
         self.account = tableAccount.account
         self.urlBase = tableAccount.urlBase
         self.user = tableAccount.user
@@ -605,7 +604,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Initialize Auto upload with \(items) uploads")
         }
 
-        DispatchQueue.global().async { NCMediaCache.shared.createCache(account: account) }
+        DispatchQueue.global().async { NCMediaCache.shared.createCache(account: self.account) }
 
         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterChangeUser)
     }

+ 3 - 9
iOSClient/Media/NCMedia.swift

@@ -39,7 +39,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
     internal let appDelegate = UIApplication.shared.delegate as! AppDelegate
     // swiftlint:enable force_cast
 
-    private var account: String = ""
+    //private var account: String = ""
 
     internal var isEditMode = false
     internal var selectOcId: [String] = []
@@ -162,7 +162,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
               let error = userInfo["error"] as? NKError else { return }
         let onlyLocalCache: Bool = userInfo["onlyLocalCache"] as? Bool ?? false
 
-        NCMediaCache.shared.getMetadatasMedia(filterClassTypeImage: filterClassTypeImage, filterClassTypeVideo: filterClassTypeVideo)
+        NCMediaCache.shared.getMetadatasMedia(account: appDelegate.account, filterClassTypeImage: filterClassTypeImage, filterClassTypeVideo: filterClassTypeVideo)
 
         if error == .success, let indexPath = userInfo["indexPath"] as? [IndexPath], !indexPath.isEmpty, !onlyLocalCache {
             collectionView?.performBatchUpdates({
@@ -447,14 +447,8 @@ extension NCMedia {
     @objc func reloadDataSourceWithCompletion(_ completion: @escaping (_ metadatas: [tableMetadata]) -> Void) {
         guard !appDelegate.account.isEmpty else { return }
 
-        if account != appDelegate.account {
-            NCMediaCache.shared.metadatas = []
-            account = appDelegate.account
-            DispatchQueue.main.async { self.collectionView?.reloadData() }
-        }
-
         DispatchQueue.global().async {
-            NCMediaCache.shared.getMetadatasMedia(filterClassTypeImage: self.filterClassTypeImage, filterClassTypeVideo: self.filterClassTypeVideo)
+            NCMediaCache.shared.getMetadatasMedia(account: self.appDelegate.account, filterClassTypeImage: self.filterClassTypeImage, filterClassTypeVideo: self.filterClassTypeVideo)
             DispatchQueue.main.sync {
                 self.reloadDataThenPerform {
                     self.updateMediaControlVisibility()

+ 7 - 7
iOSClient/Media/NCMediaCache.swift

@@ -48,7 +48,7 @@ import NextcloudKit
               let directory = CCUtility.getDirectoryProviderStorage() else { return }
 
         metadatas.removeAll()
-        getMetadatasMedia()
+        getMetadatasMedia(account: account)
 
         let ext = ".preview.ico"
         let manager = FileManager.default
@@ -116,19 +116,19 @@ import NextcloudKit
         cache.removeAllValues()
     }
 
-    func getMetadatasMedia(filterClassTypeImage: Bool = false, filterClassTypeVideo: Bool = false) {
+    func getMetadatasMedia(account: String, filterClassTypeImage: Bool = false, filterClassTypeVideo: Bool = false) {
 
         let livePhoto = CCUtility.getLivePhoto()
         guard let appDelegate = (UIApplication.shared.delegate as? AppDelegate),
-              let activeAccount = NCManageDatabase.shared.getActiveAccount() else { return }
-        let startServerUrl = NCUtilityFileSystem.shared.getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId) + activeAccount.mediaPath
+              let account = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else { return }
+        let startServerUrl = NCUtilityFileSystem.shared.getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId) + account.mediaPath
 
-        predicateDefault = NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@ AND (classFile == %@ OR classFile == %@) AND NOT (session CONTAINS[c] 'upload')", appDelegate.account, startServerUrl, NKCommon.TypeClassFile.image.rawValue, NKCommon.TypeClassFile.video.rawValue)
+        predicateDefault = NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@ AND (classFile == %@ OR classFile == %@) AND NOT (session CONTAINS[c] 'upload')", account.account, startServerUrl, NKCommon.TypeClassFile.image.rawValue, NKCommon.TypeClassFile.video.rawValue)
 
         if filterClassTypeImage {
-            predicate = NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@ AND classFile == %@ AND NOT (session CONTAINS[c] 'upload')", appDelegate.account, startServerUrl, NKCommon.TypeClassFile.video.rawValue)
+            predicate = NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@ AND classFile == %@ AND NOT (session CONTAINS[c] 'upload')", account.account, startServerUrl, NKCommon.TypeClassFile.video.rawValue)
         } else if filterClassTypeVideo {
-            predicate = NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@ AND classFile == %@ AND NOT (session CONTAINS[c] 'upload')", appDelegate.account, startServerUrl, NKCommon.TypeClassFile.image.rawValue)
+            predicate = NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@ AND classFile == %@ AND NOT (session CONTAINS[c] 'upload')", account.account, startServerUrl, NKCommon.TypeClassFile.image.rawValue)
         } else {
             predicate = predicateDefault
         }

+ 13 - 18
iOSClient/Networking/NCNetworking.swift

@@ -771,17 +771,11 @@ class NCNetworking: NSObject, NKCommonDelegate {
     // sessionIdentifierBackgroundWWan: String = "com.nextcloud.session.upload.backgroundWWan"
     // sessionIdentifierBackgroundExtension: String = "com.nextcloud.session.upload.extension"
 
-    func cancelSessions(inBackground: Bool) {
-        Task {
-            await cancel(inBackground: inBackground)
-        }
-    }
-
-    func cancel(inBackground: Bool) async {
+    func cancel(inBackground: Bool) {
 
 #if !EXTENSION
-        if let appDelegate = await UIApplication.shared.delegate as? AppDelegate {
-            await appDelegate.cancelAllQueue()
+        if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
+            appDelegate.cancelAllQueue()
         }
 #endif
 
@@ -813,16 +807,17 @@ class NCNetworking: NSObject, NKCommonDelegate {
             NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
         }
 
-        let tasksBackground = await NCNetworking.shared.sessionManagerBackground.tasks
-        for task in tasksBackground.1 { // ([URLSessionDataTask], [URLSessionUploadTask], [URLSessionDownloadTask])
-            task.cancel()
-        }
-        let tasksBackgroundWWan = await NCNetworking.shared.sessionManagerBackgroundWWan.tasks
-        for task in tasksBackgroundWWan.1 { // ([URLSessionDataTask], [URLSessionUploadTask], [URLSessionDownloadTask])
-            task.cancel()
+        Task {
+            let tasksBackground = await NCNetworking.shared.sessionManagerBackground.tasks
+            for task in tasksBackground.1 { // ([URLSessionDataTask], [URLSessionUploadTask], [URLSessionDownloadTask])
+                task.cancel()
+            }
+            let tasksBackgroundWWan = await NCNetworking.shared.sessionManagerBackgroundWWan.tasks
+            for task in tasksBackgroundWWan.1 { // ([URLSessionDataTask], [URLSessionUploadTask], [URLSessionDownloadTask])
+                task.cancel()
+            }
+            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource)
         }
-
-        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource)
     }
 
     func cancel(metadata: tableMetadata) async {

+ 1 - 1
iOSClient/Networking/NCNetworkingCheckRemoteUser.swift

@@ -32,7 +32,7 @@ class NCNetworkingCheckRemoteUser {
               let token = CCUtility.getPassword(account), !token.isEmpty,
               let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
 
-        NCNetworking.shared.cancelSessions(inBackground: true)
+        NCNetworking.shared.cancel(inBackground: true)
 
         if NCGlobal.shared.capabilityServerVersionMajor >= NCGlobal.shared.nextcloudVersion17 {
 

+ 2 - 2
iOSClient/Settings/CCAdvanced.m

@@ -367,7 +367,7 @@
 
 - (void)clearCache:(NSString *)account
 {
-    [[NCNetworking shared] cancelSessionsInBackground:true];
+    [[NCNetworking shared] cancelInBackground:true];
 
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
 
@@ -450,7 +450,7 @@
     
     [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                 
-        [[NCNetworking shared] cancelSessionsInBackground:true];
+        [[NCNetworking shared] cancelInBackground:true];
 
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {