Skip to content

Commit 66cbf08

Browse files
committed
improve URL resolution with proper fallback mechanisms
1 parent 2248839 commit 66cbf08

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Mlem/App/Views/Shared/HandleLemmyLinksModifier.swift

+10-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ struct HandleLemmyLinksModifier: ViewModifier {
103103
// The "@" check ensures that KBin links are excluded
104104
if !host.contains("reddit.com"), components.count == 2, components[1].first != "@" {
105105
Task {
106-
await showToastAndLoad(url: url)
106+
await showToastAndResolve(url: url) { url in
107+
openRegularLink(url: url)
108+
}
107109
}
108110
return .handled
109111
}
@@ -172,7 +174,11 @@ struct HandleLemmyLinksModifier: ViewModifier {
172174
} else if isLemmyHost(host) {
173175
// If it's a Lemmy host, try to resolve as a Lemmy user
174176
Task {
175-
await showToastAndLoad(url: URL(string: "https://\(host)/u/\(user)")!)
177+
await showToastAndResolve(url: URL(string: "https://\(host)/u/\(user)")!) { _ in
178+
// If resolution fails, show email alert as fallback
179+
pendingMailtoURL = url
180+
showingEmailAlert = true
181+
}
176182
}
177183
} else {
178184
// If it's neither a common email domain nor a Lemmy host, show email alert
@@ -183,7 +189,7 @@ struct HandleLemmyLinksModifier: ViewModifier {
183189
return true
184190
}
185191

186-
func showToastAndLoad(url: URL) async {
192+
func showToastAndResolve(url: URL, fallback: @escaping (URL) -> Void) async {
187193
let toastId = ToastModel.main.add(.loading())
188194
var output = try? await appState.firstApi.resolve(url: url)
189195
if output == nil {
@@ -199,7 +205,7 @@ struct HandleLemmyLinksModifier: ViewModifier {
199205
} else if let community = output as? any Community {
200206
navigation.push(.community(community))
201207
} else {
202-
openRegularLink(url: url)
208+
fallback(url)
203209
}
204210
ToastModel.main.removeToast(id: toastId)
205211
}

0 commit comments

Comments
 (0)