From 01b74e5794162051727be6e2f8d060d74053ed97 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 2 Oct 2023 14:44:53 +0200 Subject: [PATCH] Improvements code Signed-off-by: Marino Faggiana --- Nextcloud.xcodeproj/project.pbxproj | 4 +- iOSClient/AppDelegate.swift | 28 ++++++--- iOSClient/Favorites/NCFavorite.swift | 38 ++++++------ iOSClient/Groupfolders/NCGroupfolders.swift | 3 +- iOSClient/Main/NCActionCenter.swift | 2 +- iOSClient/NCGlobal.swift | 4 +- iOSClient/Networking/NCNetworking.swift | 64 ++++++++------------- iOSClient/Networking/NCOperationQueue.swift | 18 +++--- iOSClient/Networking/NCService.swift | 55 +++++++++--------- iOSClient/Recent/NCRecent.swift | 7 ++- 10 files changed, 109 insertions(+), 114 deletions(-) diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 70e59328fe..32731fc28d 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -4670,7 +4670,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 13; + CURRENT_PROJECT_VERSION = 14; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -4735,7 +4735,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 13; + CURRENT_PROJECT_VERSION = 14; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; diff --git a/iOSClient/AppDelegate.swift b/iOSClient/AppDelegate.swift index 384a122e49..38b3594d72 100644 --- a/iOSClient/AppDelegate.swift +++ b/iOSClient/AppDelegate.swift @@ -57,6 +57,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD var documentPickerViewController: NCDocumentPickerViewController? var timerErrorNetworking: Timer? + var isAppRefresh: Bool = false + var isAppProcessing: Bool = false + private var privacyProtectionWindow: UIWindow? var isUiTestingEnabled: Bool { @@ -323,11 +326,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD func handleAppRefresh(_ task: BGTask) { scheduleAppRefresh() - guard !account.isEmpty else { - task.setTaskCompleted(success: true) - return + guard !account.isEmpty, !isAppProcessing else { + return task.setTaskCompleted(success: true) } + isAppRefresh = true NextcloudKit.shared.setup(delegate: NCNetworking.shared) NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in @@ -335,6 +338,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD NCNetworkingProcessUpload.shared.start { items in NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Refresh task upload process with \(items) uploads") task.setTaskCompleted(success: true) + self.isAppRefresh = false } } } @@ -342,13 +346,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD func handleProcessingTask(_ task: BGTask) { scheduleAppProcessing() - guard !account.isEmpty else { - task.setTaskCompleted(success: true) - return + guard !account.isEmpty, !isAppRefresh else { + return task.setTaskCompleted(success: true) } - NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task: none") - task.setTaskCompleted(success: true) + isAppProcessing = true + NextcloudKit.shared.setup(delegate: NCNetworking.shared) + + NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in + NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task auto upload with \(items) uploads") + NCNetworkingProcessUpload.shared.start { items in + NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Processing task upload process with \(items) uploads") + task.setTaskCompleted(success: true) + self.isAppProcessing = false + } + } } // MARK: - Background Networking Session diff --git a/iOSClient/Favorites/NCFavorite.swift b/iOSClient/Favorites/NCFavorite.swift index 6a3ded859b..2272c04043 100644 --- a/iOSClient/Favorites/NCFavorite.swift +++ b/iOSClient/Favorites/NCFavorite.swift @@ -35,7 +35,7 @@ class NCFavorite: NCCollectionViewCommon { layoutKey = NCGlobal.shared.layoutViewFavorite enableSearchBar = false headerMenuButtonsView = true - headerRichWorkspaceDisable = true + headerRichWorkspaceDisable = false emptyImage = UIImage(named: "star.fill")?.image(color: NCBrandColor.shared.yellowFavorite, size: UIScreen.main.bounds.width) emptyTitle = "_favorite_no_files_" emptyDescription = "_tutorial_favorite_view_" @@ -93,37 +93,33 @@ class NCFavorite: NCCollectionViewCommon { if serverUrl.isEmpty { - NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorListingFavorite) { _, _, error in - if error != .success { - NCContentPresenter.shared.showError(error: error) - } + NextcloudKit.shared.listingFavorites(showHiddenFiles: CCUtility.getShowHiddenFiles(), + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in - DispatchQueue.main.async { - self.refreshControl.endRefreshing() - self.isReloadDataSourceNetworkInProgress = false + self.isReloadDataSourceNetworkInProgress = false + if error == .success { + NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, _, metadatas in + NCManageDatabase.shared.updateMetadatasFavorite(account: account, metadatas: metadatas) + self.reloadDataSource() + } + } else { + NCContentPresenter.shared.showError(error: error) self.reloadDataSource() } } } else { - networkReadFolder(isForced: isForced) { tableDirectory, metadatas, metadatasUpdate, metadatasDelete, error in - if error == .success, let metadatas = metadatas { + networkReadFolder(isForced: isForced) { tableDirectory, metadatas, _, _, error in + + self.isReloadDataSourceNetworkInProgress = false + if error == .success, let metadatas { for metadata in metadatas where (!metadata.directory && NCManageDatabase.shared.isDownloadMetadata(metadata, download: false)) { NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile) } } - - DispatchQueue.main.async { - self.refreshControl.endRefreshing() - self.isReloadDataSourceNetworkInProgress = false - self.richWorkspaceText = tableDirectory?.richWorkspace - if metadatasUpdate?.count ?? 0 > 0 || metadatasDelete?.count ?? 0 > 0 || isForced { - self.reloadDataSource() - } else { - self.collectionView?.reloadData() - } - } + self.richWorkspaceText = tableDirectory?.richWorkspace + self.reloadDataSource() } } } diff --git a/iOSClient/Groupfolders/NCGroupfolders.swift b/iOSClient/Groupfolders/NCGroupfolders.swift index 5539a00302..aa24cadfde 100644 --- a/iOSClient/Groupfolders/NCGroupfolders.swift +++ b/iOSClient/Groupfolders/NCGroupfolders.swift @@ -94,9 +94,8 @@ class NCGroupfolders: NCCollectionViewCommon { if serverUrl.isEmpty { let homeServerUrl = NCUtilityFileSystem.shared.getHomeServer(urlBase: self.appDelegate.urlBase, userId: self.appDelegate.userId) - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - NextcloudKit.shared.getGroupfolders(options: options) { account, results, _, error in + NextcloudKit.shared.getGroupfolders(options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, results, _, error in if error == .success, let groupfolders = results { diff --git a/iOSClient/Main/NCActionCenter.swift b/iOSClient/Main/NCActionCenter.swift index e1f49992f5..5e851c7ede 100644 --- a/iOSClient/Main/NCActionCenter.swift +++ b/iOSClient/Main/NCActionCenter.swift @@ -162,7 +162,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec } } else if metadata.directory { NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, offline: true, account: appDelegate.account) - NCNetworking.shared.synchronizationServerUrl(serverUrl, account: metadata.account, selector: NCGlobal.shared.selectorDownloadFile) + NCNetworking.shared.synchronizationServerUrl(serverUrl, account: metadata.account, selector: NCGlobal.shared.selectorSynchronizationOffline) } else { NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadOffline) { _, _ in } if let metadataLivePhoto = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) { diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 953e15f125..eba8fe5275 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -121,7 +121,7 @@ class NCGlobal: NSObject { // E2EE // let e2eePassphraseTest = "more over television factory tendency independence international intellectual impress interest sentence pony" - @objc let e2eeVersions = ["1.1", "1.2", "2.0"] + @objc let e2eeVersions = ["1.1", "1.2"] // ["1.1", "1.2", "2.0"] let e2eeVersionV11 = "1.1" let e2eeVersionV12 = "1.2" let e2eeVersionV20 = "2.0" @@ -304,6 +304,8 @@ class NCGlobal: NSObject { let selectorSaveAlbumLivePhotoMOV = "saveAlbumLivePhotoMOV" let selectorSaveAsScan = "saveAsScan" let selectorOpenDetail = "openDetail" + let selectorSynchronizationOffline = "synchronizationOffline" + let selectorSynchronizationFavorite = "synchronizationFavorite" // Metadata : Status // diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift index 9d8587e7b9..b134571273 100644 --- a/iOSClient/Networking/NCNetworking.swift +++ b/iOSClient/Networking/NCNetworking.swift @@ -839,9 +839,12 @@ class NCNetworking: NSObject, NKCommonDelegate { func readFolder(serverUrl: String, account: String, completion: @escaping (_ account: String, _ metadataFolder: tableMetadata?, _ metadatas: [tableMetadata]?, _ metadatasUpdate: [tableMetadata]?, _ metadatasLocalUpdate: [tableMetadata]?, _ metadatasDelete: [tableMetadata]?, _ error: NKError) -> Void) { - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) + NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, + depth: "1", + showHiddenFiles: CCUtility.getShowHiddenFiles(), + includeHiddenFiles: NCGlobal.shared.includeHiddenFiles, + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in - NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: CCUtility.getShowHiddenFiles(), includeHiddenFiles: NCGlobal.shared.includeHiddenFiles, options: options) { account, files, _, error in guard error == .success else { completion(account, nil, nil, nil, nil, nil, error) return @@ -912,9 +915,12 @@ class NCNetworking: NSObject, NKCommonDelegate { """ - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", requestBody: requestBody.data(using: .utf8), options: options) { account, files, _, error in + NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, + depth: "0", + requestBody: requestBody.data(using: .utf8), + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in + if error == .success, let file = files.first { completion(account, true, file, error) } else if error.errorCode == NCGlobal.shared.errorResourceNotFound { @@ -927,12 +933,15 @@ class NCNetworking: NSObject, NKCommonDelegate { // MARK: - Synchronization ServerUrl -#if !EXTENSION + func synchronizationServerUrl(_ serverUrl: String, account: String, selector: String) { - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) +#if !EXTENSION + NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, + depth: "infinity", + showHiddenFiles: CCUtility.getShowHiddenFiles(), + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in - NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "infinity", showHiddenFiles: CCUtility.getShowHiddenFiles(), options: options) { account, files, _, error in if error == .success { NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: true) { metadataFolder, metadatasFolder, metadatas in NCManageDatabase.shared.addDirectory(encrypted: metadataFolder.e2eEncrypted, favorite: metadataFolder.favorite, ocId: metadataFolder.ocId, fileId: metadataFolder.fileId, etag: metadataFolder.etag, permissions: metadataFolder.permissions, serverUrl: metadataFolder.serverUrl + "/" + metadataFolder.fileName, account: metadataFolder.account) @@ -942,24 +951,28 @@ class NCNetworking: NSObject, NKCommonDelegate { if metadata.directory { let serverUrl = metadata.serverUrl + "/" + metadata.fileName NCManageDatabase.shared.addDirectory(encrypted: metadata.e2eEncrypted, favorite: metadata.favorite, ocId: metadata.ocId, fileId: metadata.fileId, etag: metadata.etag, permissions: metadata.permissions, serverUrl: serverUrl, account: metadata.account) - } else if selector == NCGlobal.shared.selectorDownloadFile, NCManageDatabase.shared.isDownloadMetadata(metadata, download: true) { + } else if selector == NCGlobal.shared.selectorSynchronizationOffline, NCManageDatabase.shared.isDownloadMetadata(metadata, download: true) { NCOperationQueue.shared.download(metadata: metadata, selector: selector) } } } } } - } #endif + } + // MARK: - Search /// WebDAV search func searchFiles(urlBase: NCUserBaseUrl, literal: String, completion: @escaping (_ metadatas: [tableMetadata]?, _ error: NKError) -> Void) { - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) + NextcloudKit.shared.searchLiteral(serverUrl: urlBase.urlBase, + depth: "infinity", + literal: literal, + showHiddenFiles: CCUtility.getShowHiddenFiles(), + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in - NextcloudKit.shared.searchLiteral(serverUrl: urlBase.urlBase, depth: "infinity", literal: literal, showHiddenFiles: CCUtility.getShowHiddenFiles(), options: options) { account, files, _, error in guard error == .success else { return completion(nil, error) } @@ -1368,43 +1381,16 @@ class NCNetworking: NSObject, NKCommonDelegate { NextcloudKit.shared.setFavorite(fileName: fileName, favorite: favorite) { account, error in if error == .success && metadata.account == account { NCManageDatabase.shared.setMetadataFavorite(ocId: metadata.ocId, favorite: favorite) -#if !EXTENSION if favorite, metadata.directory { let serverUrl = metadata.serverUrl + "/" + metadata.fileName - self.synchronizationServerUrl(serverUrl, account: metadata.account, selector: "") + self.synchronizationServerUrl(serverUrl, account: metadata.account, selector: NCGlobal.shared.selectorSynchronizationFavorite) } -#endif NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterFavoriteFile, userInfo: ["ocId": ocId, "serverUrl": metadata.serverUrl]) } completion(error) } } - func listingFavoritescompletion(selector: String, completion: @escaping (_ account: String, _ metadatas: [tableMetadata]?, _ error: NKError) -> Void) { - - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - - NextcloudKit.shared.listingFavorites(showHiddenFiles: CCUtility.getShowHiddenFiles(), options: options) { account, files, _, error in - guard error == .success else { - completion(account, nil, error) - return - } - - NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, _, metadatas in - NCManageDatabase.shared.updateMetadatasFavorite(account: account, metadatas: metadatas) - if selector != NCGlobal.shared.selectorListingFavorite { -#if !EXTENSION - for metadata in metadatas where metadata.directory { - let serverUrl = metadata.serverUrl + "/" + metadata.fileName - self.synchronizationServerUrl(serverUrl, account: metadata.account, selector: "") - } -#endif - } - completion(account, metadatas, error) - } - } - } - // MARK: - Lock Files func lockUnlockFile(_ metadata: tableMetadata, shoulLock: Bool) { diff --git a/iOSClient/Networking/NCOperationQueue.swift b/iOSClient/Networking/NCOperationQueue.swift index 9ab2754549..4934200d09 100644 --- a/iOSClient/Networking/NCOperationQueue.swift +++ b/iOSClient/Networking/NCOperationQueue.swift @@ -241,7 +241,6 @@ class NCOperationDownloadThumbnail: ConcurrentOperation { if FileManager.default.fileExists(atPath: fileNameIconLocalPath) && FileManager.default.fileExists(atPath: fileNamePreviewLocalPath) { etagResource = metadata.etagResource } - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) NextcloudKit.shared.downloadPreview( fileNamePathOrFileId: fileNamePath, fileNamePreviewLocalPath: fileNamePreviewLocalPath, @@ -250,7 +249,7 @@ class NCOperationDownloadThumbnail: ConcurrentOperation { fileNameIconLocalPath: fileNameIconLocalPath, sizeIcon: NCGlobal.shared.sizeIcon, etag: etagResource, - options: options) { _, _, imageIcon, _, etag, error in + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, _, imageIcon, _, etag, error in if error == .success, let imageIcon = imageIcon { NCManageDatabase.shared.setMetadataEtagResource(ocId: self.metadata.ocId, etagResource: etag) @@ -300,9 +299,6 @@ class NCOperationDownloadThumbnailActivity: ConcurrentOperation { if isCancelled { self.finish() } else { - - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - NextcloudKit.shared.downloadPreview( fileNamePathOrFileId: fileNamePathOrFileId, fileNamePreviewLocalPath: fileNamePreviewLocalPath, @@ -310,7 +306,7 @@ class NCOperationDownloadThumbnailActivity: ConcurrentOperation { heightPreview: 0, etag: nil, useInternalEndpoint: false, - options: options) { _, imagePreview, _, _, _, error in + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imagePreview, _, _, _, error in if error == .success, let imagePreview = imagePreview { DispatchQueue.main.async { @@ -358,10 +354,12 @@ class NCOperationDownloadAvatar: ConcurrentOperation { if isCancelled { self.finish() } else { - - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - - NextcloudKit.shared.downloadAvatar(user: user, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: self.etag, options: options) { _, imageAvatar, _, etag, error in + NextcloudKit.shared.downloadAvatar(user: user, + fileNameLocalPath: fileNameLocalPath, + sizeImage: NCGlobal.shared.avatarSize, + avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, + etag: self.etag, + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imageAvatar, _, etag, error in if error == .success, let imageAvatar = imageAvatar, let etag = etag { NCManageDatabase.shared.addAvatar(fileName: self.fileName, etag: etag) diff --git a/iOSClient/Networking/NCService.swift b/iOSClient/Networking/NCService.swift index 7ab8ac6482..6a5e936b62 100644 --- a/iOSClient/Networking/NCService.swift +++ b/iOSClient/Networking/NCService.swift @@ -94,9 +94,7 @@ class NCService: NSObject { private func requestServerStatus() async -> Bool { - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - - switch await NextcloudKit.shared.getServerStatus(serverUrl: appDelegate.urlBase, options: options) { + switch await NextcloudKit.shared.getServerStatus(serverUrl: appDelegate.urlBase, options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { case .success(let serverInfo): if serverInfo.maintenance { let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_maintenance_mode_") @@ -114,7 +112,7 @@ class NCService: NSObject { return false } - let resultUserProfile = await NextcloudKit.shared.getUserProfile(options: options) + let resultUserProfile = await NextcloudKit.shared.getUserProfile(options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) if resultUserProfile.error == .success, let userProfile = resultUserProfile.userProfile { NCManageDatabase.shared.setAccountUserProfile(account: resultUserProfile.account, userProfile: userProfile) return true @@ -135,10 +133,18 @@ class NCService: NSObject { func synchronize() { - NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] start synchronize") + NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] start synchronize Favorite") + NextcloudKit.shared.listingFavorites(showHiddenFiles: CCUtility.getShowHiddenFiles(), + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in - NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorReadFile) { _, _, _ in } - self.synchronizeOffline(account: appDelegate.account) + guard error == .success else { return } + NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, _, metadatas in + NCManageDatabase.shared.updateMetadatasFavorite(account: account, metadatas: metadatas) + } + NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] end synchronize Favorite") + NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] start synchronize Offline") + self.synchronizeOffline(account: account) + } } func getAvatar() { @@ -146,9 +152,13 @@ class NCService: NSObject { let fileName = appDelegate.userBaseUrl + "-" + self.appDelegate.user + ".png" let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - NextcloudKit.shared.downloadAvatar(user: appDelegate.userId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag, options: options) { _, _, _, etag, error in + NextcloudKit.shared.downloadAvatar(user: appDelegate.userId, + fileNameLocalPath: fileNameLocalPath, + sizeImage: NCGlobal.shared.avatarSize, + avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, + etag: etag, + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, _, _, etag, error in if let etag = etag, error == .success { NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag) @@ -162,9 +172,7 @@ class NCService: NSObject { private func requestServerCapabilities() { guard !appDelegate.account.isEmpty else { return } - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - - NextcloudKit.shared.getCapabilities(options: options) { account, data, error in + NextcloudKit.shared.getCapabilities(options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, data, error in guard error == .success, let data = data else { NCBrandColor.shared.settingThemingColor(account: account) return @@ -204,7 +212,7 @@ class NCService: NSObject { // External file Server if NCGlobal.shared.capabilityExternalSites { - NextcloudKit.shared.getExternalSite(options: options) { account, externalSites, _, error in + NextcloudKit.shared.getExternalSite(options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, externalSites, _, error in if error == .success && account == self.appDelegate.account { NCManageDatabase.shared.deleteExternalSites(account: account) for externalSite in externalSites { @@ -218,7 +226,7 @@ class NCService: NSObject { // User Status if NCGlobal.shared.capabilityUserStatusEnabled { - NextcloudKit.shared.getUserStatus(options: options) { account, clearAt, icon, message, messageId, messageIsPredefined, status, statusIsUserDefined, userId, _, error in + NextcloudKit.shared.getUserStatus(options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, clearAt, icon, message, messageId, messageIsPredefined, status, statusIsUserDefined, userId, _, error in if error == .success && account == self.appDelegate.account && userId == self.appDelegate.userId { NCManageDatabase.shared.setAccountUserStatus(userStatusClearAt: clearAt, userStatusIcon: icon, userStatusMessage: message, userStatusMessageId: messageId, userStatusMessageIsPredefined: messageIsPredefined, userStatusStatus: status, userStatusStatusIsUserDefined: statusIsUserDefined, account: account) } @@ -264,9 +272,7 @@ class NCService: NSObject { } } - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - - NextcloudKit.shared.getDashboardWidget(options: options) { account, dashboardWidgets, data, error in + NextcloudKit.shared.getDashboardWidget(options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, dashboardWidgets, data, error in Task { if error == .success, let dashboardWidgets = dashboardWidgets { NCManageDatabase.shared.addDashboardWidget(account: account, dashboardWidgets: dashboardWidgets) @@ -287,26 +293,21 @@ class NCService: NSObject { @objc func synchronizeOffline(account: String) { - // Synchronize Offline Directory + // Synchronize Directory if let directories = NCManageDatabase.shared.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", account), sorted: "serverUrl", ascending: true) { for directory: tableDirectory in directories { - guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(directory.ocId) else { - continue - } - let serverUrl = metadata.serverUrl + "/" + metadata.fileName - NCNetworking.shared.synchronizationServerUrl(serverUrl, account: metadata.account, selector: NCGlobal.shared.selectorDownloadFile) + NCNetworking.shared.synchronizationServerUrl(directory.serverUrl, account: account, selector: NCGlobal.shared.selectorSynchronizationOffline) } } - // Synchronize Offline Files + // Synchronize Files let files = NCManageDatabase.shared.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", account), sorted: "fileName", ascending: true) for file: tableLocalFile in files { - guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(file.ocId) else { - continue - } + guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(file.ocId) else { continue } if NCManageDatabase.shared.isDownloadMetadata(metadata, download: true) { NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile) } } + NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] end synchronize offline") } } diff --git a/iOSClient/Recent/NCRecent.swift b/iOSClient/Recent/NCRecent.swift index 5f3a166adf..b0ba14d105 100644 --- a/iOSClient/Recent/NCRecent.swift +++ b/iOSClient/Recent/NCRecent.swift @@ -149,9 +149,10 @@ class NCRecent: NCCollectionViewCommon { isReloadDataSourceNetworkInProgress = true collectionView?.reloadData() - let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - - NextcloudKit.shared.searchBodyRequest(serverUrl: appDelegate.urlBase, requestBody: requestBody, showHiddenFiles: CCUtility.getShowHiddenFiles(), options: options) { account, files, _, error in + NextcloudKit.shared.searchBodyRequest(serverUrl: appDelegate.urlBase, + requestBody: requestBody, + showHiddenFiles: CCUtility.getShowHiddenFiles(), + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { account, files, _, error in if error == .success { NCManageDatabase.shared.convertFilesToMetadatas(files, useMetadataFolder: false) { _, metadatasFolder, metadatas in