Browse Source

move to NextcloudKit

Signed-off-by: marinofaggiana <marino.faggiana@nextcloud.com>
marinofaggiana 2 years ago
parent
commit
54e54b1bbf

+ 1 - 1
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1301,7 +1301,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
             if CCUtility.fileProviderStorageExists(metadata) {
                 NCViewer.shared.view(viewController: self, metadata: metadata, metadatas: [metadata], imageIcon: imageIcon)
             } else if NextcloudKit.shared.isNetworkReachable() {
-                NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadFileView) { _ in }
+                NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadFileView) { _, _ in }
             } else {
                 let error = NKError(errorCode: NCGlobal.shared.errorOffline, errorDescription: "_go_online_")
                 NCContentPresenter.shared.showInfo(error: error)

+ 6 - 6
iOSClient/Main/NCFunctionCenter.swift

@@ -150,9 +150,9 @@ import Photos
             NCManageDatabase.shared.setDirectory(serverUrl: serverUrl, offline: true, account: self.appDelegate.account)
             NCOperationQueue.shared.synchronizationMetadata(metadata, selector: NCGlobal.shared.selectorDownloadAllFile)
         } else {
-            NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadOffline) { _ in }
+            NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadOffline) { _, _ in }
             if let metadataLivePhoto = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
-                NCNetworking.shared.download(metadata: metadataLivePhoto, selector: NCGlobal.shared.selectorLoadOffline) { _ in }
+                NCNetworking.shared.download(metadata: metadataLivePhoto, selector: NCGlobal.shared.selectorLoadOffline) { _, _ in }
             }
         }
     }
@@ -203,7 +203,7 @@ import Photos
 
         } else {
 
-            NCNetworking.shared.download(metadata: metadata, selector: selector) { _ in }
+            NCNetworking.shared.download(metadata: metadata, selector: selector) { _, _ in }
         }
     }
 
@@ -232,7 +232,7 @@ import Photos
         let processor = ParallelWorker(n: 5, titleKey: "_downloading_", totalTasks: downloadMetadata.count, hudView: self.appDelegate.window?.rootViewController?.view)
         for (metadata, url) in downloadMetadata {
             processor.execute { completion in
-                NCNetworking.shared.download(metadata: metadata, selector: "", completion: { _ in
+                NCNetworking.shared.download(metadata: metadata, selector: "", completion: { _, _ in
                     if CCUtility.fileProviderStorageExists(metadata) { items.append(url) }
                     completion()
                 })
@@ -412,7 +412,7 @@ import Photos
 
             for metadata in downloadMetadatas {
                 parallelizer.execute { completion in
-                    NCNetworking.shared.download(metadata: metadata, selector: "") { _ in completion() }
+                    NCNetworking.shared.download(metadata: metadata, selector: "") { _, _ in completion() }
                 }
             }
             parallelizer.completeWork {
@@ -620,7 +620,7 @@ import Photos
         let copyPath = UIAction(title: NSLocalizedString("_copy_path_", comment: ""), image: UIImage(systemName: "doc.on.clipboard")) { _ in
             let board = UIPasteboard.general
             board.string = NCUtilityFileSystem.shared.getPath(path: metadata.path, user: metadata.user, fileName: metadata.fileName)
-            let error = NKError(errorCode: NCGlobal.shared.errorNoError, errorDescription: "_copied_path_")
+            let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_copied_path_")
             NCContentPresenter.shared.showInfo(error: error)
         }
 

+ 1 - 1
iOSClient/Menu/NCViewer+Menu.swift

@@ -208,7 +208,7 @@ extension NCViewer {
                         title: NSLocalizedString("_download_image_max_", comment: ""),
                         icon: NCUtility.shared.loadImage(named: "square.and.arrow.down"),
                         action: { _ in
-                            NCNetworking.shared.download(metadata: metadata, selector: "") { _ in }
+                            NCNetworking.shared.download(metadata: metadata, selector: "") { _, _ in }
                         }
                     )
                 )

+ 0 - 1
iOSClient/NCGlobal.swift

@@ -220,7 +220,6 @@ class NCGlobal: NSObject {
 
     // Error
     //
-    @objc let errorNoError: Int                     = 0
     @objc let errorRequestExplicityCancelled: Int   = 15
     @objc let errorNotModified: Int                 = 304
     @objc let errorBadRequest: Int                  = 400

+ 1 - 1
iOSClient/Networking/NCAutoUpload.swift

@@ -61,7 +61,7 @@ class NCAutoUpload: NSObject {
         NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: viewController) { hasPermission in
             guard hasPermission else { return }
             #if !EXTENSION
-            let error = NKError(errorCode: NCGlobal.shared.errorNoError, errorDescription: "_create_full_upload_")
+            let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_create_full_upload_")
             NCContentPresenter.shared.showWarning(error: error, priority: .max)
             NCActivityIndicator.shared.start()
             #endif

+ 2 - 2
iOSClient/Networking/NCNetworking.swift

@@ -313,7 +313,7 @@ import Photos
         }
     }
     
-    @objc func download(metadata: tableMetadata, selector: String, notificationCenterProgressTask: Bool = true, progressHandler: @escaping (_ progress: Progress) -> Void = { _ in }, completion: @escaping (_ errorCode: Int) -> Void) {
+    func download(metadata: tableMetadata, selector: String, notificationCenterProgressTask: Bool = true, progressHandler: @escaping (_ progress: Progress) -> Void = { _ in }, completion: @escaping (_ afError: AFError?, _ error: NKError) -> Void) {
         
         let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
         let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileName)!
@@ -375,7 +375,7 @@ import Photos
                 NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account, "selector": selector, "error": error])
             }
 
-            DispatchQueue.main.async { completion(error.errorCode) }
+            DispatchQueue.main.async { completion(afError, error) }
         }
     }
 

+ 1 - 1
iOSClient/Networking/NCOperationQueue.swift

@@ -245,7 +245,7 @@ class NCOperationDownload: ConcurrentOperation {
         if isCancelled {
             self.finish()
         } else {
-            NCNetworking.shared.download(metadata: metadata, selector: self.selector) { _ in
+            NCNetworking.shared.download(metadata: metadata, selector: self.selector) { _, _ in
                 self.finish()
             }
         }

+ 4 - 4
iOSClient/PushNotification/NCPushNotification.m

@@ -107,10 +107,10 @@
     NSString *proxyServerPath = [NCBrandOptions shared].pushNotificationServerProxy;
     
     [[NextcloudKit shared] subscribingPushNotificationWithServerUrl:urlBase account:account user:user password:[CCUtility getPassword:account] pushTokenHash:pushTokenHash devicePublicKey:pushDevicePublicKey proxyServerUrl:proxyServerPath customUserAgent:nil addCustomHeaders:nil queue:dispatch_get_main_queue() completionHandler:^(NSString *account, NSString *deviceIdentifier, NSString *signature, NSString *publicKey, NKError *error) {
-        if (error.errorCode == NCGlobal.shared.errorNoError) {
+        if (error == NKError.success) {
             NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [CCUtility getUserAgent]];
             [[NextcloudKit shared] subscribingPushProxyWithProxyServerUrl:proxyServerPath pushToken:self.pushKitToken deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey userAgent:userAgent queue:dispatch_get_main_queue() completionHandler:^(NKError *error) {
-                if (error.errorCode == NCGlobal.shared.errorNoError) {
+                if (error == NKError.success) {
                     
                     [[NKCommon shared] writeLog:@"Subscribed to Push Notification server & proxy successfully"];
 
@@ -133,11 +133,11 @@
     NSString *publicKey = [CCUtility getPushNotificationSubscribingPublicKey:account];
 
     [[NextcloudKit shared] unsubscribingPushNotificationWithServerUrl:urlBase account:account user:user password:[CCUtility getPassword:account] customUserAgent:nil addCustomHeaders:nil queue:dispatch_get_main_queue() completionHandler:^(NSString *account, NKError *error) {
-        if (error.errorCode == NCGlobal.shared.errorNoError) {
+        if (error == NKError.success) {
             NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [CCUtility getUserAgent]];
             NSString *proxyServerPath = [NCBrandOptions shared].pushNotificationServerProxy;
             [[NextcloudKit shared] unsubscribingPushProxyWithProxyServerUrl:proxyServerPath deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey userAgent:userAgent queue:dispatch_get_main_queue() completionHandler:^(NKError *error) {
-                if (error.errorCode == NCGlobal.shared.errorNoError) {
+                if (error == NKError.success) {
                 
                     [[NKCommon shared] writeLog:@"Unsubscribed to Push Notification server & proxy successfully."];
                     

+ 2 - 2
iOSClient/Settings/NCManageEndToEndEncryption.m

@@ -378,7 +378,7 @@
     [self deselectFormRow:sender];
     
     [[NextcloudKit shared] deleteE2EECertificateWithCustomUserAgent:nil addCustomHeaders:nil queue:dispatch_get_main_queue() completionHandler:^(NSString *account, NKError *error) {
-       if (error.errorCode == NCGlobal.shared.errorNoError && [account isEqualToString:appDelegate.account]) {
+       if (error == NKError.success && [account isEqualToString:appDelegate.account]) {
            NKError *error = [[NKError alloc] initWithErrorCode:NCGlobal.shared.errorInternalError errorDescription:@"Success"];
             [[NCContentPresenter shared] messageNotification:@"E2E delete certificate" error:error delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeSuccess];
         } else {
@@ -392,7 +392,7 @@
     [self deselectFormRow:sender];
     
     [[NextcloudKit shared] deleteE2EEPrivateKeyWithCustomUserAgent:nil addCustomHeaders:nil queue:dispatch_get_main_queue() completionHandler:^(NSString *account, NKError *error) {
-        if (error.errorCode == NCGlobal.shared.errorNoError && [account isEqualToString:appDelegate.account]) {
+        if (error == NKError.success && [account isEqualToString:appDelegate.account]) {
             NKError *error = [[NKError alloc] initWithErrorCode:NCGlobal.shared.errorInternalError errorDescription:@"Success"];
             [[NCContentPresenter shared] messageNotification:@"E2E delete privateKey" error:error delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeSuccess];
         } else {

+ 1 - 1
iOSClient/Share/NCSharePaging.swift

@@ -388,7 +388,7 @@ class NCShareHeaderView: UIView {
 
     @objc func longTap(sender: UIGestureRecognizer) {
         UIPasteboard.general.string = path.text
-        let error = NKError(errorCode: NCGlobal.shared.errorNoError, errorDescription: "_copied_path_")
+        let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_copied_path_")
         NCContentPresenter.shared.showInfo(error: error)
     }
 }

+ 1 - 1
iOSClient/Utility/NCContentPresenter.swift

@@ -100,7 +100,7 @@ class NCContentPresenter: NSObject {
         if error.errorCode == -999 { return }         // Cancelled transfer
         else if error.errorCode == 200 { return }     // Transfer stopped
         else if error.errorCode == 207 { return }     // WebDAV multistatus
-        else if error.errorCode == NCGlobal.shared.errorNoError && type == messageType.error { return }
+        else if error == .success && type == messageType.error { return }
 
         DispatchQueue.main.async {
             switch error.errorCode {

+ 1 - 1
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCSubtitle/NCSubtitlePlayer.swift

@@ -135,7 +135,7 @@ extension NCPlayer {
             }
         }
         if all.count != existing.count {
-            let error = NKError(errorCode: NCGlobal.shared.errorNoError, errorDescription: "_subtitle_not_dowloaded_")
+            let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_subtitle_not_dowloaded_")
             NCContentPresenter.shared.showInfo(error: error)
         }
         self.setSubtitleToolbarIcon(subtitleUrls: subtitleUrls)

+ 3 - 3
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -240,11 +240,11 @@ class NCViewerMedia: UIViewController {
             if metadata.livePhoto {
                 let fileName = (metadata.fileNameView as NSString).deletingPathExtension + ".mov"
                 if let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", metadata.account, metadata.serverUrl, fileName)), !CCUtility.fileProviderStorageExists(metadata) {
-                    NCNetworking.shared.download(metadata: metadata, selector: "") { _ in }
+                    NCNetworking.shared.download(metadata: metadata, selector: "") { _, _ in }
                 }
             }
 
-            NCNetworking.shared.download(metadata: metadata, selector: "") { _ in
+            NCNetworking.shared.download(metadata: metadata, selector: "") { _, _ in
                 let image = getImageMetadata(metadata)
                 if self.metadata.ocId == metadata.ocId && self.imageVideoContainer.layer.sublayers?.count == nil {
                     self.image = image
@@ -534,7 +534,7 @@ extension NCViewerMedia: NCViewerMediaDetailViewDelegate {
 
     func downloadFullResolution() {
         closeDetail()
-        NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorOpenDetail) { _ in }
+        NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorOpenDetail) { _, _ in }
     }
 }