Skip to content

Commit 9a5ec69

Browse files
committed
internal_link: Add tryResolveOnRealmUrl
1 parent 2cf1b36 commit 9a5ec69

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/model/internal_link.dart

+11
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,14 @@ Uri narrowLink(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
7878

7979
return store.account.realmUrl.replace(fragment: fragment.toString());
8080
}
81+
82+
/// Create a new `Uri` object in relation to a given realmUrl.
83+
///
84+
/// Returns `null` if `urlString` could not be parsed as a `Uri`.
85+
Uri? tryResolveOnRealmUrl(String urlString, Uri realmUrl) {
86+
try {
87+
return realmUrl.resolve(urlString);
88+
} on FormatException {
89+
return null;
90+
}
91+
}

lib/widgets/content.dart

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '../api/core.dart';
77
import '../api/model/model.dart';
88
import '../model/binding.dart';
99
import '../model/content.dart';
10+
import '../model/internal_link.dart';
1011
import '../model/store.dart';
1112
import 'code_block.dart';
1213
import 'dialog.dart';
@@ -661,12 +662,9 @@ void _launchUrl(BuildContext context, String urlString) async {
661662
}
662663

663664
final store = PerAccountStoreWidget.of(context);
664-
final Uri url;
665-
try {
666-
url = store.account.realmUrl.resolve(urlString);
667-
} on FormatException { // TODO(log)
665+
final url = tryResolveOnRealmUrl(urlString, store.account.realmUrl);
666+
if (url == null) { // TODO(log)
668667
await showError(context, null);
669-
if (!context.mounted) return; // TODO(dart): redundant for sake of lint
670668
return;
671669
}
672670

0 commit comments

Comments
 (0)