Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Open ComposeMessageView from 'mailto:' in messages #795

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core",
"state" : {
"revision" : "cf001ba55dbf5f152353d66b55cd46350bd4b895"
"revision" : "e5fe8e03aa06375f20c8e40f4fae3a6af6e4d75e"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Mail/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, AccountManagerDelegate
}

@discardableResult
private func handleUrlOpen(_ url: URL) -> Bool {
func handleUrlOpen(_ url: URL) -> Bool {
guard let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true),
let mailboxManager = accountManager.currentMailboxManager else {
return false
}

if urlComponents.scheme?.caseInsensitiveCompare("mailto") == .orderedSame {
if Constants.isMailTo(url) {
let newMessageView = ComposeMessageView.mailTo(urlComponents: urlComponents, mailboxManager: mailboxManager)
let viewController = UIHostingController(rootView: newMessageView)
window?.rootViewController?.present(viewController, animated: true)
Expand Down
9 changes: 9 additions & 0 deletions Mail/Views/Thread/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailCore
import SwiftUI
import WebKit

struct WebView: UIViewRepresentable {
@Environment(\.window) private var window

@ObservedObject var model: WebViewModel

let messageUid: String
Expand Down Expand Up @@ -53,6 +56,12 @@ struct WebView: UIViewRepresentable {
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
) {
if let url = navigationAction.request.url, Constants.isMailTo(url) {
decisionHandler(.cancel)
(parent.window?.windowScene?.delegate as? SceneDelegate)?.handleUrlOpen(url)
return
}

if navigationAction.navigationType == .linkActivated {
if let url = navigationAction.request.url {
decisionHandler(.cancel)
Expand Down
4 changes: 4 additions & 0 deletions MailCore/Utils/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public enum Constants {
return emailPredicate.evaluate(with: mail.lowercased())
}

public static func isMailTo(_ url: URL) -> Bool {
return url.scheme?.caseInsensitiveCompare("mailto") == .orderedSame
}

public static func forwardQuote(message: Message) -> String {
let date = DateFormatter.localizedString(from: message.date, dateStyle: .medium, timeStyle: .short)
let to = ListFormatter.localizedString(byJoining: message.to.map(\.htmlDescription))
Expand Down