Skip to content

Commit

Permalink
Minor link handling fixes for deep links (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
micahmo authored Oct 25, 2023
1 parent ff31698 commit 6a06206
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/thunder/cubits/deep_links_cubit/deep_links_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DeepLinksCubit extends Cubit<DeepLinksState> {
link: link,
linkType: LinkType.comment,
));
} else if (!link.replaceAll(RegExp(r'https?:\/\/'), '').contains('/')) {
} else if (Uri.tryParse(link)?.pathSegments.isEmpty == true) {
emit(state.copyWith(
deepLinkStatus: DeepLinkStatus.success,
link: link,
Expand Down
28 changes: 16 additions & 12 deletions lib/thunder/pages/thunder_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class _ThunderState extends State<Thunder> {

Future<void> _navigateToInstance(String link) async {
try {
await navigateToInstancePage(context, instanceHost: link.replaceAll(RegExp(r'https?:\/\/'), ''));
await navigateToInstancePage(context, instanceHost: link.replaceAll(RegExp(r'https?:\/\/'), '').replaceAll('/', ''));
} catch (e) {
if (context.mounted) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);
Expand All @@ -240,12 +240,12 @@ class _ThunderState extends State<Thunder> {
} catch (e) {
// Ignore exception, if it's not a valid comment, we'll perform the next fallback
}
}

// postId not found or could not resolve link.
// show a snackbar with option to open link
if (context.mounted) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);
}
// postId not found or could not resolve link.
// show a snackbar with option to open link
if (context.mounted) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);
}
}

Expand All @@ -267,12 +267,12 @@ class _ThunderState extends State<Thunder> {
} catch (e) {
// Ignore exception, if it's not a valid comment, we'll perform the next fallback
}
}

// commentId not found or could not resolve link.
// show a snackbar with option to open link
if (context.mounted) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);
}
// commentId not found or could not resolve link.
// show a snackbar with option to open link
if (context.mounted) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);
}
}

Expand Down Expand Up @@ -337,7 +337,11 @@ class _ThunderState extends State<Thunder> {
showSnackbar(context, state.error ?? l10n.exceptionProcessingUri);

case DeepLinkStatus.success:
_handleDeepLinkNavigation(context, linkType: state.linkType, link: state.link);
try {
_handleDeepLinkNavigation(context, linkType: state.linkType, link: state.link);
} catch (e) {
_showLinkProcessingError(context, AppLocalizations.of(context)!.uriNotSupported, state.link!);
}

case DeepLinkStatus.unknown:
showSnackbar(context, state.error ?? l10n.uriNotSupported);
Expand Down

0 comments on commit 6a06206

Please sign in to comment.