Move parentItemIdentifierMetadata helper method to the database manager

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-13 12:34:05 +01:00
Родитель 3ec9968fc2
Коммит 1d1578447e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: C839200C384636B0
4 изменённых файлов: 24 добавлений и 25 удалений

Просмотреть файл

@ -297,6 +297,26 @@ class NextcloudFilesDatabaseManager : NSObject {
}
}
func parentItemIdentifierFromMetadata(_ metadata: NextcloudItemMetadataTable) -> NSFileProviderItemIdentifier? {
let homeServerFilesUrl = metadata.urlBase + "/remote.php/dav/files/" + metadata.userId
if metadata.serverUrl == homeServerFilesUrl {
return .rootContainer
}
guard let itemParentDirectory = parentDirectoryMetadataForItem(metadata) else {
NSLog("Could not get item parent directory metadata for metadata with ocId: %@ and fileName: %@, returning nil", metadata.ocId, metadata.fileName)
return nil
}
if let parentDirectoryMetadata = itemMetadataFromOcId(itemParentDirectory.ocId) {
return NSFileProviderItemIdentifier(parentDirectoryMetadata.ocId)
}
NSLog("Could not get item parent directory item metadata for metadata with ocId: %@ and fileName: %@, returning nil", metadata.ocId, metadata.fileName)
return nil
}
func directoryMetadata(account: String, serverUrl: String) -> NextcloudDirectoryMetadataTable? {
if let metadata = ncDatabase().objects(NextcloudDirectoryMetadataTable.self).filter("account == %@ AND serverUrl == %@", account, serverUrl).first {
return NextcloudDirectoryMetadataTable(value: metadata)

Просмотреть файл

@ -284,7 +284,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
createFileOrDirectoryLocally(metadata: itemMetadata)
}
if let parentItemIdentifier = parentItemIdentifierFromMetadata(itemMetadata) {
if let parentItemIdentifier = NextcloudFilesDatabaseManager.shared.parentItemIdentifierFromMetadata(itemMetadata) {
let item = FileProviderItem(metadata: itemMetadata, parentItemIdentifier: parentItemIdentifier, ncKit: ncKit)
NSLog("Will enumerate item with ocId: %@ and name: %@", itemMetadata.ocId, itemMetadata.fileName)
items.append(item)
@ -337,7 +337,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
var allFpItemDeletionsIdentifiers = Array(allDeletedMetadatas.map { NSFileProviderItemIdentifier($0.ocId) })
for updMetadata in allUpdatedMetadatas {
guard let parentItemIdentifier = parentItemIdentifierFromMetadata(updMetadata) else {
guard let parentItemIdentifier = NextcloudFilesDatabaseManager.shared.parentItemIdentifierFromMetadata(updMetadata) else {
NSLog("Not enumerating change for metadata: %@ %@ as could not get parent item metadata.", updMetadata.ocId, updMetadata.fileName)
continue
}

Просмотреть файл

@ -99,7 +99,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
let dbManager = NextcloudFilesDatabaseManager.shared
guard let metadata = dbManager.itemMetadataFromFileProviderItemIdentifier(identifier),
let parentItemIdentifier = parentItemIdentifierFromMetadata(metadata) else {
let parentItemIdentifier = dbManager.parentItemIdentifierFromMetadata(metadata) else {
completionHandler(nil, NSFileProviderError(.noSuchItem))
return Progress()
}
@ -176,7 +176,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
dbManager.addLocalFileMetadataFromItemMetadata(updatedMetadata)
dbManager.addItemMetadata(updatedMetadata)
guard let parentItemIdentifier = parentItemIdentifierFromMetadata(updatedMetadata) else {
guard let parentItemIdentifier = dbManager.parentItemIdentifierFromMetadata(updatedMetadata) else {
completionHandler(nil, nil, NSFileProviderError(.noSuchItem))
return
}

Просмотреть файл

@ -89,27 +89,6 @@ func createFileOrDirectoryLocally(metadata: NextcloudItemMetadataTable) {
}
}
func parentItemIdentifierFromMetadata(_ metadata: NextcloudItemMetadataTable) -> NSFileProviderItemIdentifier? {
let homeServerFilesUrl = metadata.urlBase + "/remote.php/dav/files/" + metadata.userId
if metadata.serverUrl == homeServerFilesUrl {
return .rootContainer
}
let ncDatabase = NextcloudFilesDatabaseManager.shared
guard let itemParentDirectory = ncDatabase.parentDirectoryMetadataForItem(metadata) else {
NSLog("Could not get item parent directory metadata for metadata with ocId: %@ and fileName: %@, returning nil", metadata.ocId, metadata.fileName)
return nil
}
if let parentDirectoryMetadata = ncDatabase.itemMetadataFromOcId(itemParentDirectory.ocId) {
return NSFileProviderItemIdentifier(parentDirectoryMetadata.ocId)
}
NSLog("Could not get item parent directory item metadata for metadata with ocId: %@ and fileName: %@, returning nil", metadata.ocId, metadata.fileName)
return nil
}
func isFileSynced(metadata: NextcloudItemMetadataTable) -> Bool {
guard metadata.directory else { return false }
do {