diff --git a/File Provider Extension/FileProviderExtension.swift b/File Provider Extension/FileProviderExtension.swift index b094be1174..e07d6d45b4 100644 --- a/File Provider Extension/FileProviderExtension.swift +++ b/File Provider Extension/FileProviderExtension.swift @@ -254,19 +254,17 @@ class FileProviderExtension: NSFileProviderExtension { selector: "", status: NCGlobal.shared.metadataStatusUploading) - DispatchQueue.main.asyncAfter(deadline: .now() + 1) { - if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, - fileNameLocalPath: url.path, - dateCreationFile: nil, - dateModificationFile: nil, - overwrite: true, - account: metadata.account, - sessionIdentifier: metadata.session) { - self.database.setMetadataSession(ocId: metadata.ocId, - sessionTaskIdentifier: task.taskIdentifier, - status: NCGlobal.shared.metadataStatusUploading) - fileProviderData.shared.fileProviderManager.register(task, forItemWithIdentifier: NSFileProviderItemIdentifier(metadata.fileId)) { _ in } - } + if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, + fileNameLocalPath: url.path, + dateCreationFile: nil, + dateModificationFile: nil, + overwrite: true, + account: metadata.account, + sessionIdentifier: NCNetworking.shared.sessionUploadBackgroundExt) { + self.database.setMetadataSession(ocId: metadata.ocId, + sessionTaskIdentifier: task.taskIdentifier, + status: NCGlobal.shared.metadataStatusUploading) + fileProviderData.shared.fileProviderManager.register(task, forItemWithIdentifier: NSFileProviderItemIdentifier(metadata.fileId)) { _ in } } } diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 72fd74e845..21629c71f1 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -5487,7 +5487,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 11; + CURRENT_PROJECT_VERSION = 2; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -5514,7 +5514,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 6.1.7; + MARKETING_VERSION = 6.1.8; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-v"; OTHER_LDFLAGS = ""; @@ -5553,7 +5553,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 11; + CURRENT_PROJECT_VERSION = 2; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -5577,7 +5577,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 6.1.7; + MARKETING_VERSION = 6.1.8; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-v"; OTHER_LDFLAGS = ""; diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 61809d312e..246bff4cc3 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -615,6 +615,18 @@ extension NCManageDatabase { } } + func deleteMetadataOcIds(_ ocIds: [String]) { + do { + let realm = try Realm() + try realm.write { + let results = realm.objects(tableMetadata.self).filter("ocId IN %@", ocIds) + realm.delete(results) + } + } catch let error as NSError { + NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not access database: \(error)") + } + } + func deleteMetadatas(_ metadatas: [tableMetadata]) { do { let realm = try Realm() diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index b1459ba80a..8de4ed4684 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -36,8 +36,8 @@ class NCMedia: UIViewController { @IBOutlet weak var menuButton: UIButton! @IBOutlet weak var gradientView: UIView! - let semaphore = DispatchSemaphore(value: 1) - var hasRunSearchMedia: Bool = false + let semaphoreSearchMedia = DispatchSemaphore(value: 1) + let semaphoreNotificationCenter = DispatchSemaphore(value: 1) let layout = NCMediaLayout() var layoutType = NCGlobal.shared.mediaLayoutRatio @@ -54,6 +54,8 @@ class NCMedia: UIViewController { var isEditMode = false var fileSelect: [String] = [] var filesExists: [String] = [] + var ocIdDoNotExists: [String] = [] + var hasRunSearchMedia: Bool = false var attributesZoomIn: UIMenuElement.Attributes = [] var attributesZoomOut: UIMenuElement.Attributes = [] let gradient: CAGradientLayer = CAGradientLayer() @@ -255,12 +257,21 @@ class NCMedia: UIViewController { guard let userInfo = notification.userInfo as NSDictionary?, let error = userInfo["error"] as? NKError else { return } - if error.errorCode == self.global.errorResourceNotFound, let ocId = userInfo["ocId"] as? String { + semaphoreNotificationCenter.wait() + + if error.errorCode == self.global.errorResourceNotFound, + let ocId = userInfo["ocId"] as? String { self.database.deleteMetadataOcId(ocId) - self.loadDataSource() + self.loadDataSource { + self.semaphoreNotificationCenter.signal() + } } else if error != .success { NCContentPresenter().showError(error: error) - self.loadDataSource() + self.loadDataSource { + self.semaphoreNotificationCenter.signal() + } + } else { + semaphoreNotificationCenter.signal() } } @@ -271,28 +282,21 @@ class NCMedia: UIViewController { @objc func fileExists(_ notification: NSNotification) { guard let userInfo = notification.userInfo as NSDictionary?, let ocId = userInfo["ocId"] as? String, - let fileExists = userInfo["fileExists"] as? Bool else { return } - var indexPaths: [IndexPath] = [] + let fileExists = userInfo["fileExists"] as? Bool + else { + return + } filesExists.append(ocId) - if !fileExists { - if let index = dataSource.metadatas.firstIndex(where: {$0.ocId == ocId}), - index < self.dataSource.metadatas.count, - let cell = collectionView.cellForItem(at: IndexPath(row: index, section: 0)) as? NCMediaCell, - dataSource.metadatas[index].ocId == cell.ocId { - indexPaths.append(IndexPath(row: index, section: 0)) - } - - dataSource.removeMetadata([ocId]) - database.deleteMetadataOcId(ocId) + ocIdDoNotExists.append(ocId) + } - if !indexPaths.isEmpty, - !indexPaths.filter({ $0.item < self.dataSource.metadatas.count }).isEmpty { - collectionView.deleteItems(at: indexPaths) - } else { - collectionViewReloadData() - } + if NCNetworking.shared.fileExistsQueue.operationCount == 0, !ocIdDoNotExists.isEmpty { + dataSource.removeMetadata(ocIdDoNotExists) + database.deleteMetadataOcIds(ocIdDoNotExists) + ocIdDoNotExists.removeAll() + collectionViewReloadData() } } diff --git a/iOSClient/Media/NCMediaDataSource.swift b/iOSClient/Media/NCMediaDataSource.swift index 48c469d956..cf59a79031 100644 --- a/iOSClient/Media/NCMediaDataSource.swift +++ b/iOSClient/Media/NCMediaDataSource.swift @@ -26,13 +26,14 @@ import NextcloudKit import RealmSwift extension NCMedia { - func loadDataSource() { + func loadDataSource(completion: @escaping () -> Void = {}) { let session = self.session DispatchQueue.global().async { if let metadatas = self.database.getResultsMetadatas(predicate: self.imageCache.getMediaPredicate(filterLivePhotoFile: true, session: session, showOnlyImages: self.showOnlyImages, showOnlyVideos: self.showOnlyVideos), sortedByKeyPath: "date") { self.dataSource = NCMediaDataSource(metadatas: metadatas) } self.collectionViewReloadData() + completion() } } @@ -61,7 +62,7 @@ extension NCMedia { let visibleCells = self.collectionView?.indexPathsForVisibleItems.sorted(by: { $0.row < $1.row }).compactMap({ self.collectionView?.cellForItem(at: $0) }) DispatchQueue.global(qos: .background).async { - self.semaphore.wait() + self.semaphoreSearchMedia.wait() self.hasRunSearchMedia = true var lessDate = Date.distantFuture @@ -156,7 +157,7 @@ extension NCMedia { self.collectionViewReloadData() } - self.semaphore.signal() + self.semaphoreSearchMedia.signal() DispatchQueue.main.async { self.activityIndicator.stopAnimating() diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index 22625208b6..2dfa2bc1ed 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -841,12 +841,13 @@ class NCOperationFileExists: ConcurrentOperation, @unchecked Sendable { requestBody: nil, account: account, options: options) { _, _, _, error in + self.finish() + if error == .success { NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterFileExists, userInfo: ["ocId": self.ocId, "fileExists": true]) } else if error.errorCode == NCGlobal.shared.errorResourceNotFound { NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterFileExists, userInfo: ["ocId": self.ocId, "fileExists": false]) } - self.finish() } } } diff --git a/iOSClient/Supporting Files/de.lproj/Localizable.strings b/iOSClient/Supporting Files/de.lproj/Localizable.strings index b6f96e1ca6..ef853129e3 100644 Binary files a/iOSClient/Supporting Files/de.lproj/Localizable.strings and b/iOSClient/Supporting Files/de.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/eu.lproj/Localizable.strings b/iOSClient/Supporting Files/eu.lproj/Localizable.strings index ebd8d632c4..1ce86dd4b8 100644 Binary files a/iOSClient/Supporting Files/eu.lproj/Localizable.strings and b/iOSClient/Supporting Files/eu.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ga.lproj/Localizable.strings b/iOSClient/Supporting Files/ga.lproj/Localizable.strings index bfd6cad0ce..7ce3a1ba9e 100644 Binary files a/iOSClient/Supporting Files/ga.lproj/Localizable.strings and b/iOSClient/Supporting Files/ga.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ja-JP.lproj/Localizable.strings b/iOSClient/Supporting Files/ja-JP.lproj/Localizable.strings index 572eceb43f..8070e396d4 100644 Binary files a/iOSClient/Supporting Files/ja-JP.lproj/Localizable.strings and b/iOSClient/Supporting Files/ja-JP.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ko.lproj/Localizable.strings b/iOSClient/Supporting Files/ko.lproj/Localizable.strings index c71cbb2e7d..f15d3967e7 100644 Binary files a/iOSClient/Supporting Files/ko.lproj/Localizable.strings and b/iOSClient/Supporting Files/ko.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/pt-BR.lproj/Localizable.strings b/iOSClient/Supporting Files/pt-BR.lproj/Localizable.strings index bd8b5ddd06..6c90f773e8 100644 Binary files a/iOSClient/Supporting Files/pt-BR.lproj/Localizable.strings and b/iOSClient/Supporting Files/pt-BR.lproj/Localizable.strings differ