]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Add functionality to share controller to save changes
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 4 Mar 2024 12:41:01 +0000 (20:41 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 17 Apr 2024 08:38:54 +0000 (16:38 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/Extensions/Logger+Extensions.swift
shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareController.swift

index 63ff845a69d8026143046f8b65a485719f18d7d8..c668e3a8dd5b88e2deb184e4e742a1e70fe78285 100644 (file)
@@ -11,6 +11,7 @@ extension Logger {
     private static var subsystem = Bundle.main.bundleIdentifier!
 
     static let actionViewController = Logger(subsystem: subsystem, category: "actionViewController")
+    static let shareController = Logger(subsystem: subsystem, category: "shareController")
     static let sharesDataSource = Logger(subsystem: subsystem, category: "sharesDataSource")
     static let shareViewController = Logger(subsystem: subsystem, category: "shareViewController")
 }
index fdd4b5a8a27176a8fe311c5eab50d83c3d31ecba..4a51d609a7447d11a3f385edcb077056fe5e5765 100644 (file)
@@ -5,15 +5,40 @@
 //  Created by Claudio Cambra on 4/3/24.
 //
 
+import Combine
 import Foundation
 import NextcloudKit
+import OSLog
 
-class ShareController {
-    let share: NKShare
+class ShareController: ObservableObject {
+    @Published private(set) var share: NKShare
     private let kit: NextcloudKit
 
     init(share: NKShare, kit: NextcloudKit) {
         self.share = share
         self.kit = kit
     }
+
+    func save() async -> NKError? {
+        return await withCheckedContinuation { continuation in
+            kit.updateShare(
+                idShare: share.idShare,
+                password: share.password,
+                expireDate: share.expirationDateString ?? "",
+                permissions: share.permissions,
+                note: share.note,
+                label: share.label,
+                hideDownload: share.hideDownload,
+                attributes: share.attributes
+            ) { account, share, data, error in
+                Logger.shareController.info("Received update response: \(share?.url ?? "")")
+                defer { continuation.resume(returning: error) }
+                guard error == .success, let share = share else {
+                    Logger.shareController.error("Error updating save: \(error.errorDescription)")
+                    return
+                }
+                self.share = share
+            }
+        }
+    }
 }