Przeglądaj źródła

Merge pull request #2451 from nextcloud/service

Marino Faggiana 1 rok temu
rodzic
commit
853c2ce9ee

+ 1 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -4288,7 +4288,7 @@
 			repositoryURL = "https://github.com/nextcloud/NextcloudKit";
 			requirement = {
 				kind = exactVersion;
-				version = 2.4.0;
+				version = 2.6.0;
 			};
 		};
 		F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {

+ 0 - 5
iOSClient/AppDelegate.swift

@@ -41,7 +41,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     @objc var userId: String = ""
     @objc var password: String = ""
 
-    var deletePasswordSession: Bool = false
     var activeLogin: NCLogin?
     var activeLoginWeb: NCLoginWeb?
     var activeServerUrl: String = ""
@@ -193,8 +192,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         NCNetworkingProcessUpload.shared.observeTableMetadata()
         NCNetworkingProcessUpload.shared.startTimer()
 
-        self.deletePasswordSession = false
-
         if !NCAskAuthorization.shared.isRequesting {
             hidePrivacyProtectionWindow()
         }
@@ -541,8 +538,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     }
 
     @objc private func checkErrorNetworking() {
-        
-        // check unauthorized server (401/403)
         if account != "" && CCUtility.getPassword(account)!.count == 0 {
             openLogin(viewController: window?.rootViewController, selector: NCGlobal.shared.introLogin, openLoginWeb: true)
         }

+ 6 - 5
iOSClient/Login/NCLogin.swift

@@ -260,9 +260,10 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
 
         loginButton.isEnabled = false
 
-        NextcloudKit.shared.getServerStatus(serverUrl: url) { _, _, versionMajor, _, _, _, _, error in
+        NextcloudKit.shared.getServerStatus(serverUrl: url) { serverInfoResult in
 
-            if error == .success {
+            switch serverInfoResult {
+            case .success(let serverInfo):
 
                 if let host = URL(string: url)?.host {
                     NCNetworking.shared.writeCertificate(host: host)
@@ -288,7 +289,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
                         }
 
                     // Login Flow
-                    } else if versionMajor >= NCGlobal.shared.nextcloudVersion12 {
+                    } else if serverInfo.versionMajor >= NCGlobal.shared.nextcloudVersion12 {
 
                         if let loginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb {
 
@@ -299,7 +300,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
                         }
 
                     // NO Login flow available
-                    } else if versionMajor < NCGlobal.shared.nextcloudVersion12 {
+                    } else if serverInfo.versionMajor < NCGlobal.shared.nextcloudVersion12 {
 
                         let alertController = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_webflow_not_available_", comment: ""), preferredStyle: .alert)
 
@@ -309,7 +310,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
                     }
                 }
 
-            } else {
+            case .failure(let error):
 
                 self.loginButton.isEnabled = true
 

+ 2 - 2
iOSClient/NCGlobal.swift

@@ -208,13 +208,13 @@ 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 errorUnauthorized401: 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 errorNCUnauthorized: Int              = 997
+    @objc let errorUnauthorized997: Int             = 997
     @objc let errorConnectionLost: Int              = -1005
     @objc let errorNetworkNotAvailable: Int         = -1009
     @objc let errorBadServerResponse: Int           = -1011

+ 1 - 2
iOSClient/Networking/NCNetworkingCheckRemoteUser.swift

@@ -58,13 +58,12 @@ class NCNetworkingCheckRemoteUser {
 
                 } else {
 
-                    if UIApplication.shared.applicationState == .active && NextcloudKit.shared.isNetworkReachable() && !CCUtility.getPassword(account).isEmpty && !appDelegate.deletePasswordSession {
+                    if UIApplication.shared.applicationState == .active && NextcloudKit.shared.isNetworkReachable() && !CCUtility.getPassword(account).isEmpty {
                         let description = String.localizedStringWithFormat(NSLocalizedString("_error_check_remote_user_", comment: ""), tableAccount.user, tableAccount.urlBase)
                         let error = NKError(errorCode: error.errorCode, errorDescription: description)
                         NCContentPresenter.shared.showError(error: error, priority: .max)
                         CCUtility.setPassword(account, password: nil)
                         NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Password removed.")
-                        appDelegate.deletePasswordSession = true
                     }
                 }
             }

+ 61 - 66
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,78 @@ 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
-            }
-
-            if serverProductName == "owncloud" {
+        switch await NextcloudKit.shared.getServerStatus(serverUrl: appDelegate.urlBase, options: options) {
+        case .success(let serverInfo):
+            if serverInfo.maintenance {
+                let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_maintenance_mode_")
+                NCContentPresenter.shared.showWarning(error: error, priority: .max)
+                return (false, nil)
+            } else if serverInfo.productName.lowercased().contains("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 {
+                return (false, nil)
+            } else if serverInfo.versionMajor <=  NCGlobal.shared.nextcloud_unsupported_version {
                 let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_warning_unsupported_")
                 NCContentPresenter.shared.showWarning(error: error, priority: .max)
             }
+        case .failure(_):
+            return(false, nil)
         }
-    }
-
-    // MARK: -
-
-    private func requestUserProfile() {
-        guard !appDelegate.account.isEmpty else { return }
-
-        let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
-
-        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
-            }
 
-            // Update User (+ userProfile.id) & active account & account network
-            guard let tableAccount = NCManageDatabase.shared.setAccountUserProfile(account: account, userProfile: userProfile) else {
-                let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "Internal error : account not found on DB")
+        let resultUserProfile = await NextcloudKit.shared.getUserProfile(options: options)
+        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.errorUnauthorized401 ||
+                    resultUserProfile.error.errorCode == NCGlobal.shared.errorUnauthorized997 {
+            // 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 go checkRemoteUser \(resultUserProfile.error.errorCode)")
+                    NCNetworkingCheckRemoteUser().checkRemoteUser(account: resultUserProfile.account, error: resultUserProfile.error)
+                }
+            }
+            return (false, nil)
+        } else {
+            NCContentPresenter.shared.showError(error: resultUserProfile.error, priority: .max)
+            return (false, nil)
+        }
+    }
 
-            self.appDelegate.settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userId: tableAccount.userId, password: CCUtility.getPassword(tableAccount.account))
+    func synchronize(tableAccount: tableAccount) {
 
-            // Synchronize favorite
-            NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorReadFile) { _, _, _ in }
+        NCNetworking.shared.listingFavoritescompletion(selector: NCGlobal.shared.selectorReadFile) { _, _, _ in }
+        self.synchronizeOffline(account: tableAccount.account)
+    }
 
-            // Synchronize Offline
-            self.synchronizeOffline(account: tableAccount.account)
+    func getAvatar(tableAccount: tableAccount) {
 
-            // 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)
+        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)
-                    }
-                    return
+        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 }
 

+ 5 - 5
iOSClient/Notification/NCNotification.storyboard

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="c26-Us-IIn">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="c26-Us-IIn">
     <device id="retina4_7" orientation="portrait" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>
@@ -17,7 +17,7 @@
                         <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                         <prototypes>
                             <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" rowHeight="187" id="R1c-h5-BOp" customClass="NCNotificationCell" customModule="Nextcloud" customModuleProvider="target">
-                                <rect key="frame" x="0.0" y="44.5" width="375" height="187"/>
+                                <rect key="frame" x="0.0" y="50" width="375" height="187"/>
                                 <autoresizingMask key="autoresizingMask"/>
                                 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="R1c-h5-BOp" id="9Bv-1W-yVV">
                                     <rect key="frame" x="0.0" y="0.0" width="375" height="187"/>
@@ -64,7 +64,7 @@
                                                 <constraint firstAttribute="height" constant="20" id="IIr-Ys-RMx"/>
                                                 <constraint firstAttribute="width" constant="20" id="YaB-cW-gAT"/>
                                             </constraints>
-                                            <state key="normal" image="exit"/>
+                                            <state key="normal" image="xmark" catalog="system"/>
                                             <connections>
                                                 <action selector="touchUpInsideRemove:" destination="R1c-h5-BOp" eventType="touchUpInside" id="Wlp-VM-Vf2"/>
                                             </connections>
@@ -166,6 +166,6 @@
         </scene>
     </scenes>
     <resources>
-        <image name="exit" width="300" height="300"/>
+        <image name="xmark" catalog="system" width="128" height="113"/>
     </resources>
 </document>

+ 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.";