mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-24 14:05:58 +03:00
Cllean up function and method calls in File Provider Extension
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
d707ccc5b3
commit
7ac5f38178
6 changed files with 46 additions and 21 deletions
|
@ -28,8 +28,10 @@ extension NextcloudFilesDatabaseManager {
|
|||
of: placeholderSeparator, with: problematicSeparator)
|
||||
|
||||
if let metadata = ncDatabase().objects(NextcloudItemMetadataTable.self).filter(
|
||||
"account == %@ AND serverUrl == %@ AND fileName == %@ AND directory == true", account,
|
||||
directoryItemServerUrl, directoryItemFileName
|
||||
"account == %@ AND serverUrl == %@ AND fileName == %@ AND directory == true",
|
||||
account,
|
||||
directoryItemServerUrl,
|
||||
directoryItemFileName
|
||||
).first {
|
||||
return NextcloudItemMetadataTable(value: metadata)
|
||||
}
|
||||
|
|
|
@ -123,7 +123,9 @@ class NextcloudFilesDatabaseManager: NSObject {
|
|||
-> [NextcloudItemMetadataTable]
|
||||
{
|
||||
let metadatas = ncDatabase().objects(NextcloudItemMetadataTable.self).filter(
|
||||
"account == %@ AND serverUrl == %@ AND status == %@", account, serverUrl,
|
||||
"account == %@ AND serverUrl == %@ AND status == %@",
|
||||
account,
|
||||
serverUrl,
|
||||
status.rawValue)
|
||||
return sortedItemMetadatas(metadatas)
|
||||
}
|
||||
|
@ -216,7 +218,9 @@ class NextcloudFilesDatabaseManager: NSObject {
|
|||
}
|
||||
|
||||
func updateItemMetadatas(
|
||||
account: String, serverUrl: String, updatedMetadatas: [NextcloudItemMetadataTable],
|
||||
account: String,
|
||||
serverUrl: String,
|
||||
updatedMetadatas: [NextcloudItemMetadataTable],
|
||||
updateDirectoryEtags: Bool
|
||||
) -> (
|
||||
newMetadatas: [NextcloudItemMetadataTable]?,
|
||||
|
@ -227,7 +231,9 @@ class NextcloudFilesDatabaseManager: NSObject {
|
|||
|
||||
do {
|
||||
let existingMetadatas = database.objects(NextcloudItemMetadataTable.self).filter(
|
||||
"account == %@ AND serverUrl == %@ AND status == %@", account, serverUrl,
|
||||
"account == %@ AND serverUrl == %@ AND status == %@",
|
||||
account,
|
||||
serverUrl,
|
||||
NextcloudItemMetadataTable.Status.normal.rawValue)
|
||||
|
||||
let metadatasToDelete = processItemMetadatasToDelete(
|
||||
|
@ -249,7 +255,8 @@ class NextcloudFilesDatabaseManager: NSObject {
|
|||
|
||||
for metadata in directoriesNeedingRename {
|
||||
if let updatedDirectoryChildren = renameDirectoryAndPropagateToChildren(
|
||||
ocId: metadata.ocId, newServerUrl: metadata.serverUrl,
|
||||
ocId: metadata.ocId,
|
||||
newServerUrl: metadata.serverUrl,
|
||||
newFileName: metadata.fileName)
|
||||
{
|
||||
metadatasToUpdate += updatedDirectoryChildren
|
||||
|
@ -270,7 +277,8 @@ class NextcloudFilesDatabaseManager: NSObject {
|
|||
}
|
||||
|
||||
return (
|
||||
newMetadatas: metadatasToCreate, updatedMetadatas: metadatasToUpdate,
|
||||
newMetadatas: metadatasToCreate,
|
||||
updatedMetadatas: metadatasToUpdate,
|
||||
deletedMetadatas: metadatasToDelete
|
||||
)
|
||||
} catch {
|
||||
|
@ -282,7 +290,8 @@ class NextcloudFilesDatabaseManager: NSObject {
|
|||
}
|
||||
|
||||
func setStatusForItemMetadata(
|
||||
_ metadata: NextcloudItemMetadataTable, status: NextcloudItemMetadataTable.Status,
|
||||
_ metadata: NextcloudItemMetadataTable,
|
||||
status: NextcloudItemMetadataTable.Status,
|
||||
completionHandler: @escaping (_ updatedMetadata: NextcloudItemMetadataTable?) -> Void
|
||||
) {
|
||||
let database = ncDatabase()
|
||||
|
|
|
@ -104,8 +104,11 @@ extension NextcloudItemMetadataTable {
|
|||
var metadatas: [NextcloudItemMetadataTable] = []
|
||||
|
||||
let conversionQueue = DispatchQueue(
|
||||
label: "nkFileToMetadataConversionQueue", qos: .userInitiated, attributes: .concurrent)
|
||||
let appendQueue = DispatchQueue(label: "metadataAppendQueue", qos: .userInitiated) // Serial queue
|
||||
label: "nkFileToMetadataConversionQueue",
|
||||
qos: .userInitiated,
|
||||
attributes: .concurrent)
|
||||
// appendQueue is a serial queue, not concurrent
|
||||
let appendQueue = DispatchQueue(label: "metadataAppendQueue", qos: .userInitiated)
|
||||
let dispatchGroup = DispatchGroup()
|
||||
|
||||
for file in files {
|
||||
|
|
|
@ -94,7 +94,8 @@ class NextcloudItemMetadataTable: Object {
|
|||
@Persisted var sessionSelector = ""
|
||||
@Persisted var sessionTaskIdentifier: Int = 0
|
||||
@Persisted var sharePermissionsCollaborationServices: Int = 0
|
||||
let sharePermissionsCloudMesh = List<String>() // TODO: Find a way to compare these in remote state check
|
||||
// TODO: Find a way to compare these two below in remote state check
|
||||
let sharePermissionsCloudMesh = List<String>()
|
||||
let shareType = List<Int>()
|
||||
@Persisted var size: Int64 = 0
|
||||
@Persisted var status: Int = 0
|
||||
|
@ -183,9 +184,12 @@ class NextcloudItemMetadataTable: Object {
|
|||
func isInSameDatabaseStoreableRemoteState(_ comparingMetadata: NextcloudItemMetadataTable)
|
||||
-> Bool
|
||||
{
|
||||
comparingMetadata.etag == etag && comparingMetadata.fileNameView == fileNameView
|
||||
&& comparingMetadata.date == date && comparingMetadata.permissions == permissions
|
||||
&& comparingMetadata.hasPreview == hasPreview && comparingMetadata.note == note
|
||||
comparingMetadata.etag == etag
|
||||
&& comparingMetadata.fileNameView == fileNameView
|
||||
&& comparingMetadata.date == date
|
||||
&& comparingMetadata.permissions == permissions
|
||||
&& comparingMetadata.hasPreview == hasPreview
|
||||
&& comparingMetadata.note == note
|
||||
&& comparingMetadata.lock == lock
|
||||
&& comparingMetadata.sharePermissionsCollaborationServices
|
||||
== sharePermissionsCollaborationServices
|
||||
|
@ -203,13 +207,13 @@ class NextcloudItemMetadataTable: Object {
|
|||
}
|
||||
|
||||
let urlBase = urlBase.urlEncoded!
|
||||
let webdavUrl = urlBase + NextcloudAccount.webDavFilesUrlSuffix + user // Leave the leading slash
|
||||
// Leave the leading slash in webdavUrl
|
||||
let webdavUrl = urlBase + NextcloudAccount.webDavFilesUrlSuffix + user
|
||||
let serverFileRelativeUrl =
|
||||
serverUrl.replacingOccurrences(of: webdavUrl, with: "") + "/" + fileName
|
||||
|
||||
let urlString =
|
||||
"\(urlBase)/index.php/core/preview.png?file=\(serverFileRelativeUrl)&x=\(size.width)&y=\(size.height)&a=1&mode=cover"
|
||||
|
||||
return URL(string: urlString)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
|||
FileProviderEnumerator.isSystemIdentifier(enumeratedItemIdentifier)
|
||||
}
|
||||
|
||||
private let anchor = NSFileProviderSyncAnchor(Date().description.data(using: .utf8)!) // TODO: actually use this in NCKit and server requests
|
||||
// TODO: actually use this in NCKit and server requests
|
||||
private let anchor = NSFileProviderSyncAnchor(Date().description.data(using: .utf8)!)
|
||||
private static let maxItemsPerFileProviderPage = 100
|
||||
let ncAccount: NextcloudAccount
|
||||
let ncKit: NextcloudKit
|
||||
|
@ -35,7 +36,8 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
|||
}
|
||||
|
||||
init(
|
||||
enumeratedItemIdentifier: NSFileProviderItemIdentifier, ncAccount: NextcloudAccount,
|
||||
enumeratedItemIdentifier: NSFileProviderItemIdentifier,
|
||||
ncAccount: NextcloudAccount,
|
||||
ncKit: NextcloudKit
|
||||
) {
|
||||
self.enumeratedItemIdentifier = enumeratedItemIdentifier
|
||||
|
@ -317,8 +319,12 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
|
|||
)
|
||||
|
||||
FileProviderEnumerator.completeChangesObserver(
|
||||
observer, anchor: anchor, ncKit: self.ncKit, newMetadatas: newMetadatas,
|
||||
updatedMetadatas: updatedMetadatas, deletedMetadatas: deletedMetadatas)
|
||||
observer,
|
||||
anchor: anchor,
|
||||
ncKit: self.ncKit,
|
||||
newMetadatas: newMetadatas,
|
||||
updatedMetadatas: updatedMetadatas,
|
||||
deletedMetadatas: deletedMetadatas)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,8 @@ class FileProviderItem: NSObject, NSFileProviderItem {
|
|||
}
|
||||
|
||||
required init(
|
||||
metadata: NextcloudItemMetadataTable, parentItemIdentifier: NSFileProviderItemIdentifier,
|
||||
metadata: NextcloudItemMetadataTable,
|
||||
parentItemIdentifier: NSFileProviderItemIdentifier,
|
||||
ncKit: NextcloudKit
|
||||
) {
|
||||
self.metadata = metadata
|
||||
|
|
Loading…
Reference in a new issue