Kaynağa Gözat

move to NextcloudKit

Signed-off-by: marinofaggiana <marino.faggiana@nextcloud.com>
marinofaggiana 2 yıl önce
ebeveyn
işleme
20e84c58f6

+ 2 - 2
File Provider Extension/FileProviderExtension.swift

@@ -371,7 +371,7 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
         }
     }
 
-    func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, task: URLSessionTask, errorCode: Int, errorDescription: String) {
+    func uploadComplete(fileName: String, serverUrl: String, ocId: String?, etag: String?, date: NSDate?, size: Int64, description: String?, task: URLSessionTask, error: NKError) {
 
         guard let ocIdTemp = description else { return }
         guard let metadataTemp = NCManageDatabase.shared.getMetadataFromOcId(ocIdTemp) else { return }
@@ -383,7 +383,7 @@ class FileProviderExtension: NSFileProviderExtension, NCNetworkingDelegate {
         }
         outstandingOcIdTemp[ocIdTemp] = ocId
 
-        if errorCode == 0 {
+        if error == .success {
 
             // New file
             if ocId != ocIdTemp {

+ 1 - 1
iOSClient/Login/NCLogin.swift

@@ -335,7 +335,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
 
     func standardLogin(url: String, user: String, password: String, errorCode: Int, errorDescription: String) {
 
-        if errorCode == 0 {
+        if errorCode == NCGlobal.shared.errorNoError {
 
             if let host = URL(string: url)?.host {
                 NCNetworking.shared.writeCertificate(host: host)

+ 1 - 1
iOSClient/Main/NCFunctionCenter.swift

@@ -53,7 +53,7 @@ import Photos
               account == appDelegate.account
         else { return }
 
-        guard errorCode == 0 else {
+        guard errorCode == NCGlobal.shared.errorNoError else {
             // File do not exists on server, remove in local
             if errorCode == NCGlobal.shared.errorResourceNotFound || errorCode == NCGlobal.shared.errorBadServerResponse {
                 do {

+ 2 - 1
iOSClient/Media/NCMedia.swift

@@ -214,7 +214,8 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
     @objc func uploadedFile(_ notification: NSNotification) {
 
         guard let userInfo = notification.userInfo as NSDictionary?,
-              let errorCode = userInfo["errorCode"] as? Int, errorCode == 0 ,
+              let errorCode = userInfo["errorCode"] as? Int,
+              errorCode == NCGlobal.shared.errorNoError,
               let account = userInfo["account"] as? String,
               account == appDelegate.account
         else { return }

+ 3 - 0
iOSClient/NCGlobal.swift

@@ -224,9 +224,12 @@ class NCGlobal: NSObject {
     @objc let errorRequestExplicityCancelled: Int   = 15
     @objc let errorNotModified: Int                 = 304
     @objc let errorBadRequest: Int                  = 400
+    @objc let errorUnauthorized: Int                = 401
+    @objc let errorForbidden: Int                   = 403
     @objc let errorResourceNotFound: Int            = 404
     @objc let errordMethodNotSupported: Int         = 405
     @objc let errorConflict: Int                    = 409
+    @objc let errorPreconditionFailed: Int          = 412
     @objc let errorConnectionLost: Int              = -1005
     @objc let errorBadServerResponse: Int           = -1011
     @objc let errorInternalError: Int               = -99999

+ 4 - 4
iOSClient/Networking/NCNetworking.swift

@@ -368,7 +368,7 @@ import Photos
 
                 NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, session: "", sessionError: error.errorDescription, sessionSelector: selector, sessionTaskIdentifier: 0, status: NCGlobal.shared.metadataStatusDownloadError)
                 #if !EXTENSION
-                if error.errorCode == 401 || error.errorCode == 403 {
+                if error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
                     NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, error: error)
                 }
                 #endif
@@ -547,7 +547,7 @@ import Photos
                     NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                     NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadCancelFile, userInfo: ["ocId": metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account])
 
-                } else if error.errorCode == 401 || error.errorCode == 403 {
+                } else if error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
 
                     #if !EXTENSION
                     NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, error: error)
@@ -980,7 +980,7 @@ import Photos
 
         NextcloudKit.shared.createFolder(fileNameFolderUrl) { account, ocId, _, error in
             guard error == .success else {
-                if error.errorCode == 405 && overwrite {
+                if error.errorCode == NCGlobal.shared.errordMethodNotSupported && overwrite {
                     completion(NKError())
                 } else {
                     completion(error)
@@ -1193,7 +1193,7 @@ import Photos
     @objc func lockUnlockFile(_ metadata: tableMetadata, shoulLock: Bool) {
         NextcloudKit.shared.lockUnlockFile(serverUrlFileName: metadata.serverUrl + "/" + metadata.fileName, shouldLock: shoulLock) { error in
             // 0: lock was successful; 412: lock did not change, no error, refresh
-            guard error == .success || error.errorCode == 412 else {
+            guard error == .success || error.errorCode == NCGlobal.shared.errorPreconditionFailed else {
                 let error = NKError(errorCode: error.errorCode, errorDescription: "_files_lock_error_")
                 NCContentPresenter.shared.messageNotification(metadata.fileName, error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
                 return

+ 1 - 1
iOSClient/Networking/NCNetworkingCheckRemoteUser.swift

@@ -47,7 +47,7 @@ import NextcloudKit
 
         if serverVersionMajor >= NCGlobal.shared.nextcloudVersion17 {
 
-            if error.errorCode == 401 {
+            if error.errorCode == NCGlobal.shared.errorUnauthorized {
 
                 let token = CCUtility.getPassword(account)!
                 if token == "" {

+ 1 - 1
iOSClient/Networking/NCNetworkingE2EE.swift

@@ -318,7 +318,7 @@ import Alamofire
 
                         } else {
 
-                            if error.errorCode == 401 || error.errorCode == 403 {
+                            if error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
 
                                 #if !EXTENSION
                                 NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: metadata.account, error: error)

+ 2 - 2
iOSClient/Networking/NCService.swift

@@ -103,7 +103,7 @@ class NCService: NSObject {
         NextcloudKit.shared.getUserProfile(queue: NKCommon.shared.backgroundQueue) { account, userProfile, error in
             guard error == .success, account == self.appDelegate.account else {
                 NCBrandColor.shared.settingThemingColor(account: account)
-                if error.errorCode == 401 || error.errorCode == 403 {
+                if error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
                     NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, error: error)
                 }
                 return
@@ -150,7 +150,7 @@ class NCService: NSObject {
         NextcloudKit.shared.getCapabilities(queue: NKCommon.shared.backgroundQueue) { account, data, error in
             guard error == .success, let data = data else {
                 NCBrandColor.shared.settingThemingColor(account: account)
-                if error.errorCode == 401 || error.errorCode == 403 {
+                if error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden {
                     NCNetworkingCheckRemoteUser.shared.checkRemoteUser(account: account, error: error)
                 }
                 return

+ 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 == 0) {
+        if (error.errorCode == NCGlobal.shared.errorNoError) {
             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 == 0) {
+                if (error.errorCode == NCGlobal.shared.errorNoError) {
                     
                     [[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 == 0) {
+        if (error.errorCode == NCGlobal.shared.errorNoError) {
             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 == 0) {
+                if (error.errorCode == NCGlobal.shared.errorNoError) {
                 
                     [[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 == 0 && [account isEqualToString:appDelegate.account]) {
+       if (error.errorCode == NCGlobal.shared.errorNoError && [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 == 0 && [account isEqualToString:appDelegate.account]) {
+        if (error.errorCode == NCGlobal.shared.errorNoError && [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/Viewer/NCViewerMedia/NCViewerMediaPage.swift

@@ -250,7 +250,7 @@ class NCViewerMediaPage: UIViewController {
         guard let userInfo = notification.userInfo as NSDictionary?,
               let ocId = userInfo["ocId"] as? String,
               let errorCode = userInfo["errorCode"] as? Int,
-              errorCode == 0,
+              errorCode == NCGlobal.shared.errorNoError,
               let index = metadatas.firstIndex(where: {$0.ocId == ocId}),
               let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
         else {

+ 1 - 1
iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift

@@ -293,7 +293,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
 
         NCActivityIndicator.shared.stop()
 
-        if errorCode == 0 {
+        if errorCode == NCGlobal.shared.errorNoError {
             pdfDocument = PDFDocument(url: URL(fileURLWithPath: filePath))
             pdfView.document = pdfDocument
             pdfView.layoutDocumentView()

+ 2 - 2
iOSClient/Viewer/NCViewerProviderContextMenu.swift

@@ -190,7 +190,7 @@ class NCViewerProviderContextMenu: UIViewController {
               let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
         else { return }
 
-        if errorCode == 0 && metadata.ocId == self.metadata?.ocId {
+        if errorCode == NCGlobal.shared.errorNoError && metadata.ocId == self.metadata?.ocId {
             if metadata.classFile == NKCommon.typeClassFile.image.rawValue {
                 viewImage(metadata: metadata)
             } else if metadata.classFile == NKCommon.typeClassFile.video.rawValue {
@@ -199,7 +199,7 @@ class NCViewerProviderContextMenu: UIViewController {
                 playSound(metadata: metadata)
             }
         }
-        if errorCode == 0 && metadata.ocId == self.metadataLivePhoto?.ocId {
+        if errorCode == NCGlobal.shared.errorNoError && metadata.ocId == self.metadataLivePhoto?.ocId {
             viewVideo(metadata: metadata)
         }
         if ocId == self.metadata?.ocId || ocId == self.metadataLivePhoto?.ocId {