From ad12a6f5f7e7f0a8181db6cd5027fe8398780820 Mon Sep 17 00:00:00 2001 From: marinofaggiana Date: Wed, 25 May 2022 17:14:12 +0200 Subject: [PATCH] coding Signed-off-by: marinofaggiana --- .../FileProviderExtension.swift | 2 +- Nextcloud.xcodeproj/project.pbxproj | 2 +- Share/NCShareExtension.swift | 3 +-- iOSClient/Data/NCDatabase.swift | 2 ++ .../Data/NCManageDatabase+Metadata.swift | 21 +++++++++++++------ .../NCCreateFormUploadAssets.swift | 4 ++-- .../NCCreateFormUploadDocuments.swift | 6 +++--- .../NCCreateFormUploadScanDocument.swift | 2 +- .../NCCreateFormUploadVoiceNote.swift | 2 +- iOSClient/Main/NCPickerViewController.swift | 2 +- iOSClient/NCGlobal.swift | 2 +- iOSClient/Networking/NCAutoUpload.swift | 4 ++-- iOSClient/Networking/NCNetworking.swift | 7 ++++++- iOSClient/Utility/NCUserBaseUrl.swift | 1 + .../NCViewerQuickLook/NCViewerQuickLook.swift | 3 +-- 15 files changed, 39 insertions(+), 24 deletions(-) diff --git a/File Provider Extension/FileProviderExtension.swift b/File Provider Extension/FileProviderExtension.swift index 2e003945fd..9643b4fddf 100644 --- a/File Provider Extension/FileProviderExtension.swift +++ b/File Provider Extension/FileProviderExtension.swift @@ -347,7 +347,7 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate { fileURL.stopAccessingSecurityScopedResource() - let metadata = NCManageDatabase.shared.createMetadata(account: fileProviderData.shared.account, user: fileProviderData.shared.user, userId: fileProviderData.shared.userId, fileName: fileName, fileNameView: fileName, ocId: ocIdTemp, serverUrl: tableDirectory.serverUrl, urlBase: fileProviderData.shared.accountUrlBase, url: "", contentType: "", livePhoto: false) + let metadata = NCManageDatabase.shared.createMetadata(account: fileProviderData.shared.account, user: fileProviderData.shared.user, userId: fileProviderData.shared.userId, fileName: fileName, fileNameView: fileName, ocId: ocIdTemp, serverUrl: tableDirectory.serverUrl, urlBase: fileProviderData.shared.accountUrlBase, url: "", contentType: "") metadata.session = NCNetworking.shared.sessionIdentifierBackgroundExtension metadata.size = size metadata.status = NCGlobal.shared.metadataStatusUploading diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index f711d0f5e3..6f5b7e9ca9 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -3284,7 +3284,7 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/nextcloud/ios-communication-library/"; requirement = { - branch = develop; + branch = unifiedSearch; kind = branch; }; }; diff --git a/Share/NCShareExtension.swift b/Share/NCShareExtension.swift index 831dc455cf..597dae5205 100644 --- a/Share/NCShareExtension.swift +++ b/Share/NCShareExtension.swift @@ -303,8 +303,7 @@ extension NCShareExtension { fileName: fileName, fileNameView: fileName, ocId: ocId, serverUrl: serverUrl, urlBase: activeAccount.urlBase, url: "", - contentType: "", - livePhoto: false) + contentType: "") metadata.session = NCCommunicationCommon.shared.sessionIdentifierUpload metadata.sessionSelector = NCGlobal.shared.selectorUploadFileShareExtension metadata.size = NCUtilityFileSystem.shared.getFileSize(filePath: toPath) diff --git a/iOSClient/Data/NCDatabase.swift b/iOSClient/Data/NCDatabase.swift index 202436ca92..5dd8ae618d 100644 --- a/iOSClient/Data/NCDatabase.swift +++ b/iOSClient/Data/NCDatabase.swift @@ -386,6 +386,7 @@ class tableMetadata: Object, NCUserBaseUrl { @objc dynamic var iconName = "" @objc dynamic var livePhoto: Bool = false @objc dynamic var mountType = "" + @objc dynamic var name = "" @objc dynamic var note = "" @objc dynamic var ocId = "" @objc dynamic var ownerId = "" @@ -413,6 +414,7 @@ class tableMetadata: Object, NCUserBaseUrl { let shareType = List() @objc dynamic var size: Int64 = 0 @objc dynamic var status: Int = 0 + @objc dynamic var subline: String? @objc dynamic var trashbinFileName = "" @objc dynamic var trashbinOriginalLocation = "" @objc dynamic var trashbinDeletionTime = NSDate() diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 2c115ce6db..1f29e1d7cf 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -60,6 +60,7 @@ extension NCManageDatabase { metadata.iconName = file.iconName metadata.livePhoto = file.livePhoto metadata.mountType = file.mountType + metadata.name = file.name metadata.note = file.note metadata.ocId = file.ocId metadata.ownerId = file.ownerId @@ -163,30 +164,38 @@ extension NCManageDatabase { completion(metadataFolder, metadataFolders, metadatas) } - @objc func createMetadata(account: String, user: String, userId: String, fileName: String, fileNameView: String, ocId: String, serverUrl: String, urlBase: String, url: String, contentType: String, livePhoto: Bool) -> tableMetadata { + @objc func createMetadata(account: String, user: String, userId: String, fileName: String, fileNameView: String, ocId: String, serverUrl: String, urlBase: String, url: String, contentType: String, isLivePhoto: Bool = false, isUrl: Bool = false, name: String = "Files", subline: String? = nil) -> tableMetadata { let metadata = tableMetadata() - let resultInternalType = NCCommunicationCommon.shared.getInternalType(fileName: fileName, mimeType: contentType, directory: false) + if isUrl { + metadata.contentType = "text/uri-list" + metadata.iconName = NCCommunicationCommon.typeIconFile.url.rawValue + metadata.classFile = NCCommunicationCommon.typeClassFile.url.rawValue + } else { + let (mimeType, classFile, iconName, _, _, _) = NCCommunicationCommon.shared.getInternalType(fileName: fileName, mimeType: contentType, directory: false) + metadata.contentType = mimeType + metadata.iconName = iconName + metadata.classFile = classFile + } let fileName = fileName.trimmingCharacters(in: .whitespacesAndNewlines) metadata.account = account metadata.chunk = false - metadata.contentType = resultInternalType.mimeType metadata.creationDate = Date() as NSDate metadata.date = Date() as NSDate metadata.hasPreview = true - metadata.iconName = resultInternalType.iconName metadata.etag = ocId metadata.ext = (fileName as NSString).pathExtension.lowercased() metadata.fileName = fileName metadata.fileNameView = fileName metadata.fileNameWithoutExt = (fileName as NSString).deletingPathExtension - metadata.livePhoto = livePhoto + metadata.livePhoto = isLivePhoto + metadata.name = name metadata.ocId = ocId metadata.permissions = "RGDNVW" metadata.serverUrl = serverUrl - metadata.classFile = resultInternalType.classFile + metadata.subline = subline metadata.uploadDate = Date() as NSDate metadata.url = url metadata.urlBase = urlBase diff --git a/iOSClient/Main/Create cloud/NCCreateFormUploadAssets.swift b/iOSClient/Main/Create cloud/NCCreateFormUploadAssets.swift index adcd666d2f..b5cb3c03e4 100644 --- a/iOSClient/Main/Create cloud/NCCreateFormUploadAssets.swift +++ b/iOSClient/Main/Create cloud/NCCreateFormUploadAssets.swift @@ -410,7 +410,7 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate { continue } - let metadataForUpload = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: fileName, fileNameView: fileName, ocId: NSUUID().uuidString, serverUrl: serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", livePhoto: livePhoto) + let metadataForUpload = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: fileName, fileNameView: fileName, ocId: NSUUID().uuidString, serverUrl: serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", isLivePhoto: livePhoto) metadataForUpload.assetLocalIdentifier = asset.localIdentifier metadataForUpload.session = self.session @@ -427,7 +427,7 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate { CCUtility.extractLivePhotoAsset(asset, filePath: filePath) { url in if let url = url { let fileSize = NCUtilityFileSystem.shared.getFileSize(filePath: url.path) - let metadataMOVForUpload = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: fileNameMove, fileNameView: fileNameMove, ocId: ocId, serverUrl: serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", livePhoto: livePhoto) + let metadataMOVForUpload = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: fileNameMove, fileNameView: fileNameMove, ocId: ocId, serverUrl: serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", isLivePhoto: livePhoto) metadataForUpload.livePhoto = true metadataMOVForUpload.livePhoto = true diff --git a/iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift b/iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift index 3132159132..e96f5d4f60 100644 --- a/iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift +++ b/iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift @@ -284,7 +284,7 @@ import XLForm if NCManageDatabase.shared.getMetadataConflict(account: appDelegate.account, serverUrl: serverUrl, fileName: String(describing: fileNameForm)) != nil { - let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, user: appDelegate.user, userId: appDelegate.userId, fileName: String(describing: fileNameForm), fileNameView: String(describing: fileNameForm), ocId: "", serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "", livePhoto: false) + let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, user: appDelegate.user, userId: appDelegate.userId, fileName: String(describing: fileNameForm), fileNameView: String(describing: fileNameForm), ocId: "", serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "") guard let conflictViewController = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict else { return } conflictViewController.textLabelDetailNewFile = NSLocalizedString("_now_", comment: "") @@ -340,7 +340,7 @@ import XLForm let results = NCCommunicationCommon.shared.getInternalType(fileName: fileName, mimeType: "", directory: false) self.dismiss(animated: true, completion: { - let metadata = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: fileName, fileNameView: fileName, ocId: CCUtility.createRandomString(12), serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: url ?? "", contentType: results.mimeType, livePhoto: false) + let metadata = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: fileName, fileNameView: fileName, ocId: CCUtility.createRandomString(12), serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: url ?? "", contentType: results.mimeType) if let viewController = self.appDelegate.activeViewController { NCViewer.shared.view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: nil) @@ -365,7 +365,7 @@ import XLForm self.dismiss(animated: true, completion: { let createFileName = (fileName as NSString).deletingPathExtension + "." + self.fileNameExtension - let metadata = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: createFileName, fileNameView: createFileName, ocId: CCUtility.createRandomString(12), serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: url!, contentType: "", livePhoto: false) + let metadata = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: createFileName, fileNameView: createFileName, ocId: CCUtility.createRandomString(12), serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: url!, contentType: "") if let viewController = self.appDelegate.activeViewController { NCViewer.shared.view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: nil) diff --git a/iOSClient/Main/Create cloud/NCCreateFormUploadScanDocument.swift b/iOSClient/Main/Create cloud/NCCreateFormUploadScanDocument.swift index 565d3fc2b0..4ce5caab88 100644 --- a/iOSClient/Main/Create cloud/NCCreateFormUploadScanDocument.swift +++ b/iOSClient/Main/Create cloud/NCCreateFormUploadScanDocument.swift @@ -414,7 +414,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC } // Create metadata for upload - let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, user: appDelegate.user, userId: appDelegate.userId, fileName: fileNameSave, fileNameView: fileNameSave, ocId: UUID().uuidString, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "", livePhoto: false) + let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, user: appDelegate.user, userId: appDelegate.userId, fileName: fileNameSave, fileNameView: fileNameSave, ocId: UUID().uuidString, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "") metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile diff --git a/iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift b/iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift index 795dadeddc..3066f0d549 100644 --- a/iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift +++ b/iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift @@ -240,7 +240,7 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud fileNameSave = (name as! NSString).deletingPathExtension + ".m4a" } - let metadataForUpload = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: fileNameSave, fileNameView: fileNameSave, ocId: UUID().uuidString, serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "", livePhoto: false) + let metadataForUpload = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: fileNameSave, fileNameView: fileNameSave, ocId: UUID().uuidString, serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: "", contentType: "") metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile diff --git a/iOSClient/Main/NCPickerViewController.swift b/iOSClient/Main/NCPickerViewController.swift index a4fddfa018..b43118c12e 100644 --- a/iOSClient/Main/NCPickerViewController.swift +++ b/iOSClient/Main/NCPickerViewController.swift @@ -150,7 +150,7 @@ class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate { if NCUtilityFileSystem.shared.copyFile(atPath: atPath, toPath: toPath) { - let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, user: appDelegate.user, userId: appDelegate.userId, fileName: fileName, fileNameView: fileName, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "", livePhoto: false) + let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, user: appDelegate.user, userId: appDelegate.userId, fileName: fileName, fileNameView: fileName, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "") metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index af5f23ab26..e46a2d628b 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -112,7 +112,7 @@ class NCGlobal: NSObject { // Database Realm // let databaseDefault = "nextcloud.realm" - let databaseSchemaVersion: UInt64 = 222 + let databaseSchemaVersion: UInt64 = 224 // Intro selector // diff --git a/iOSClient/Networking/NCAutoUpload.swift b/iOSClient/Networking/NCAutoUpload.swift index 2e080974c8..5e77971041 100644 --- a/iOSClient/Networking/NCAutoUpload.swift +++ b/iOSClient/Networking/NCAutoUpload.swift @@ -165,7 +165,7 @@ class NCAutoUpload: NSObject { } else { /* INSERT METADATA FOR UPLOAD */ - let metadataForUpload = NCManageDatabase.shared.createMetadata(account: account.account, user: account.user, userId: account.userId, fileName: fileName, fileNameView: fileName, ocId: NSUUID().uuidString, serverUrl: serverUrl, urlBase: account.urlBase, url: "", contentType: "", livePhoto: livePhoto) + let metadataForUpload = NCManageDatabase.shared.createMetadata(account: account.account, user: account.user, userId: account.userId, fileName: fileName, fileNameView: fileName, ocId: NSUUID().uuidString, serverUrl: serverUrl, urlBase: account.urlBase, url: "", contentType: "", isLivePhoto: livePhoto) metadataForUpload.assetLocalIdentifier = asset.localIdentifier metadataForUpload.session = session metadataForUpload.sessionSelector = selector @@ -195,7 +195,7 @@ class NCAutoUpload: NSObject { CCUtility.extractLivePhotoAsset(asset, filePath: filePath) { url in if url != nil { - let metadataForUpload = NCManageDatabase.shared.createMetadata(account: account.account, user: account.user, userId: account.userId, fileName: fileName, fileNameView: fileName, ocId: ocId, serverUrl: serverUrl, urlBase: account.urlBase, url: "", contentType: "", livePhoto: livePhoto) + let metadataForUpload = NCManageDatabase.shared.createMetadata(account: account.account, user: account.user, userId: account.userId, fileName: fileName, fileNameView: fileName, ocId: ocId, serverUrl: serverUrl, urlBase: account.urlBase, url: "", contentType: "", isLivePhoto: livePhoto) metadataForUpload.session = session metadataForUpload.sessionSelector = selector metadataForUpload.size = NCUtilityFileSystem.shared.getFileSize(filePath: filePath) diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift index eb745f7426..2ac0a50dad 100644 --- a/iOSClient/Networking/NCNetworking.swift +++ b/iOSClient/Networking/NCNetworking.swift @@ -936,11 +936,16 @@ import Queuer } NCCommunication.shared.unifiedSearch(term: literal) { provider in - ["files", "fulltextsearch"].contains(provider.id) + ["contacts", "files", "fulltextsearch", "talk-conversations",].contains(provider.id) } update: { partialResult, provider, errorCode, errorDescription in guard let partialResult = partialResult else { return } switch provider.id { + case "contacts", "talk-conversations": + partialResult.entries.forEach({ entry in + let metadata = NCManageDatabase.shared.createMetadata(account: urlBase.account, user: urlBase.user, userId: urlBase.userId, fileName: entry.title, fileNameView: entry.title, ocId: NSUUID().uuidString, serverUrl: "", urlBase: urlBase.urlBase, url: entry.resourceURL, contentType: "", isUrl: true, name: partialResult.name, subline: entry.subline) + print("") + }) case "files": partialResult.entries.forEach({ entry in if let fileId = entry.fileId, diff --git a/iOSClient/Utility/NCUserBaseUrl.swift b/iOSClient/Utility/NCUserBaseUrl.swift index b2f09076ce..f92b2ae9f7 100644 --- a/iOSClient/Utility/NCUserBaseUrl.swift +++ b/iOSClient/Utility/NCUserBaseUrl.swift @@ -27,6 +27,7 @@ import Foundation var user: String { get } var urlBase: String { get } var account: String { get } + var userId: String { get } } public extension NCUserBaseUrl { diff --git a/iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift b/iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift index cff53169d4..ca6faa0bbb 100644 --- a/iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift +++ b/iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift @@ -147,8 +147,7 @@ extension NCViewerQuickLook: QLPreviewControllerDataSource, QLPreviewControllerD serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, url: url.path, - contentType: "", - livePhoto: false) + contentType: "") metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile