Skip to content

Commit

Permalink
Cllean up function and method calls in File Provider Extension
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Feb 5, 2024
1 parent fc3472f commit 0c2e011
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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]?,
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -270,7 +277,8 @@ class NextcloudFilesDatabaseManager: NSObject {
}

return (
newMetadatas: metadatasToCreate, updatedMetadatas: metadatasToUpdate,
newMetadatas: metadatasToCreate,
updatedMetadatas: metadatasToUpdate,
deletedMetadatas: metadatasToDelete
)
} catch {
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +36,8 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
}

init(
enumeratedItemIdentifier: NSFileProviderItemIdentifier, ncAccount: NextcloudAccount,
enumeratedItemIdentifier: NSFileProviderItemIdentifier,
ncAccount: NextcloudAccount,
ncKit: NextcloudKit
) {
self.enumeratedItemIdentifier = enumeratedItemIdentifier
Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ class FileProviderItem: NSObject, NSFileProviderItem {
}

required init(
metadata: NextcloudItemMetadataTable, parentItemIdentifier: NSFileProviderItemIdentifier,
metadata: NextcloudItemMetadataTable,
parentItemIdentifier: NSFileProviderItemIdentifier,
ncKit: NextcloudKit
) {
self.metadata = metadata
Expand Down

0 comments on commit 0c2e011

Please sign in to comment.