Fetch sharing capabilities in ShareTableViewDataSource

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-03-18 18:06:26 +08:00
Родитель 8039fcd951
Коммит cfd8c00e94
2 изменённых файлов: 25 добавлений и 0 удалений

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

@ -69,6 +69,11 @@ struct ShareCapabilities {
private(set) var email = EmailCapabilities(dict: [:])
private(set) var publicLink = PublicLinkCapabilities(dict: [:])
init() {
Logger.shareCapabilities.warning("Providing defaulted share capabilities!")
}
init(json: Data) {
guard let anyJson = try? JSONSerialization.jsonObject(with: json, options: []),
let jsonDict = anyJson as? [String : Any],
@ -86,5 +91,7 @@ struct ShareCapabilities {
if let publicLinkCapabilities = sharingCapabilities["public"] as? [String : Any] {
publicLink = PublicLinkCapabilities(dict: publicLinkCapabilities)
}
Logger.shareCapabilities.debug("Parses share capabilities.")
}
}

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

@ -43,6 +43,7 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource, NSTableViewDele
)
}
}
private var shareCapabilities = ShareCapabilities()
func loadItem(url: URL) {
itemServerRelativePath = nil
@ -81,6 +82,7 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource, NSTableViewDele
itemServerRelativePath = serverPath as String
account = convertedAccount
await sharesTableView?.deselectAll(self)
shareCapabilities = await fetchCapabilities()
shares = await fetch(
itemIdentifier: itemIdentifier, itemRelativePath: serverPath as String
)
@ -139,6 +141,22 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource, NSTableViewDele
}
}
private func fetchCapabilities() async -> ShareCapabilities {
return await withCheckedContinuation { continuation in
kit?.getCapabilities { account, capabilitiesJson, error in
guard error == .success, let capabilitiesJson = capabilitiesJson else {
let errorString = "Error getting server capabilities: \(error.errorDescription)"
Logger.sharesDataSource.error("\(errorString)")
Task { @MainActor in self.uiDelegate?.showError(errorString) }
continuation.resume(returning: ShareCapabilities())
return
}
Logger.sharesDataSource.info("Successfully retrieved server share capabilities")
continuation.resume(returning: ShareCapabilities(json: capabilitiesJson))
}
}
}
// MARK: - NSTableViewDataSource protocol methods
@objc func numberOfRows(in tableView: NSTableView) -> Int {