Browse Source

change Service

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 year ago
parent
commit
603d2505da

+ 2 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -4287,8 +4287,8 @@
 			isa = XCRemoteSwiftPackageReference;
 			repositoryURL = "https://github.com/nextcloud/NextcloudKit";
 			requirement = {
-				kind = exactVersion;
-				version = 2.4.0;
+				branch = sessionManager;
+				kind = branch;
 			};
 		};
 		F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {

+ 1 - 1
iOSClient/Login/NCLogin.swift

@@ -260,7 +260,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
 
         loginButton.isEnabled = false
 
-        NextcloudKit.shared.getServerStatus(serverUrl: url) { _, _, versionMajor, _, _, _, _, error in
+        NextcloudKit.shared.getServerStatus(serverUrl: url) {installed, maintenance, _, _, _, versionMajor, _, _, _, _, error in
 
             if error == .success {
 

+ 0 - 1
iOSClient/NCGlobal.swift

@@ -214,7 +214,6 @@ class NCGlobal: NSObject {
     @objc let errordMethodNotSupported: Int         = 405
     @objc let errorConflict: Int                    = 409
     @objc let errorPreconditionFailed: Int          = 412
-    @objc let errorNCUnauthorized: Int              = 997
     @objc let errorConnectionLost: Int              = -1005
     @objc let errorNetworkNotAvailable: Int         = -1009
     @objc let errorBadServerResponse: Int           = -1011

+ 60 - 67
iOSClient/Networking/NCService.swift

@@ -41,9 +41,17 @@ class NCService: NSObject {
         NCManageDatabase.shared.clearAllAvatarLoaded()
         guard !appDelegate.account.isEmpty else { return }
 
-        addInternalTypeIdentifier()
-        requestServerStatus()
-        requestUserProfile()        
+        Task {
+            addInternalTypeIdentifier()
+            let result = await requestServerStatus()
+            if result.serverStatus, let tableAccount = result.tableAccount {
+                synchronize(tableAccount: tableAccount)
+                getAvatar(tableAccount: tableAccount)
+                requestServerCapabilities()
+                requestDashboardWidget()
+                NCNetworkingE2EE.shared.unlockAll(account: tableAccount.account)
+            }
+        }
     }
 
     // MARK: -
@@ -81,91 +89,76 @@ class NCService: NSObject {
 
     // MARK: -
 
-    private func requestServerStatus() {
+    private func requestServerStatus() async -> (serverStatus: Bool, tableAccount: tableAccount?) {
 
         let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
 
-        NextcloudKit.shared.getServerStatus(serverUrl: appDelegate.urlBase, options: options) { serverProductName, _, versionMajor, _, _, extendedSupport, data, error in
-            guard error == .success, extendedSupport == false else {
-                return
-            }
+        let resultServerStatus = await NextcloudKit.shared.getServerStatus(serverUrl: appDelegate.urlBase, options: options)
+        let resultUserProfile = await NextcloudKit.shared.getUserProfile(options: options)
 
-            if serverProductName == "owncloud" {
-                let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_warning_owncloud_")
-                NCContentPresenter.shared.showWarning(error: error, priority: .max)
-            } else if versionMajor <=  NCGlobal.shared.nextcloud_unsupported_version {
-                let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_warning_unsupported_")
-                NCContentPresenter.shared.showWarning(error: error, priority: .max)
-            }
+        if resultServerStatus.maintenance {
+            let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_maintenance_mode_")
+            NCContentPresenter.shared.showWarning(error: error, priority: .max)
+            return (false, nil)
         }
-    }
-
-    // MARK: -
 
-    private func requestUserProfile() {
-        guard !appDelegate.account.isEmpty else { return }
-
-        let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
+        if let serverProductName = resultServerStatus.serverProductName, serverProductName.contains("owncloud") {
+            let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_warning_owncloud_")
+            NCContentPresenter.shared.showWarning(error: error, priority: .max)
+        }
 
-        NextcloudKit.shared.getUserProfile(options: options) { account, userProfile, data, error in
-            guard error == .success, let userProfile = userProfile else {
-                
-                // Ops the server has Unauthorized
-                NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] The server has response with Unauthorized \(error.errorCode)")
-
-                DispatchQueue.main.async {
-                    if  (UIApplication.shared.applicationState == .active) &&
-                        (NCNetworking.shared.networkReachability != NKCommon.TypeReachability.notReachable) &&
-                        (error.errorCode == NCGlobal.shared.errorNCUnauthorized || error.errorCode == NCGlobal.shared.errorUnauthorized || error.errorCode == NCGlobal.shared.errorForbidden) {
-                        
-                        NCBrandColor.shared.settingThemingColor(account: account)
-                        NCNetworkingCheckRemoteUser().checkRemoteUser(account: account, error: error)
-                    }
-                }
-                return
-            }
+        if resultServerStatus.versionMajor <=  NCGlobal.shared.nextcloud_unsupported_version {
+            let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_warning_unsupported_")
+            NCContentPresenter.shared.showWarning(error: error, priority: .max)
+        }
 
-            // Update User (+ userProfile.id) & active account & account network
-            guard let tableAccount = NCManageDatabase.shared.setAccountUserProfile(account: account, userProfile: userProfile) else {
+        if resultUserProfile.error == .success, let userProfile = resultUserProfile.userProfile {
+            guard let tableAccount = NCManageDatabase.shared.setAccountUserProfile(account: resultUserProfile.account, userProfile: userProfile) else {
                 let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "Internal error : account not found on DB")
                 NCContentPresenter.shared.showError(error: error, priority: .max)
-                return
+                return (false, nil)
+            }
+            await self.appDelegate.settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userId: tableAccount.userId, password: CCUtility.getPassword(tableAccount.account))
+            return (true, tableAccount)
+        } else if resultUserProfile.error.errorCode == NCGlobal.shared.errorUnauthorized {
+            // Ops the server has Unauthorized
+            DispatchQueue.main.async {
+                if UIApplication.shared.applicationState == .active && NCNetworking.shared.networkReachability != NKCommon.TypeReachability.notReachable {
+                    NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] The server has response with Unauthorized \(resultUserProfile.error.errorCode)")
+                    NCNetworkingCheckRemoteUser().checkRemoteUser(account: resultUserProfile.account, error: resultUserProfile.error)
+                }
             }
+            return (false, nil)
+        }
 
-            self.appDelegate.settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userId: tableAccount.userId, password: CCUtility.getPassword(tableAccount.account))
+        return (false, nil)
+    }
 
-            // Synchronize favorite
-            NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorReadFile) { _, _, _ in }
+    func synchronize(tableAccount: tableAccount) {
 
-            // Synchronize Offline
-            self.synchronizeOffline(account: tableAccount.account)
+        NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorReadFile) { _, _, _ in }
+        self.synchronizeOffline(account: tableAccount.account)
+    }
 
-            // Get Avatar
-            let fileName = tableAccount.userBaseUrl + "-" + self.appDelegate.user + ".png"
-            let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
-            let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
-            let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
+    func getAvatar(tableAccount: tableAccount) {
 
-            NextcloudKit.shared.downloadAvatar(user: tableAccount.userId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag, options: options) { _, _, _, etag, error in
-                guard let etag = etag, error == .success else {
-                    if error.errorCode == NCGlobal.shared.errorNotModified {
-                        NCManageDatabase.shared.setAvatarLoaded(fileName: fileName)
-                    }
-                    return
+        let fileName = tableAccount.userBaseUrl + "-" + self.appDelegate.user + ".png"
+        let fileNameLocalPath = String(CCUtility.getDirectoryUserData()) + "/" + fileName
+        let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag
+        let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
+
+        NextcloudKit.shared.downloadAvatar(user: tableAccount.userId, fileNameLocalPath: fileNameLocalPath, sizeImage: NCGlobal.shared.avatarSize, avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag, options: options) { _, _, _, etag, error in
+            guard let etag = etag, error == .success else {
+                if error.errorCode == NCGlobal.shared.errorNotModified {
+                    NCManageDatabase.shared.setAvatarLoaded(fileName: fileName)
                 }
-                NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
-                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadAvatar, userInfo: nil)
+                return
             }
-
-            self.requestServerCapabilities()
-            self.requestDashboardWidget()
-            // Unlock E2EE
-            NCNetworkingE2EE.shared.unlockAll(account: account)
+            NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag)
+            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadAvatar, userInfo: nil)
         }
     }
 
-    // MARK: -
-
     private func requestServerCapabilities() {
         guard !appDelegate.account.isEmpty else { return }
 

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -966,6 +966,7 @@
 "_user_"                    = "User";
 "_add_subtitle_"            = "Add an external subtitle";
 "_add_audio_"               = "Add an external audio";
+"_maintenance_mode_"        = "Server is currently in maintenance mode";
 
 // Tip
 "_tip_pdf_thumbnails_"      = "Swipe left from the right edge of the screen to show the thumbnails.";