Эх сурвалжийг харах

Get email from URL instead of title + improve errors

Using the *mailto:* url is probably more reliable, since the title might be subject to change

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 жил өмнө
parent
commit
acebd313b7

+ 19 - 15
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -34,7 +34,14 @@ extension UIViewController {
         
         switch action.appId {
         case "email":
-            sendEmail(to: action.title)
+            guard let url = action.hyperlinkUrl,
+                  url.scheme == "mailto",
+                  let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
+                NCContentPresenter.shared.showGenericError(description: "_cannot_send_mail_error_")
+                return
+            }
+
+            sendEmail(to: components.path)
         case "spreed":
             let appDelegate = UIApplication.shared.delegate as! AppDelegate
             if let talkUrl = URL(string: "nextcloudtalk://open-conversation?server=\(appDelegate.urlBase)&user=\(userId)&withUser=\(appDelegate.userId)"),
@@ -44,7 +51,8 @@ extension UIViewController {
                 UIApplication.shared.open(url, options: [:])
             }
         default:
-            guard let url = action.hyperlinkUrl else {
+            guard let url = action.hyperlinkUrl, UIApplication.shared.canOpenURL(url) else {
+                NCContentPresenter.shared.showGenericError(description: "_open_url_error")
                 return
             }
             UIApplication.shared.open(url, options: [:])
@@ -80,20 +88,16 @@ extension UIViewController {
     }
     
     func sendEmail(to email: String) {
-        if MFMailComposeViewController.canSendMail() {
-            let mail = MFMailComposeViewController()
-            mail.mailComposeDelegate = self
-            mail.setToRecipients([email])
-
-            present(mail, animated: true)
-        } else {
-            NCContentPresenter.shared.messageNotification(
-                "_error_", description: "_error_send_mail_",
-                delay: NCGlobal.shared.dismissAfterSecond,
-                type: NCContentPresenter.messageType.error,
-                errorCode: NCGlobal.shared.errorGeneric,
-                forced: true)
+        guard MFMailComposeViewController.canSendMail() else {
+            NCContentPresenter.shared.showGenericError(description: "_cannot_send_mail_error_")
+            return
         }
+
+        let mail = MFMailComposeViewController()
+        mail.mailComposeDelegate = self
+        mail.setToRecipients([email])
+
+        present(mail, animated: true)
     }
     
     fileprivate func presentMenu(with actions: [NCMenuAction]) {

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

@@ -435,7 +435,7 @@
 "_insert_password_"             = "Enter password";
 "_update_in_progress_"          = "Version upgrade, please wait…";
 "_forbidden_characters_"        = "The file or folder name contains invalid characters";
-"_mail_not_can_send_mail_"      = "No account set up, or wrong email address entered";
+"_cannot_send_mail_error_"      = "No account set up, or wrong email address entered";
 "_photo_camera_"                = "Photos";
 "_media_"                       = "Media";
 "_unzip_in_progress_"           = "Extraction in progress on local storage…";

+ 13 - 4
iOSClient/Utility/NCContentPresenter.swift

@@ -64,11 +64,21 @@ class NCContentPresenter: NSObject {
 
     //MARK: - Message
     
+    @objc func showGenericError(description: String) {
+        messageNotification(
+            "_error_", description: description,
+            delay: NCGlobal.shared.dismissAfterSecond,
+            type: .error,
+            errorCode: NCGlobal.shared.errorGeneric,
+            forced: true)
+    }
+    
     @objc func messageNotification(_ title: String, description: String?, delay: TimeInterval, type: messageType, errorCode: Int, forced: Bool = false) {
                        
         // No notification message
         if forced == false {
-            
+            let internetError = Int(CFNetworkErrors.cfurlErrorNotConnectedToInternet.rawValue)
+
             if errorCode == -999 { return }         // Cancelled transfer
             else if errorCode == 200 { return }     // Transfer stopped
             else if errorCode == 207 { return }     // WebDAV multistatus
@@ -77,10 +87,9 @@ class NCContentPresenter: NSObject {
             else if errorCode == -1005 { return }   // Connection lost
             else if errorCode == 0 && type == messageType.error { return }
             
+            else if errorCode == internetError && errorCode == lastErrorCode { return }
             // No repeat message for:
-            if errorCode == lastErrorCode {
-                if errorCode ==  Int(CFNetworkErrors.cfurlErrorNotConnectedToInternet.rawValue) { return }
-            } else {
+            else if errorCode != lastErrorCode {
                 lastErrorCode = errorCode
             }
         }